From: dan Date: Wed, 24 Jun 2026 18:51:36 +0000 (+0000) Subject: Only delete a super-journal if it contains a pointer to the current database's journa... X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=171b1cfb9b11a6ac05b42b2003ce36f7e576c42c;p=thirdparty%2Fsqlite.git Only delete a super-journal if it contains a pointer to the current database's journal. Test cases in this commit might be broken on some platforms. FossilOrigin-Name: c768be03d4885557c9520c37e3cecbf5647d358a87cd34948578a4a0a8a59a5e --- diff --git a/manifest b/manifest index d42ab302d2..6e5e12ba23 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Do\snot\sdelete\ssuper-journal\sfiles\snamed\s"xyz.9hh"\sunless\sthe\slibrary\sis\sbuilt\swith\sSQLITE_ENABLE_8_3_FILENAMES. -D 2026-06-24T18:03:20.210 +C Only\sdelete\sa\ssuper-journal\sif\sit\scontains\sa\spointer\sto\sthe\scurrent\sdatabase's\sjournal.\sTest\scases\sin\sthis\scommit\smight\sbe\sbroken\son\ssome\splatforms. +D 2026-06-24T18:51:36.470 F .fossil-settings/binary-glob 61195414528fb3ea9693577e1980230d78a1f8b0a54c78cf1b9b24d0a409ed6a x F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea @@ -725,7 +725,7 @@ F src/os_setup.h 8efc64eda6a6c2f221387eefc2e7e45fd5a3d5c8337a7a83519ba4fbd2957ae F src/os_unix.c 83759942d1ea8d59daed50901c123016f845fada74caf3496b8a2537c9a08838 F src/os_win.c 1227a3e962b017d676d985a8aec0d64f273991931ea0a0b99773651102f62df4 F src/os_win.h c06ccc3a090cf54202ea58981c298817f3309d4c9e4d52ad0a02927346493721 -F src/pager.c 743890169ec2aee165f194334334ef07ccc2f499a49f39f1a373ddcc3a643a60 +F src/pager.c 927713c6cc3033268f2c440f3ccc45081266fe956e018ce6c04092f1776215e7 F src/pager.h 6137149346e6c8a3ddc1eeb40aee46381e9bc8b0fcc6dda8a1efde993c2275b8 F src/parse.y d5a3c5b0277a441c38b35071c05e2b61ff5fc918a63309c809f4b6706179c320 F src/pcache.c 588cc3c5ccaaadde689ed35ce5c5c891a1f7b1f4d1f56f6cf0143b74d8ee6484 @@ -1448,7 +1448,7 @@ F test/misc6.test 953cc693924d88e6117aeba16f46f0bf5abede91 F test/misc7.test d595599972ec0b436985f0f02f243b68500ffc977b9b3194ec66c0866cfddcab F test/misc8.test 08d2380bc435486b12161521f225043ac2be26f02471c2c1ea4cac0b1548edbd F test/misuse.test 859f37014d9824ca66bd90c36372c08c80c51c9593a7cfa8a31d4f92cd4d5b7f -F test/mjournal.test b5cf0f006ed6e5ebee585b59c038fb452d6b7ef267c573cf3808d45006ab7adb +F test/mjournal.test dab80921515d0a7856cf4db6ac1d288a271e1b61b41b8014e9469218920ead36 F test/mmap1.test 18de3fd7b70a777af6004ca2feecfcdd3d0be17fa04058e808baf530c94b1a1d F test/mmap2.test dba452dc7db91e9df10f70bdd73dc4190c7b8ee7b5133b4684f04277ada0b9ac F test/mmap3.test b3c297e78e6a8520aafcc1a8f140535594c9086e @@ -2208,8 +2208,8 @@ F tool/warnings-clang.sh bbf6a1e685e534c92ec2bfba5b1745f34fb6f0bc2a362850723a9ee F tool/warnings.sh a554d13f6e5cf3760f041b87939e3d616ec6961859c3245e8ef701d1eafc2ca2 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f F tool/winmain.c 00c8fb88e365c9017db14c73d3c78af62194d9644feaf60e220ab0f411f3604c -P 0cdde6755837935e4feaa4367a0b107e363582adc8112a91dc7416f1100ae3aa -R f742f6a3b760fe3304ca4b954a3f0e18 +P 3973e37a1ef528676de44ddb1b1f18d55b90fca1f6b43c51c3f3ba613267bb92 +R bc7fb1e94610cf55af99479425038388 U dan -Z a2b308a7214f63948761fd690edee7c3 +Z b1fce37783a4345a4d95d4bad65d6cad # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 554a93c7e1..04d09373a3 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -3973e37a1ef528676de44ddb1b1f18d55b90fca1f6b43c51c3f3ba613267bb92 +c768be03d4885557c9520c37e3cecbf5647d358a87cd34948578a4a0a8a59a5e diff --git a/src/pager.c b/src/pager.c index a1ce9ecd56..53397037a3 100644 --- a/src/pager.c +++ b/src/pager.c @@ -2585,6 +2585,7 @@ static int pager_delsuper(Pager *pPager, const char *zSuper){ i64 nSuperJournal; /* Size of super-journal file */ char *zJournal; /* Pointer to one journal within MJ file */ char *zFree = 0; /* Free this buffer */ + int bSeen = 0; /* If super-journal contains pPager->zJournal */ /* Check if this looks like a real super-journal name. If it does not, ** return SQLITE_OK without attempting to delete it. This is to limit @@ -2632,47 +2633,56 @@ static int pager_delsuper(Pager *pPager, const char *zSuper){ zJournal = zSuperJournal; while( (zJournal-zSuperJournal)zJournal)==0 ){ + bSeen = 1; + }else{ + int exists; + rc = sqlite3OsAccess(pVfs, zJournal, SQLITE_ACCESS_EXISTS, &exists); if( rc!=SQLITE_OK ){ goto delsuper_out; } + if( exists ){ + char *zSuperPtr = 0; + + /* One of the journals pointed to by the super-journal exists. + ** Open it and check if it points at the super-journal. If + ** so, return without deleting the super-journal file. + ** NB: zJournal is really a MAIN_JOURNAL. But call it a + ** SUPER_JOURNAL here so that the VFS will not send the zJournal + ** name into sqlite3_database_file_object(). + */ + int c; + int flags = (SQLITE_OPEN_READONLY|SQLITE_OPEN_SUPER_JOURNAL); + rc = sqlite3OsOpen(pVfs, zJournal, pJournal, flags, 0); + if( rc!=SQLITE_OK ){ + goto delsuper_out; + } - rc = readSuperJournal(pJournal, 1+(u64)pVfs->mxPathname, &zSuperPtr); - sqlite3OsClose(pJournal); - if( rc!=SQLITE_OK ){ - assert( zSuperPtr==0 ); - goto delsuper_out; - } + rc = readSuperJournal(pJournal, 1+(u64)pVfs->mxPathname, &zSuperPtr); + sqlite3OsClose(pJournal); + if( rc!=SQLITE_OK ){ + assert( zSuperPtr==0 ); + goto delsuper_out; + } - c = zSuperPtr!=0 && strcmp(zSuperPtr, zSuper)==0; - freeSuperJournal(zSuperPtr); - if( c ){ - /* We have a match. Do not delete the super-journal file. */ - goto delsuper_out; + c = zSuperPtr!=0 && strcmp(zSuperPtr, zSuper)==0; + freeSuperJournal(zSuperPtr); + if( c ){ + /* We have a match. Do not delete the super-journal file. */ + goto delsuper_out; + } } } zJournal += (sqlite3Strlen30(zJournal)+1); } sqlite3OsClose(pSuper); - rc = sqlite3OsDelete(pVfs, zSuper, 0); + if( bSeen ){ + /* Only delete the super-journal if bSeen is true - indicating that + ** the super-journal contained a pointer to this database's journal + ** file. */ + rc = sqlite3OsDelete(pVfs, zSuper, 0); + } delsuper_out: sqlite3_free(zFree); diff --git a/test/mjournal.test b/test/mjournal.test index ac37a68cf6..c3b0b5fcf7 100644 --- a/test/mjournal.test +++ b/test/mjournal.test @@ -234,9 +234,7 @@ proc append_super_journal {jrnl mjname} { } set c 0 -ifcapable 8_3_names { - set c 1 -} +ifcapable 8_3_names { set c 1 } set tests [subst { 1 notamasterjournal 0 @@ -254,33 +252,41 @@ set tests [subst { 13 master-mj12G4569AA 0 }] -foreach {tn mjname bDel} { -} { - db_restore_and_reopen - execsql { - PRAGMA synchronous = OFF; - BEGIN; - INSERT INTO t1 DEFAULT VALUES; - } - - db_save_and_close - db_restore - - append_super_journal test.db-journal $mjname - set fd [open $mjname w] - puts $fd "helloworld" - close $fd - - sqlite3 db test.db - do_test 4.$tn.1 { - execsql { SELECT * FROM t1 } - file exists $mjname - } [expr !$bDel] - do_test 4.$tn.2 { - file exists test.db-journal - } {0} +foreach {tn mjname bDel} $tests { + for {set content 0} {$content<2} {incr content} { + db_restore_and_reopen + execsql { + PRAGMA synchronous = OFF; + BEGIN; + INSERT INTO t1 DEFAULT VALUES; + } + + db_save_and_close + db_restore - forcedelete $mjname + append_super_journal test.db-journal $mjname + set fd [open $mjname w] + if {$content} { + puts -nonewline $fd [file normalize test.db-journal] + puts -nonewline $fd "\0" + set mjexists [expr !$bDel] + } else { + puts -nonewline $fd "helloworld" + set mjexists 1 + } + close $fd + + sqlite3 db test.db + do_test 4.$tn.$content.1 { + execsql { SELECT * FROM t1 } + file exists $mjname + } $mjexists + do_test 4.$tn.$content.2 { + file exists test.db-journal + } {0} + + forcedelete $mjname + } } finish_test