Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use provided SFTP paths if enumeration fails #1793

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 25 additions & 12 deletions src/service/plugins/sftp.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,22 +150,34 @@ 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++) {
const name = this._mount_body.pathNames[i];
const path = this._mount_body.multiPaths[i];
directories[name] = `${file.get_uri()}${path}/`;
}
}
}

return directories;
Expand Down Expand Up @@ -206,6 +218,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();
Expand Down
Loading