1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-11-12 13:01:09 +03:00

Fix the temporary directory search algorithm for unix so that it fails

gracefully even if all candidate directories are inaccessible.  This fixes
a bug that was introduced by check-in [9b8fec60d8e].

FossilOrigin-Name: 614bb709d34e11488da88861243023cc5de4b409
This commit is contained in:
drh
2016-04-29 20:30:56 +00:00
parent 54606bbc14
commit 2aab11fa5a
3 changed files with 18 additions and 15 deletions

View File

@@ -5412,18 +5412,22 @@ static const char *unixTempFileDir(void){
"/tmp",
"."
};
unsigned int i;
unsigned int i = 0;
struct stat buf;
const char *zDir = sqlite3_temp_directory;
if( !azDirs[0] ) azDirs[0] = getenv("SQLITE_TMPDIR");
if( !azDirs[1] ) azDirs[1] = getenv("TMPDIR");
for(i=0; i<=sizeof(azDirs)/sizeof(azDirs[0]); zDir=azDirs[i++]){
if( zDir==0 ) continue;
if( osStat(zDir, &buf) ) continue;
if( !S_ISDIR(buf.st_mode) ) continue;
if( osAccess(zDir, 03) ) continue;
return zDir;
while(1){
if( zDir!=0
&& osStat(zDir, &buf)==0
&& S_ISDIR(buf.st_mode)
&& osAccess(zDir, 03)==0
){
return zDir;
}
if( i>=sizeof(azDirs)/sizeof(azDirs[0]) ) break;
zDir = azDirs[i++];
}
return 0;
}