BrowserFS icon indicating copy to clipboard operation
BrowserFS copied to clipboard

existsSync() not working?

Open loic-meister-guild opened this issue 5 years ago • 1 comments

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

loic-meister-guild avatar Aug 03 '20 09:08 loic-meister-guild

IndexedDB does not support "sync"

BoryaGames avatar Mar 11 '22 08:03 BoryaGames

@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 avatar Mar 09 '23 23:03 james-pre

@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).

james-pre avatar Mar 23 '23 18:03 james-pre