diff --git a/pkg/lib/cockpit-components-file-autocomplete.jsx b/pkg/lib/cockpit-components-file-autocomplete.jsx index f09002ba0539..33db69edc7b6 100644 --- a/pkg/lib/cockpit-components-file-autocomplete.jsx +++ b/pkg/lib/cockpit-components-file-autocomplete.jsx @@ -23,6 +23,8 @@ import { Select, SelectOption } from "@patternfly/react-core/dist/esm/deprecated import PropTypes from "prop-types"; import { debounce } from 'throttle-debounce'; +import { fsinfo } from "cockpit/fsinfo"; + const _ = cockpit.gettext; export class FileAutoComplete extends React.Component { @@ -58,7 +60,7 @@ export class FileAutoComplete extends React.Component { path = value.slice(0, value.length - 1); const match = this.state.displayFiles - .find(entry => (entry.type == 'directory' && entry.path == path + '/') || (entry.type == 'file' && entry.path == path)); + .find(entry => (entry.type == 'dir' && entry.path == path + '/') || (entry.type == 'reg' && entry.path == path)); if (match) { // If match file path is a prefix of another file, do not update current directory, @@ -67,7 +69,7 @@ export class FileAutoComplete extends React.Component { const isPrefix = this.state.displayFiles.filter(entry => entry.path.startsWith(value)).length > 1; // If the inserted string corresponds to a directory listed in the results // update the current directory and refetch results - if (match.type == 'directory' && !isPrefix) + if (match.type == 'dir' && !isPrefix) cb(match.path); else this.setState({ value: match.path }); @@ -91,7 +93,7 @@ export class FileAutoComplete extends React.Component { onCreateOption(newValue) { this.setState(prevState => ({ - displayFiles: [...prevState.displayFiles, { type: "file", path: newValue }] + displayFiles: [...prevState.displayFiles, { type: "reg", path: newValue }] })); } @@ -99,30 +101,17 @@ export class FileAutoComplete extends React.Component { if (this.state.directory == path) return; - const channel = cockpit.channel({ - payload: "fslist1", - path, - superuser: this.props.superuser, - watch: false, - }); - const results = []; - - channel.addEventListener("ready", () => { - this.finishUpdate(results, null, path); - }); - - channel.addEventListener("close", (ev, data) => { - this.finishUpdate(results, data.message, path); - }); - - channel.addEventListener("message", (ev, data) => { - const item = JSON.parse(data); - if (item && item.path && item.event == 'present' && - (!this.props.onlyDirectories || item.type == 'directory')) { - item.path = item.path + (item.type == 'directory' ? '/' : ''); - results.push(item); - } - }); + fsinfo(path, ['type', 'entries'], { superuser: this.props.superuser }) + .then(info => { + const results = []; + for (const name in info.entries ?? {}) { + const type = info.entries[name].type; + if (!this.props.onlyDirectories || type == 'dir') + results.push({ type, path: name + (type == 'dir' ? '/' : '') }); + } + this.finishUpdate(results, null, path); + }) + .catch(error => this.finishUpdate([], error.message, path)); } finishUpdate(results, error, directory) { @@ -137,7 +126,7 @@ export class FileAutoComplete extends React.Component { if (directory) { listItems.unshift({ - type: "directory", + type: "dir", path: directory }); } diff --git a/test/verify/check-shell-keys b/test/verify/check-shell-keys index 17c2030bef66..42e211b095ea 100755 --- a/test/verify/check-shell-keys +++ b/test/verify/check-shell-keys @@ -313,7 +313,7 @@ session optional pam_ssh_add.so b.wait_in_text("#credentials-modal .pf-v5-c-select__menu-item.pf-m-disabled", "No such file or directory") b.focus("#credentials-modal .pf-v5-c-select__toggle-typeahead input") b.key("Backspace", 5) - b.wait_visible("#credentials-modal .pf-v5-c-select__menu-item.directory:contains('/var/lib/')") + b.wait_visible("#credentials-modal .pf-v5-c-select__menu-item.dir:contains('/var/lib/')") b.click("#credentials-modal .pf-v5-c-select__toggle-clear") b.wait_val("#credentials-modal .pf-v5-c-select__toggle-typeahead input", "")