Skip to content

Commit a6b1de0

Browse files
committed
libsql-sqlite3: Sync ext/misc/fileio.c symlink fixes from 3.46.1
The 3.46.1 merge updated shell8.test (adding the symlink extraction tests shell8-3.x) and the bundled MultipleCiphers fileio.c, but left libsql-sqlite3/ext/misc/fileio.c at 3.44.0. That file is embedded into the CLI shell via 'INCLUDE ../ext/misc/fileio.c', so '.ar -x' ran the stale writeFile() and the new tests failed with 'failed to create symlink: link1'. Bring writeFile() in line with upstream 3.46.1: - Skip utimes() on symbolic links. utimes() follows the link to its target; the archive only contains link1 -> file1 (no file1), so the dangling link made utimes() fail and broke the first extraction (shell8-3.2). - unlink(zFile) before symlink() so re-extraction does not fail with EEXIST (shell8-3.3).
1 parent 8cedfe2 commit a6b1de0

1 file changed

Lines changed: 16 additions & 8 deletions

File tree

libsql-sqlite3/ext/misc/fileio.c

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,9 @@ static int writeFile(
372372
#if !defined(_WIN32) && !defined(WIN32)
373373
if( S_ISLNK(mode) ){
374374
const char *zTo = (const char*)sqlite3_value_text(pData);
375-
if( zTo==0 || symlink(zTo, zFile)<0 ) return 1;
375+
if( zTo==0 ) return 1;
376+
unlink(zFile);
377+
if( symlink(zTo, zFile)<0 ) return 1;
376378
}else
377379
#endif
378380
{
@@ -458,13 +460,19 @@ static int writeFile(
458460
return 1;
459461
}
460462
#else
461-
/* Legacy unix */
462-
struct timeval times[2];
463-
times[0].tv_usec = times[1].tv_usec = 0;
464-
times[0].tv_sec = time(0);
465-
times[1].tv_sec = mtime;
466-
if( utimes(zFile, times) ){
467-
return 1;
463+
/* Legacy unix.
464+
**
465+
** Do not use utimes() on a symbolic link - it sees through the link and
466+
** modifies the timestamps on the target. Or fails if the target does
467+
** not exist. */
468+
if( 0==S_ISLNK(mode) ){
469+
struct timeval times[2];
470+
times[0].tv_usec = times[1].tv_usec = 0;
471+
times[0].tv_sec = time(0);
472+
times[1].tv_sec = mtime;
473+
if( utimes(zFile, times) ){
474+
return 1;
475+
}
468476
}
469477
#endif
470478
}

0 commit comments

Comments
 (0)