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

@ -1,5 +1,5 @@
C Postpone\sI/O\sassociated\swith\sTEMP\sfiles\sfor\sas\slong\sas\spossible,\swith\sthe\nhope\sthat\sthe\sI/O\scan\sultimately\sbe\savoided\scompletely.
D 2016-04-29T15:39:48.423
C Fix\sthe\stemporary\sdirectory\ssearch\salgorithm\sfor\sunix\sso\sthat\sit\sfails\ngracefully\seven\sif\sall\scandidate\sdirectories\sare\sinaccessible.\s\sThis\sfixes\na\sbug\sthat\swas\sintroduced\sby\scheck-in\s[9b8fec60d8e].
D 2016-04-29T20:30:56.115
F Makefile.in 9e816d0323e418fbc0f8b2c05fc14e0b3763d9e8
F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434
F Makefile.msc 71b8b16cf9393f68e2e2035486ca104872558836
@ -361,7 +361,7 @@ F src/os.c 4d83917f072ad958fba9235136fa2ed43df47905
F src/os.h 8e976e59eb4ca1c0fca6d35ee803e38951cb0343
F src/os_common.h b2f4707a603e36811d9b1a13278bffd757857b85
F src/os_setup.h c9d4553b5aaa6f73391448b265b89bed0b890faa
F src/os_unix.c 8422fba2eb592fbbb2d4006b6f2a67cad8951495
F src/os_unix.c a9443cdab41d7f3cdf0df3a5aab62fd6e1c9b234
F src/os_win.c 852fc2ff6084296348ed3739c548b2cf32df394e
F src/os_win.h eb7a47aa17b26b77eb97e4823f20a00b8bda12ca
F src/pager.c a8d30c49c231e9a20d05257613db922532588963
@ -1486,8 +1486,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
P 4cbd50245440e714935399a5c285cf32d8bfc424 b7bec7f2d3d08d0c14f77654be2c5cedf1619e58
R f9ef4e1af8653e902d9192ffb04cabc2
T +closed b7bec7f2d3d08d0c14f77654be2c5cedf1619e58
P 9d0a5ae00273686ea35b43bc2ffaa8775c176363
R a933a7d712b512086a1e3835745ceb3a
U drh
Z 20681342134be4241c18925dab8e4f41
Z 98ad5e2467f45a0f2dba904fa48c29d6

View File

@ -1 +1 @@
9d0a5ae00273686ea35b43bc2ffaa8775c176363
614bb709d34e11488da88861243023cc5de4b409

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;
}