Skip to content

Commit 1de6440

Browse files
committed
Fix MDEV-12587 MariaDB CONNECT DIR Type
- Subfolder Option: SELECT Query Never Ends modified: storage/connect/tabmul.cpp modified: storage/connect/tabmul.h Work on MDEV-12667 Crash when using JSON tables modified: storage/connect/connect.cc modified: storage/connect/ha_connect.cc modified: storage/connect/ha_connect.h modified: storage/connect/plgdbutl.cpp Change Base offset for DIR tables on Linux modified: storage/connect/reldef.cpp
1 parent 63b7d9d commit 1de6440

File tree

9 files changed

+82
-50
lines changed

9 files changed

+82
-50
lines changed

storage/connect/connect.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,8 @@ bool CntCheckDB(PGLOBAL g, PHC handler, const char *pathname)
117117
handler);
118118

119119
// Set the database path for this table
120-
handler->SetDataPath(g, pathname);
120+
if (handler->SetDataPath(g, pathname))
121+
return true;
121122

122123
if (dbuserp->Catalog) {
123124
// ((MYCAT *)dbuserp->Catalog)->SetHandler(handler); done later

storage/connect/ha_connect.cc

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1739,9 +1739,9 @@ void ha_connect::AddColName(char *cp, Field *fp)
17391739
/***********************************************************************/
17401740
/* This function sets the current database path. */
17411741
/***********************************************************************/
1742-
void ha_connect::SetDataPath(PGLOBAL g, const char *path)
1742+
bool ha_connect::SetDataPath(PGLOBAL g, const char *path)
17431743
{
1744-
datapath= SetPath(g, path);
1744+
return (!(datapath = SetPath(g, path)));
17451745
} // end of SetDataPath
17461746

17471747
/****************************************************************************/
@@ -2721,6 +2721,8 @@ PCFIL ha_connect::CheckCond(PGLOBAL g, PCFIL filp, const Item *cond)
27212721

27222722
if (x)
27232723
return NULL;
2724+
else
2725+
pb0 = pb1 = pb2 = ph0 = ph1 = ph2 = NULL;
27242726

27252727
if (trace)
27262728
htrc("Cond: Ftype=%d name=%s\n", cond_item->functype(),
@@ -4110,10 +4112,14 @@ int ha_connect::info(uint flag)
41104112
} // endif xmod
41114113

41124114
// This is necessary for getting file length
4113-
if (table)
4114-
SetDataPath(g, table->s->db.str);
4115-
else
4116-
DBUG_RETURN(HA_ERR_INTERNAL_ERROR); // Should never happen
4115+
if (table) {
4116+
if (SetDataPath(g, table->s->db.str)) {
4117+
my_message(ER_UNKNOWN_ERROR, g->Message, MYF(0));
4118+
DBUG_RETURN(HA_ERR_INTERNAL_ERROR);
4119+
} // endif SetDataPath
4120+
4121+
} else
4122+
DBUG_RETURN(HA_ERR_INTERNAL_ERROR); // Should never happen
41174123

41184124
if (!(tdbp= GetTDB(g)))
41194125
DBUG_RETURN(HA_ERR_INTERNAL_ERROR); // Should never happen
@@ -6563,9 +6569,10 @@ int ha_connect::create(const char *name, TABLE *table_arg,
65636569
PDBUSER dup= PlgGetUser(g);
65646570
PCATLG cat= (dup) ? dup->Catalog : NULL;
65656571

6566-
SetDataPath(g, table_arg->s->db.str);
6567-
6568-
if (cat) {
6572+
if (SetDataPath(g, table_arg->s->db.str)) {
6573+
my_message(ER_UNKNOWN_ERROR, g->Message, MYF(0));
6574+
rc = HA_ERR_INTERNAL_ERROR;
6575+
} else if (cat) {
65696576
// cat->SetDataPath(g, table_arg->s->db.str);
65706577

65716578
#if defined(WITH_PARTITION_STORAGE_ENGINE)
@@ -7137,6 +7144,6 @@ maria_declare_plugin(connect)
71377144
NULL, /* status variables */
71387145
connect_system_variables, /* system variables */
71397146
"1.05.0003", /* string version */
7140-
MariaDB_PLUGIN_MATURITY_GAMMA /* maturity */
7147+
MariaDB_PLUGIN_MATURITY_STABLE /* maturity */
71417148
}
71427149
maria_declare_plugin_end;

storage/connect/ha_connect.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ class ha_connect: public handler
199199
bool IsUnique(uint n);
200200
char *GetDataPath(void) {return (char*)datapath;}
201201

202-
void SetDataPath(PGLOBAL g, const char *path);
202+
bool SetDataPath(PGLOBAL g, const char *path);
203203
PTDB GetTDB(PGLOBAL g);
204204
int OpenTable(PGLOBAL g, bool del= false);
205205
bool CheckColumnList(PGLOBAL g);

storage/connect/plgdbutl.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -412,8 +412,9 @@ char *SetPath(PGLOBAL g, const char *path)
412412
if (path) {
413413
size_t len= strlen(path) + (*path != '.' ? 4 : 1);
414414

415-
buf= (char*)PlugSubAlloc(g, NULL, len);
416-
415+
if (!(buf = (char*)PlgDBSubAlloc(g, NULL, len)))
416+
return NULL;
417+
417418
if (PlugIsAbsolutePath(path)) {
418419
strcpy(buf, path);
419420
return buf;

storage/connect/reldef.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
/************* RelDef CPP Program Source Code File (.CPP) **************/
22
/* PROGRAM NAME: RELDEF */
33
/* ------------- */
4-
/* Version 1.6 */
4+
/* Version 1.7 */
55
/* */
66
/* COPYRIGHT: */
77
/* ---------- */
8-
/* (C) Copyright to the author Olivier BERTRAND 2004-2016 */
8+
/* (C) Copyright to the author Olivier BERTRAND 2004-2017 */
99
/* */
1010
/* WHAT THIS PROGRAM DOES: */
1111
/* ----------------------- */
@@ -277,8 +277,13 @@ int TABDEF::GetColCatInfo(PGLOBAL g)
277277
// Take care of the column definitions
278278
i= poff= nof= nlg= 0;
279279

280+
#if defined(__WIN__)
280281
// Offsets of HTML and DIR tables start from 0, DBF at 1
281-
loff= (tc == TAB_DBF) ? 1 : (tc == TAB_XML || tc == TAB_DIR) ? -1 : 0;
282+
loff = (tc == TAB_DBF) ? 1 : (tc == TAB_XML || tc == TAB_DIR) ? -1 : 0;
283+
#else // !__WIN__
284+
// Offsets of HTML tables start from 0, DIR and DBF at 1
285+
loff = (tc == TAB_DBF || tc == TAB_DIR) ? 1 : (tc == TAB_XML) ? -1 : 0;
286+
#endif // !__WIN__
282287

283288
while (true) {
284289
// Default Offset depends on table type

storage/connect/tabjson.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,10 @@ PQRYRES JSONColumns(PGLOBAL g, char *db, PTOS topt, bool info)
117117
return NULL;
118118
} // endif Fn
119119

120-
tdp->Database = SetPath(g, db);
121-
tdp->Objname = GetStringTableOption(g, topt, "Object", NULL);
120+
if (!(tdp->Database = SetPath(g, db)))
121+
return NULL;
122+
123+
tdp->Objname = GetStringTableOption(g, topt, "Object", NULL);
122124
tdp->Base = GetIntegerTableOption(g, topt, "Base", 0) ? 1 : 0;
123125
tdp->Pretty = GetIntegerTableOption(g, topt, "Pretty", 2);
124126

storage/connect/tabmul.cpp

Lines changed: 38 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -603,9 +603,10 @@ bool TDBMSD::InitFileNames(PGLOBAL g)
603603
bool DIRDEF::DefineAM(PGLOBAL g, LPCSTR, int)
604604
{
605605
Desc = Fn = GetStringCatInfo(g, "Filename", NULL);
606-
Incl = (GetIntCatInfo("Subdir", 0) != 0);
607-
Huge = (GetIntCatInfo("Huge", 0) != 0);
608-
return false;
606+
Incl = GetBoolCatInfo("Subdir", false);
607+
Huge = GetBoolCatInfo("Huge", false);
608+
Nodir = GetBoolCatInfo("Nodir", true);
609+
return false;
609610
} // end of DefineAM
610611

611612
/***********************************************************************/
@@ -654,12 +655,14 @@ void TDBDIR::Init(void)
654655
TDBDIR::TDBDIR(PDIRDEF tdp) : TDBASE(tdp)
655656
{
656657
To_File = tdp->Fn;
658+
Nodir = tdp->Nodir;
657659
Init();
658660
} // end of TDBDIR standard constructor
659661

660662
TDBDIR::TDBDIR(PSZ fpat) : TDBASE((PTABDEF)NULL)
661663
{
662664
To_File = fpat;
665+
Nodir = true;
663666
Init();
664667
} // end of TDBDIR constructor
665668

@@ -812,27 +815,32 @@ int TDBDIR::ReadDB(PGLOBAL g)
812815
int rc = RC_OK;
813816

814817
#if defined(__WIN__)
815-
if (hSearch == INVALID_HANDLE_VALUE) {
816-
/*******************************************************************/
817-
/* Start searching files in the target directory. The use of the */
818-
/* Path function is required when called from TDBSDR. */
819-
/*******************************************************************/
820-
hSearch = FindFirstFile(Path(g), &FileData);
818+
do {
819+
if (hSearch == INVALID_HANDLE_VALUE) {
820+
/*****************************************************************/
821+
/* Start searching files in the target directory. The use of */
822+
/* the Path function is required when called from TDBSDR. */
823+
/*****************************************************************/
824+
hSearch = FindFirstFile(Path(g), &FileData);
825+
826+
if (hSearch == INVALID_HANDLE_VALUE) {
827+
rc = RC_EF;
828+
break;
829+
} else
830+
iFile++;
821831

822-
if (hSearch == INVALID_HANDLE_VALUE)
823-
rc = RC_EF;
824-
else
825-
iFile++;
832+
} else {
833+
if (!FindNextFile(hSearch, &FileData)) {
834+
// Restore file name and type pattern
835+
_splitpath(To_File, NULL, NULL, Fname, Ftype);
836+
rc = RC_EF;
837+
break;
838+
} else
839+
iFile++;
826840

827-
} else {
828-
if (!FindNextFile(hSearch, &FileData)) {
829-
// Restore file name and type pattern
830-
_splitpath(To_File, NULL, NULL, Fname, Ftype);
831-
rc = RC_EF;
832-
} else
833-
iFile++;
841+
} // endif hSearch
834842

835-
} // endif hSearch
843+
} while (Nodir && FileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY);
836844

837845
if (rc == RC_OK)
838846
_splitpath(FileData.cFileName, NULL, NULL, Fname, Ftype);
@@ -1229,17 +1237,19 @@ int TDBSDR::ReadDB(PGLOBAL g)
12291237
retry:
12301238
do {
12311239
if (Sub->H == INVALID_HANDLE_VALUE) {
1232-
_makepath(Fpath, Drive, Direc, "*", ".");
1233-
Sub->H = FindFirstFile(Fpath, &FileData);
1240+
// _makepath(Fpath, Drive, Direc, "*", "."); why was this made?
1241+
_makepath(Fpath, Drive, Direc, "*", NULL);
1242+
Sub->H = FindFirstFile(Fpath, &FileData);
12341243
} else if (!FindNextFile(Sub->H, &FileData)) {
12351244
FindClose(Sub->H);
12361245
Sub->H = INVALID_HANDLE_VALUE;
12371246
*FileData.cFileName= '\0';
12381247
break;
12391248
} // endif findnext
12401249

1241-
} while(!(FileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
1242-
|| *FileData.cFileName== '.');
1250+
} while (!(FileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ||
1251+
(*FileData.cFileName == '.' &&
1252+
(!FileData.cFileName[1] || FileData.cFileName[1] == '.')));
12431253

12441254
if (Sub->H == INVALID_HANDLE_VALUE) {
12451255
// No more sub-directories. Are we in a sub-directory?
@@ -1293,8 +1303,9 @@ int TDBSDR::ReadDB(PGLOBAL g)
12931303
if (lstat(Fpath, &Fileinfo) < 0) {
12941304
sprintf(g->Message, "%s: %s", Fpath, strerror(errno));
12951305
rc = RC_FX;
1296-
} else if (S_ISDIR(Fileinfo.st_mode) && *Entry->d_name != '.') {
1297-
// Look in the name sub-directory
1306+
} else if (S_ISDIR(Fileinfo.st_mode) && strcmp(Entry->d_name, ".")
1307+
&& strcmp(Entry->d_name, "..")) {
1308+
// Look in the name sub-directory
12981309
if (!Sub->Next) {
12991310
PSUBDIR sup;
13001311

storage/connect/tabmul.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,8 @@ class DllExport DIRDEF : public TABDEF { /* Directory listing table */
119119
PSZ Fn; /* Path/Name of file search */
120120
bool Incl; /* true to include sub-directories */
121121
bool Huge; /* true if files can be larger than 2GB */
122-
}; // end of DIRDEF
122+
bool Nodir; /* true to exclude directories */
123+
}; // end of DIRDEF
123124

124125
/***********************************************************************/
125126
/* This is the DIR Access Method class declaration for tables that */
@@ -175,7 +176,8 @@ class TDBDIR : public TDBASE {
175176
char Direc[_MAX_DIR]; // Search path
176177
char Fname[_MAX_FNAME]; // File name
177178
char Ftype[_MAX_EXT]; // File extention
178-
}; // end of class TDBDIR
179+
bool Nodir; // Exclude directories from file list
180+
}; // end of class TDBDIR
179181

180182
/***********************************************************************/
181183
/* This is the DIR Access Method class declaration for tables that */

storage/connect/tabxml.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,11 @@ PQRYRES XMLColumns(PGLOBAL g, char *db, char *tab, PTOS topt, bool info)
157157

158158
tdp = new(g) XMLDEF;
159159
tdp->Fn = fn;
160-
tdp->Database = SetPath(g, db);
161-
tdp->Tabname = tab;
160+
161+
if (!(tdp->Database = SetPath(g, db)))
162+
return NULL;
163+
164+
tdp->Tabname = tab;
162165
tdp->Zipped = GetBooleanTableOption(g, topt, "Zipped", false);
163166
tdp->Entry = GetStringTableOption(g, topt, "Entry", NULL);
164167

0 commit comments

Comments
 (0)