zen-fs / core

A filesystem, anywhere.
https://zenfs.dev/core/
MIT License
134 stars 20 forks source link

`readdir` throws an error when withFileTypes is true #67

Closed atty303 closed 5 months ago

atty303 commented 5 months ago
    await zenfs.configure({
      mounts: {
        "/user": {
          backend: WebAccess,
          handle: await navigator.storage.getDirectory(),
          disableAsyncCache: true,
        },
      },
    });
    console.log(await zenfs.promises.readdir("/user/Path of Building/Builds", { withFileTypes: true }));

This throws error.

Error: File is not a directory
    at _ErrnoError.With (chunk-LLIBHIR3.js?v=15a94a03:8481:12)
    at WebAccessFS.getHandle (@zenfs_dom.js?v=15a94a03:227:26)
    at async WebAccessFS.stat (@zenfs_dom.js?v=15a94a03:154:20)
    at async stat (chunk-LLIBHIR3.js?v=15a94a03:13198:19)
    at async Object.readdir (chunk-LLIBHIR3.js?v=15a94a03:13340:118)
    at async DriverWorker.start (worker.ts?worker_file&type=module:94:21)

image

Since entry is already a relative path, join seems unnecessary.

-        values.push(typeof options == 'object' && options?.withFileTypes ? new Dirent(entry, await stat(join(path, entry))) : entry);
+        values.push(typeof options == 'object' && options?.withFileTypes ? new Dirent(entry, await stat(entry)) : entry);
james-pre commented 5 months ago

entries should be the list of file names, not full paths. WebAccess.readdir should return the file names, not paths. dom:08c3592 fixes this. See @zenfs/dom v0.2.11

james-pre commented 5 months ago

@atty303 I feel bad having such buggy code... Please tell me if the DOM release fixes the issue. Everything looks to be working correctly in my testing.

atty303 commented 5 months ago

Everything works well now. Thanks!