Fossil

Check-in [ec02acfd]
Login

Check-in [ec02acfd]

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Resolve the bug revealed in forum post 16880a28aad1a868 in which the db_open() appendvfs check can misinteract with g.nameOfExe. This is in a branch until a Windows user can confirm that the g.nameOfExe change in main.c behaves as desired on Windows. This was a collaborative bug fix via /chat, not my own. Edit: test success on Windows reported by Martin G.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | nameofexe-appendvfs-check
Files: files | file ages | folders
SHA3-256: ec02acfd095752419ce85bc2482dfdb6f02935597989c1491e3d2cffe639d0d7
User & Date: stephan 2022-02-28 21:30:48
Original Comment: Resolve the bug revealed in forum post 16880a28aad1a868 in which the db_open() appendvfs check can misinteract with g.nameOfExe. This is in a branch until a Windows user can confirm that the g.nameOfExe change in main.c behaves as desired on Windows. This was a collaborative bug fix via /chat, not my own.
Context
2022-03-01
16:21
Fix an unused var warning in windows ... (Closed-Leaf check-in: 169a3dab user: mgagnon tags: nameofexe-appendvfs-check)
2022-02-28
21:30
Resolve the bug revealed in forum post 16880a28aad1a868 in which the db_open() appendvfs check can misinteract with g.nameOfExe. This is in a branch until a Windows user can confirm that the g.nameOfExe change in main.c behaves as desired on Windows. This was a collaborative bug fix via /chat, not my own. Edit: test success on Windows reported by Martin G. ... (check-in: ec02acfd user: stephan tags: nameofexe-appendvfs-check)
20:49
Since checkin [d8c32ebdff], file_fullexename() function is supported windows, remove comment saying otherwize. (no code change) ... (check-in: 491b986d user: mgagnon tags: trunk)
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/db.c.

1633
1634
1635
1636
1637
1638
1639

1640
1641





1642
1643
1644
1645
1646
1647
1648

1649
1650
1651
1652
1653
1654
1655
/*
** Open a database file.  Return a pointer to the new database
** connection.  An error results in process abort.
*/
LOCAL sqlite3 *db_open(const char *zDbName){
  int rc;
  sqlite3 *db;


  if( g.fSqlTrace ) fossil_trace("-- sqlite3_open: [%s]\n", zDbName);





  if( strcmp(zDbName, g.nameOfExe)==0 ){
    extern int sqlite3_appendvfs_init(
      sqlite3 *, char **, const sqlite3_api_routines *
    );
    sqlite3_appendvfs_init(0,0,0);
    g.zVfsName = "apndvfs";
  }

  rc = sqlite3_open_v2(
       zDbName, &db,
       SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE,
       g.zVfsName
  );
  if( rc!=SQLITE_OK ){
    db_err("[%s]: %s", zDbName, sqlite3_errmsg(db));







>


>
>
>
>
>
|






>







1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
/*
** Open a database file.  Return a pointer to the new database
** connection.  An error results in process abort.
*/
LOCAL sqlite3 *db_open(const char *zDbName){
  int rc;
  sqlite3 *db;
  Blob bNameCheck = BLOB_INITIALIZER;

  if( g.fSqlTrace ) fossil_trace("-- sqlite3_open: [%s]\n", zDbName);
  file_canonical_name(zDbName, &bNameCheck, 0)
    /* For purposes of the apndvfs check, g.nameOfExe and zDbName must
    ** both be canonicalized, else chances are very good that they
    ** will not match even if they're the same file. Details:
    ** https://fossil-scm.org/forum/forumpost/16880a28aad1a868 */;
  if( strcmp(blob_str(&bNameCheck), g.nameOfExe)==0 ){
    extern int sqlite3_appendvfs_init(
      sqlite3 *, char **, const sqlite3_api_routines *
    );
    sqlite3_appendvfs_init(0,0,0);
    g.zVfsName = "apndvfs";
  }
  blob_zero(&bNameCheck);
  rc = sqlite3_open_v2(
       zDbName, &db,
       SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE,
       g.zVfsName
  );
  if( rc!=SQLITE_OK ){
    db_err("[%s]: %s", zDbName, sqlite3_errmsg(db));

Changes to src/main.c.

430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
  g.argv = argv;
  sqlite3_initialize();
#if defined(_WIN32) && defined(BROKEN_MINGW_CMDLINE)
  for(i=0; i<g.argc; i++) g.argv[i] = fossil_mbcs_to_utf8(g.argv[i]);
#else
  for(i=0; i<g.argc; i++) g.argv[i] = fossil_path_to_utf8(g.argv[i]);
#endif
#if defined(_WIN32)
  GetModuleFileNameW(NULL, buf, MAX_PATH);
  g.nameOfExe = fossil_path_to_utf8(buf);
#else
  g.nameOfExe = g.argv[0];
#endif
  for(i=1; i<g.argc-1; i++){
    z = g.argv[i];
    if( z[0]!='-' ) continue;
    z++;
    if( z[0]=='-' ) z++;
    if( z[0]==0 ) return;   /* Stop searching at "--" */
    if( fossil_strcmp(z, "args")==0 ) break;







<
<
<
<
|
<







430
431
432
433
434
435
436




437

438
439
440
441
442
443
444
  g.argv = argv;
  sqlite3_initialize();
#if defined(_WIN32) && defined(BROKEN_MINGW_CMDLINE)
  for(i=0; i<g.argc; i++) g.argv[i] = fossil_mbcs_to_utf8(g.argv[i]);
#else
  for(i=0; i<g.argc; i++) g.argv[i] = fossil_path_to_utf8(g.argv[i]);
#endif




  g.nameOfExe = file_fullexename(g.argv[0]);

  for(i=1; i<g.argc-1; i++){
    z = g.argv[i];
    if( z[0]!='-' ) continue;
    z++;
    if( z[0]=='-' ) z++;
    if( z[0]==0 ) return;   /* Stop searching at "--" */
    if( fossil_strcmp(z, "args")==0 ) break;