summaryrefslogtreecommitdiffstats
path: root/ext/misc/fileio.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--ext/misc/fileio.c24
1 files changed, 16 insertions, 8 deletions
diff --git a/ext/misc/fileio.c b/ext/misc/fileio.c
index 70546ad..ca8090e 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
}