diff options
author | dan <Dan Kennedy> | 2024-05-06 20:21:31 +0000 |
---|---|---|
committer | dan <Dan Kennedy> | 2024-05-06 20:21:31 +0000 |
commit | 11a088b7eb9b563419253badf56fa50e897d5123 (patch) | |
tree | 629ad79f70e2badf65af8a00e84a2d2fcc7faed4 /ext/misc/fileio.c | |
parent | 07305e3a3ab5aaaa1062417f8176b95c13e73954 (diff) | |
download | sqlite-11a088b7eb9b563419253badf56fa50e897d5123.tar.gz sqlite-11a088b7eb9b563419253badf56fa50e897d5123.zip |
When extracting links from sqlar archives, clobber any existing file or link, and do not call utimes() to set the timestamp - it looks through the link and operates on the target.
FossilOrigin-Name: 2bf8c3f99ad8b74f707d17272fa12b674bec66082d3e8349ebef3dac42ba0782
Diffstat (limited to 'ext/misc/fileio.c')
-rw-r--r-- | ext/misc/fileio.c | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/ext/misc/fileio.c b/ext/misc/fileio.c index 70546adfc..ca8090ed2 100644 --- a/ext/misc/fileio.c +++ b/ext/misc/fileio.c @@ -372,7 +372,9 @@ static int writeFile( #if !defined(_WIN32) && !defined(WIN32) if( S_ISLNK(mode) ){ const char *zTo = (const char*)sqlite3_value_text(pData); - if( zTo==0 || symlink(zTo, zFile)<0 ) return 1; + if( zTo==0 ) return 1; + unlink(zFile); + if( symlink(zTo, zFile)<0 ) return 1; }else #endif { @@ -458,13 +460,19 @@ static int writeFile( return 1; } #else - /* Legacy unix */ - struct timeval times[2]; - times[0].tv_usec = times[1].tv_usec = 0; - times[0].tv_sec = time(0); - times[1].tv_sec = mtime; - if( utimes(zFile, times) ){ - return 1; + /* Legacy unix. + ** + ** Do not use utimes() on a symbolic link - it sees through the link and + ** modifies the timestamps on the target. Or fails if the target does + ** not exist. */ + if( 0==S_ISLNK(mode) ){ + struct timeval times[2]; + times[0].tv_usec = times[1].tv_usec = 0; + times[0].tv_sec = time(0); + times[1].tv_sec = mtime; + if( utimes(zFile, times) ){ + return 1; + } } #endif } |