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.08k stars 221 forks source link

AsyncMirror and Dropbox fails when there are subfolders with file #276

Open FredrikAleksander opened 5 years ago

FredrikAleksander commented 5 years ago

When using AsyncMirror and Dropbox, and there are subfolders with files, it fails during configure. In the error, it seems to try and fetch but uses the subfolder path twice errmsg .

I'm running the latest code from the master branch

A simple way to reproduce this error is by using this code in a web page, waiting for it to write the changes, and reload the page.

var dbx = new Dropbox.Dropbox({ fetch, accessToken: 'REDACTED' });
BrowserFS.configure({
    fs: "AsyncMirror",
    options: {
        sync: { fs: "InMemory" },
        async: {
            fs: "Dropbox",
            options: {
                client: dbx
            }
        }
    }
}, function (err) {
    if (err) { console.log(err); return; }

    var fs = BrowserFS.BFSRequire('fs');
    if(!fs.existsSync('/subfolder')) {
        fs.mkdirSync('/subfolder');
        fs.writeFileSync('/subfolder/somefile.txt', 'hello world');
    }
});
Faless commented 4 years ago

I can confirm this issue, after some debugging, it seems the reason for this is that Dropbox returns the absolute path of the file when listing directories. The AsyncMirror instead, seems to expect each entry to be the relative path to the listed directory.

I'm pretty new to the codebase, so I'm not sure which behaviour is supposed to be correct (I tend to lean towards the AsyncMirror expectations). I'll dig further.

Faless commented 4 years ago

(I tend to lean towards the AsyncMirror expectations).

Yep, official doc says

where files is an array of the names of the files in the directory excluding '.' and '..'.

so the correct behaviour is relative path. I'll look into a fix, hoping it does not break other Dropbox internals.

james-pre commented 1 year ago

@FredrikAleksander Does this bug still exist?

james-pre commented 1 year ago

Closing (stale). If you would like to reopen this issue, please do so by creating a new issue in the relevant repositories of @browser-fs