From 437ec540b883bc259328f2fe60ab6d04d7f4c7ea Mon Sep 17 00:00:00 2001 From: William Stein Date: Sat, 11 Nov 2023 14:41:27 +0000 Subject: [PATCH] fix major bug where directory listings were truncated --- websocketfs/lib/sftp-fuse.ts | 18 +++++++++++++----- websocketfs/package.json | 2 +- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/websocketfs/lib/sftp-fuse.ts b/websocketfs/lib/sftp-fuse.ts index 5eb3771..1d1c548 100644 --- a/websocketfs/lib/sftp-fuse.ts +++ b/websocketfs/lib/sftp-fuse.ts @@ -354,11 +354,22 @@ export default class SftpFuse { return; } try { - let handle, items; + let handle; + let items: any[] = []; try { handle = await callback(this.sftp.opendir, path); log("readdir - opendir got a handle", handle._handle); - items = await callback(this.sftp.readdir, handle); + // We read repeatedly chunks of files from the backend until done. + // (Usually 64 files are sent, but looking at the source code if the names + // are really long, then I think less could be, so assuming that less than + // 64 means we are done may be a bad optimization to make!). + while (true) { + const nextItems = await callback(this.sftp.readdir, handle); + if (typeof nextItems == "boolean" || nextItems.length == 0) { + break; + } + items = items.concat(nextItems); + } } finally { // do not block on this. this.sftp.close(handle, (err) => { @@ -367,9 +378,6 @@ export default class SftpFuse { } //log("readdir - items", items); // todo: cache attrs from items (?) - if (typeof items == "boolean") { - throw Error("readdir fail"); - } const filenames = items.map(({ filename }) => filename); if (this.attrCache != null) { for (const { filename, stats, longname } of items) { diff --git a/websocketfs/package.json b/websocketfs/package.json index 7e7d9ec..d50ce1c 100644 --- a/websocketfs/package.json +++ b/websocketfs/package.json @@ -1,6 +1,6 @@ { "name": "websocketfs", - "version": "0.10.2", + "version": "0.10.3", "description": "Like sshfs, but over a WebSocket", "main": "./dist/lib/index.js", "scripts": {