jvilk / BrowserFS

BrowserFS is an in-browser filesystem that emulates the Node JS filesystem API and supports storing and retrieving files from various backends.
Other
3.06k stars 216 forks source link

existsSync() not working? #300

Closed loic-meister-guild closed 1 year ago

loic-meister-guild commented 3 years ago

Is this library still maintained?

if I test to see if a directory exists in a previously created IndexedDB filesystem instance with existsSync(), I always get false. Then an error when I try to create the directory ...

My code:

(new Promise((resolve, reject) => {
    if (!fs.existsSync(stagingRoot+path.getValue())) {
        fs.mkdir(stagingRoot+path.getValue(), {recursive:true}, (err) => {
            if (err) console.log('error! = ',err)
            if (err) reject(err)
            resolve(true)
        })
    }
}))

The error:

edit:1 Uncaught (in promise) 
ApiError {syscall: "", errno: 17, code: "EEXIST", path: "/staging", stack: "Error↵    at new ApiError (https://unpkg.com/brows…r.onsuccess (https://unpkg.com/browserfs:9504:18)", …}
code: "EEXIST"
errno: 17
message: "Error: EEXIST: File exists., '/staging'"
path: "/staging"
stack: "Error↵    at new ApiError (https://unpkg.com/browserfs:127:23)↵    at Function.FileError (https://unpkg.com/browserfs:152:17)↵    at Function.EEXIST (https://unpkg.com/browserfs:158:22)↵    at https://unpkg.com/browserfs:9299:38↵    at IndexedDBRWTransaction.abort (https://unpkg.com/browserfs:9572:14)↵    at https://unpkg.com/browserfs:9298:25↵    at https://unpkg.com/browserfs:9238:26↵    at https://unpkg.com/browserfs:9215:26↵    at IDBRequest.r.onsuccess (https://unpkg.com/browserfs:9504:18)"
syscall: ""
__proto__: Error
BoryaGames commented 2 years ago

IndexedDB does not support "sync"

james-pre commented 1 year ago

@loic-meister-guild

Is this library still maintained?

Yes

if I test to see if a directory exists in a previously created IndexedDB filesystem instance with existsSync(), I always get false.

Please try with the latest dev version, it should work.

james-pre commented 1 year ago

@loic-meister-guild If you want to use sync functions with IndexedDB you need to use AsyncMirror. That should fix the issues you are having (you can then use the sync versions of mkdir).