]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Get kvvfs::xAccess() fleshed out.
authorstephan <stephan@noemail.net>
Tue, 2 Dec 2025 18:10:53 +0000 (18:10 +0000)
committerstephan <stephan@noemail.net>
Tue, 2 Dec 2025 18:10:53 +0000 (18:10 +0000)
FossilOrigin-Name: d947e9bed5affee3f6e54b0fe3e2b1a0ac3771865b93c06a4087318f26d87f7f

ext/wasm/api/sqlite3-vfs-kvvfs.c-pp.js
ext/wasm/tester1.c-pp.js
manifest
manifest.uuid

index caada9c31b93605172a747e12f99aefaa6cf09a0..c1a0d97e9ce8da10333e77323127705e55e29dce 100644 (file)
@@ -360,6 +360,29 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
     listeners: undefined
   });
 
+  /**
+     Public interface for kvvfs v2. The capi.sqlite3_js_kvvfs_...()
+     routines remain in place for v1. Some members of this class proxy
+     to those functions but use different default argument values in
+     some cases.
+  */
+  const kvvfs = sqlite3.kvvfs = Object.create(null);
+  if( sqlite3.__isUnderTest ){
+    /* For inspection via the dev tools console. */
+    kvvfs.log = Object.assign(Object.create(null),{
+      xOpen: false,
+      xClose: false,
+      xWrite: false,
+      xRead: false,
+      xSync: false,
+      xAccess: false,
+      xFileControl: false,
+      xRcrdRead: false,
+      xRcrdWrite: false,
+      xRcrdDelete: false,
+    });
+  }
+
   /**
      Deletes the cache.storagePool entries for store (a
      cache.storagePool entry) and its db/journal counterpart.
@@ -368,7 +391,8 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
     const other = cache.rxJournalSuffix.test(store.jzClass)
           ? store.jzClass.replace(cache.rxJournalSuffix,'')
           : store.jzClass+'-journal';
-    debug("cleaning up storage handles [", store.jzClass, other,"]",store);
+    kvvfs?.log?.xClose
+      && debug("cleaning up storage handles [", store.jzClass, other,"]",store);
     delete cache.storagePool[store.jzClass];
     delete cache.storagePool[other];
     if( !sqlite3.__isUnderTest ){
@@ -634,13 +658,12 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
   const originalIoMethods = (kvvfsFile)=>
         originalMethods[kvvfsFile.$isJournal ? 'ioJrnl' : 'ioDb'];
 
-  /**
-     Public interface for kvvfs v2. The capi.sqlite3_js_kvvfs_...()
-     routines remain in place for v1. Some members of this class proxy
-     to those functions but use different default argument values in
-     some cases.
-  */
-  const kvvfs = sqlite3.kvvfs = Object.create(null);
+  const pVfs = new capi.sqlite3_vfs(kvvfsMethods.$pVfs);
+  const pIoDb = new capi.sqlite3_io_methods(kvvfsMethods.$pIoDb);
+  const pIoJrnl = new capi.sqlite3_io_methods(kvvfsMethods.$pIoJrnl);
+  const recordHandler =
+        Object.create(null)/** helper for some vfs
+                               routines. Populated later. */;
   const kvvfsInternal = Object.assign(Object.create(null),{
     pFileHandles,
     cache,
@@ -654,29 +677,11 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
     */
     disablePageSizeChange: true
   });
