From a3f9fb119ca343a182b1ec1c1519b1c44f8f8c48 Mon Sep 17 00:00:00 2001 From: Peter Oliver Date: Tue, 30 Apr 2024 13:19:26 +0100 Subject: [PATCH 1/2] Use provided SFTP paths if enumeration fails MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It’s common to encounter a “permission denied” error when trying to list the available paths. --- src/service/plugins/sftp.js | 38 +++++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/src/service/plugins/sftp.js b/src/service/plugins/sftp.js index 2789ff36d..b14ee29e0 100644 --- a/src/service/plugins/sftp.js +++ b/src/service/plugins/sftp.js @@ -150,22 +150,35 @@ const SFTPPlugin = GObject.registerClass({ async _listDirectories(mount) { const file = mount.get_root(); + const directories = {}; - const iter = await file.enumerate_children_async( - Gio.FILE_ATTRIBUTE_STANDARD_NAME, - Gio.FileQueryInfoFlags.NOFOLLOW_SYMLINKS, - GLib.PRIORITY_DEFAULT, - this.cancellable); + try { + const iter = await file.enumerate_children_async( + Gio.FILE_ATTRIBUTE_STANDARD_NAME, + Gio.FileQueryInfoFlags.NOFOLLOW_SYMLINKS, + GLib.PRIORITY_DEFAULT, + this.cancellable); - const infos = await iter.next_files_async(MAX_MOUNT_DIRS, - GLib.PRIORITY_DEFAULT, this.cancellable); - iter.close_async(GLib.PRIORITY_DEFAULT, null, null); + const infos = await iter.next_files_async(MAX_MOUNT_DIRS, + GLib.PRIORITY_DEFAULT, this.cancellable); + iter.close_async(GLib.PRIORITY_DEFAULT, null, null); - const directories = {}; + for (const info of infos) { + const name = info.get_name(); + directories[name] = `${file.get_uri()}${name}/`; + } + } + catch (e) { + debug(e, this.device.name); - for (const info of infos) { - const name = info.get_name(); - directories[name] = `${file.get_uri()}${name}/`; + // If no directories were found, fall back to using 'multiPaths' + if (this._mount_body.hasOwnProperty('multiPaths')) { + for (let i = 0; i < this._mount_body.multiPaths.length; i++) { + let name = this._mount_body.pathNames[i]; + let path = this._mount_body.multiPaths[i]; + directories[name] = `${file.get_uri()}${path}/`; + } + } } return directories; @@ -206,6 +219,7 @@ const SFTPPlugin = GObject.registerClass({ return; this._mounting = true; + this._mount_body = packet.body // Ensure the private key is in the keyring await this._addPrivateKey(); From af6912bf994c65ea2f4f687943ff2551f070c41e Mon Sep 17 00:00:00 2001 From: Peter Oliver Date: Tue, 30 Apr 2024 13:41:33 +0100 Subject: [PATCH 2/2] Lint. --- src/service/plugins/sftp.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/service/plugins/sftp.js b/src/service/plugins/sftp.js index b14ee29e0..daef6421c 100644 --- a/src/service/plugins/sftp.js +++ b/src/service/plugins/sftp.js @@ -167,15 +167,14 @@ const SFTPPlugin = GObject.registerClass({ const name = info.get_name(); directories[name] = `${file.get_uri()}${name}/`; } - } - catch (e) { + } catch (e) { debug(e, this.device.name); // If no directories were found, fall back to using 'multiPaths' if (this._mount_body.hasOwnProperty('multiPaths')) { for (let i = 0; i < this._mount_body.multiPaths.length; i++) { - let name = this._mount_body.pathNames[i]; - let path = this._mount_body.multiPaths[i]; + const name = this._mount_body.pathNames[i]; + const path = this._mount_body.multiPaths[i]; directories[name] = `${file.get_uri()}${path}/`; } } @@ -219,7 +218,7 @@ const SFTPPlugin = GObject.registerClass({ return; this._mounting = true; - this._mount_body = packet.body + this._mount_body = packet.body; // Ensure the private key is in the keyring await this._addPrivateKey();