-  if( sqlite3.__isUnderTest ){
-    /* For inspection via the dev tools console. */
+  if( kvvfs.log ){
+    // this is a test build
     kvvfs.internal = kvvfsInternal;
-    kvvfs.log = Object.assign(Object.create(null),{
-      xOpen: false,
-      xClose: false,
-      xWrite: false,
-      xRead: false,
-      xSync: false,
-      xFileControl: false,
-      xRcrdRead: false,
-      xRcrdWrite: false,
-      xRcrdDelete: false,
-    });
   }
 
-  const pVfs = new capi.sqlite3_vfs(kvvfsMethods.$pVfs);
-  const pIoDb = new capi.sqlite3_io_methods(kvvfsMethods.$pIoDb);
-  const pIoJrnl = new capi.sqlite3_io_methods(kvvfsMethods.$pIoJrnl);
-  const recordHandler =
-        Object.create(null)/** helper for some vfs
-                               routines. Populated later. */;
-
   /**
      Implementations for members of the object referred to by
      sqlite3__wasm_kvvfs_methods(). We swap out some native
@@ -793,6 +798,10 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
       xOpen: function(pProtoVfs,zName,pProtoFile,flags,pOutFlags){
         cache.popError();
         let zToFree /* alloc()'d memory for temp db name */;
+        if( 0 ){
+          /* tester1.js makes it a lot further if we do this. */
+          flags |= capi.SQLITE_OPEN_CREATE;
+        }
         try{
           if( !zName ){
             zToFree = wasm.allocCString(""+pProtoFile+"."
@@ -841,7 +850,8 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
             installStorageAndJournal(s);
             s.files.push(f);
             s.deleteAtRefc0 = deleteAt0;
-            debug("xOpen installed storage handle [",nm, nm+"-journal","]", s);
+            kvvfs?.log?.xOpen
+              && debug("xOpen installed storage handle [",nm, nm+"-journal","]", s);
           }
           pFileHandles.set(pProtoFile, {store: s, file: f, jzClass});
           s.listeners && notifyListeners('open', s, s.files.length);
@@ -874,14 +884,35 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
       xAccess: function(pProtoVfs, zPath, flags, pResOut){
         cache.popError();
         try{
-          /**
-             In every test run to date, if this function sets
-             *pResOut to anything other than 0, the VFS fails to
-             function.  Why that that is is a mystery. How it seems
-             to work despite never reporting "file found" is a
-             mystery.
-          */
-          wasm.poke32(pResOut, 0);
+          const s = storageForZClass(zPath);
+          const jzPath = s?.jzClass || wasm.cstrToJs(zPath);
+          if( kvvfs?.log?.xAccess ){
+            debug("xAccess",jzPath,"flags =",
+                  flags,"*pResOut =",wasm.peek32(pResOut),
+                  "store =",s);
+          }
+          if( !s ){
+            /** The xAccess method returns [SQLITE_OK] on success or some
+             ** non-zero error code if there is an I/O error or if the name of
+             ** the file given in the second argument is illegal.
+             */
+            validateStorageName(jzPath);
+          }
+          if( s ){
+            const key = s.keyPrefix+
+                  (cache.rxJournalSuffix.test(jzPath) ? "jrnl" : "1");
+            const res = s.storage.getItem(key) ? 0 : 1;
+            /* This res value looks completely backwards to me, and
+               is the opposite of the native kvvfs's impl, but it's
+               working, whereas reimplementing the native one
+               faithfully does not. Read the lib-level code of where
+               this is invoked, my expectation is that we set res to 0
+               for not-exists. */
+            //warn("access res",jzPath,res);
+            wasm.poke32(pResOut, res);
+          }else{
+            wasm.poke32(pResOut, 0);
+          }
           return 0;
         }catch(e){
           error('xAccess',e);
index e0eb6673ee82f9c9945c00628da1ea62a081e744..29cdc70a9fdb97c51c4c1a92c9ecfc6a46b6f636 100644 (file)
@@ -3193,7 +3193,8 @@ globalThis.sqlite3InitModule = sqlite3InitModule;
                       "select page_size from pragma_page_size()"
                     ));
             }
-            kvvfs.log.xFileControl = true;
+            //kvvfs.log.xFileControl = true;
+            //kvvfs.log.xAccess = true;
             db.exec([
               "BEGIN;",
               "insert into kvvfs(a) values(randomblob(16000/*>pg size*/));",
@@ -3214,7 +3215,7 @@ globalThis.sqlite3InitModule = sqlite3InitModule;
                      "got",gotPageSize);
             T.assert(expectRows === duo.selectValue(sqlCount),
                      "Unexpected record count.");
-            kvvfs.log.xFileControl = false;
+            kvvfs.log.xAccess = kvvfs.log.xFileControl = false;
             T.assert(expectRows === duo.selectValue(sqlCount),
                      "Unexpected record count.");
             exp = exportDb(expOpt);
index 5b26201fd3d522c74217b4fc49b9ee482660c061..546ba528e7577a0fa6bf93b9a56cf0653db57d84 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Consolidate\skvvfs's\spage\ssize\sworkaround\sinto\sa\scentral\sflag\sand\sadd\ssome\slogging\sto\sfacilitate\stesting\sand\sdebugging.
-D 2025-12-02T16:29:28.643
+C Get\skvvfs::xAccess()\sfleshed\sout.
+D 2025-12-02T18:10:53.321
 F .fossil-settings/binary-glob 61195414528fb3ea9693577e1980230d78a1f8b0a54c78cf1b9b24d0a409ed6a x
 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
@@ -600,7 +600,7 @@ F ext/wasm/api/sqlite3-api-worker1.c-pp.js 1041dd645e8e821c082b628cd8d9acf70c667
 F ext/wasm/api/sqlite3-license-version-header.js 0c807a421f0187e778dc1078f10d2994b915123c1223fe752b60afdcd1263f89
 F ext/wasm/api/sqlite3-opfs-async-proxy.js 9654b565b346dc609b75d15337f20acfa7af7d9d558da1afeb9b6d8eaa404966
 F ext/wasm/api/sqlite3-vfs-helper.c-pp.js 3f828cc66758acb40e9c5b4dcfd87fd478a14c8fb7f0630264e6c7fa0e57515d
-F ext/wasm/api/sqlite3-vfs-kvvfs.c-pp.js 08c8b8546c89f2e5bfa52ccc659db9d4dc01955cf4407407cb1e123c47b66e30
+F ext/wasm/api/sqlite3-vfs-kvvfs.c-pp.js 9aa012b9b9953548d2cc541adbb12b8619fae3e3e023626d06c2b93aeaada73c
 F ext/wasm/api/sqlite3-vfs-opfs-sahpool.c-pp.js a2eea6442556867b589e04107796c6e1d04a472219529eeb45b7cd221d7d048b
 F ext/wasm/api/sqlite3-vfs-opfs.c-pp.js 88ce2078267a2d1af57525a32d896295f4a8db7664de0e17e82dc9ff006ed8d3
 F ext/wasm/api/sqlite3-vtab-helper.c-pp.js 366596d8ff73d4cefb938bbe95bc839d503c3fab6c8335ce4bf52f0d8a7dee81
@@ -647,7 +647,7 @@ F ext/wasm/test-opfs-vfs.html 1f2d672f3f3fce810dfd48a8d56914aba22e45c6834e262555
 F ext/wasm/test-opfs-vfs.js 1618670e466f424aa289859fe0ec8ded223e42e9e69b5c851f809baaaca1a00c
 F ext/wasm/tester1-worker.c-pp.html 0e432ec2c0d99cd470484337066e8d27e7aee4641d97115338f7d962bf7b081a
 F ext/wasm/tester1.c-pp.html 52d88fe2c6f21a046030a36410b4839b632f4424028197a45a3d5669ea724ddb
-F ext/wasm/tester1.c-pp.js e34021c29b7bd0cdcba9cb5fa0ee6efc9509f46b0c97120698ddbc388245c086
+F ext/wasm/tester1.c-pp.js c1c42f246c063409cbcf533e0fdcbe5e72de66664ea8e110eecce27e7affcb31
 F ext/wasm/tests/opfs/concurrency/index.html 657578a6e9ce1e9b8be951549ed93a6a471f4520a99e5b545928668f4285fb5e
 F ext/wasm/tests/opfs/concurrency/test.js d08889a5bb6e61937d0b8cbb78c9efbefbf65ad09f510589c779b7cc6a803a88
 F ext/wasm/tests/opfs/concurrency/worker.js 0a8c1a3e6ebb38aabbee24f122693f1fb29d599948915c76906681bb7da1d3d2
@@ -2180,8 +2180,8 @@ F tool/version-info.c 33d0390ef484b3b1cb685d59362be891ea162123cea181cb8e6d2cf6dd
 F tool/warnings-clang.sh bbf6a1e685e534c92ec2bfba5b1745f34fb6f0bc2a362850723a9ee87c1b31a7
 F tool/warnings.sh d924598cf2f55a4ecbc2aeb055c10bd5f48114793e7ba25f9585435da29e7e98
 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f
-P 0bf0b8a98a2cc5128aa0e510ef2fe411a6859ce807d6159175f5eaf3bc14183b
-R bdf2c95d466c8e43e29937d2fd3fb9ba
+P 8d683130d2f2aaf6300a8c858802eb671e831ed520621af59c9e830e87a9d753
+R d11120ed294f213ba2dd31d3a01d4d3b
 U stephan
-Z b42a739c26e9a29ed2bf89c88b59d1d6
+Z 6db5eec4505b09e9eded658344d6b133
 # Remove this line to create a well-formed Fossil manifest.
index 70ed40ac4a117ad1077bfc5064d74e97e3498a2b..63818b0217c446928080128ab6d3dc8220ae4309 100644 (file)
@@ -1 +1 @@
-8d683130d2f2aaf6300a8c858802eb671e831ed520621af59c9e830e87a9d753
+d947e9bed5affee3f6e54b0fe3e2b1a0ac3771865b93c06a4087318f26d87f7f