From f91fd9aea04290768fde131cf182d928c42b3c77 Mon Sep 17 00:00:00 2001 From: joshuaboud Date: Wed, 26 Oct 2022 17:37:56 -0300 Subject: [PATCH 1/3] Allow 'edit anyway' option for non-text files fixes #50 --- navigator/components/NavFile.js | 51 +++++++++++++++++---------------- 1 file changed, 26 insertions(+), 25 deletions(-) diff --git a/navigator/components/NavFile.js b/navigator/components/NavFile.js index 170138b..2b38439 100644 --- a/navigator/components/NavFile.js +++ b/navigator/components/NavFile.js @@ -41,18 +41,18 @@ export class NavFile extends NavEntry { * @param {Event} e */ handleEvent(e) { - switch(e.type){ + switch (e.type) { case "click": if (this.double_click) { - if(this.timeout) + if (this.timeout) clearTimeout(this.timeout); this.double_click = false; this.open(); return; } else { // single click this.double_click = true; - if(this.timeout) - clearTimeout(this.timeout) + if (this.timeout) + clearTimeout(this.timeout); this.timeout = setTimeout(() => { this.double_click = false; }, 500); @@ -77,7 +77,7 @@ export class NavFile extends NavEntry { return new Promise((resolve, reject) => { var proc = cockpit.spawn( ["rm", "-f", this.path_str()], - {superuser: "try", err: "out"} + { superuser: "try", err: "out" } ); proc.done((data) => { resolve(); @@ -87,20 +87,21 @@ export class NavFile extends NavEntry { }); }); } - + async open() { - var proc_output = await cockpit.spawn(["file", "--mime-type", this.path_str()], {superuser: "try"}); - var fields = proc_output.split(/:(?=[^:]+$)/); // ensure it's the last : with lookahead - var type = fields[1].trim(); - - if (/^text/.test(type) || /^inode\/x-empty$/.test(type) || this.stat["size"] === 0 || (/^application\/octet-stream/.test(type) && this.stat["size"] === 1)) { + async function isEditable(path, fileSize) { + if (fileSize === 0) + return true; // empty file always editable + const encoding = (await cockpit.spawn(["file", "-bL", "--mime-encoding", path], { superuser: "try" })).trim(); + if (['us-ascii', 'utf-8'].includes(encoding)) + return true; + if (fileSize === 1 && ['\n', '\t', ' '].includes(await cockpit.file(path).read())) + return true; // special case for empty file with newline, shows as `application/octet-stream; charset=binary` + return false; + } + + if (await isEditable(this.path_str(), this.stat['size']) || await this.nav_window_ref.modal_prompt.confirm(`'${this.filename}' is not a text file. Open it anyway?`, "WARNING: this may lead to file corruption.", true)) { this.show_edit_file_contents(); - } else { - console.log("Unknown mimetype: " + type); - if (await this.nav_window_ref.modal_prompt.confirm("Can't open " + this.filename + " for editing.", "Download it instead?")) { - var download = new NavDownloader(this); - download.download(); - } } } @@ -109,7 +110,7 @@ export class NavFile extends NavEntry { this.nav_window_ref.disable_buttons_for_editing(); var contents = ""; try { - contents = await cockpit.file(this.path_str(), {superuser: "try"}).read(); + contents = await cockpit.file(this.path_str(), { superuser: "try" }).read(); } catch (e) { this.nav_window_ref.enable_buttons(); this.nav_window_ref.modal_prompt.alert(e.message); @@ -124,7 +125,7 @@ export class NavFile extends NavEntry { document.getElementById("nav-contents-view-holder").style.display = "none"; document.getElementById("nav-edit-contents-view").style.display = "flex"; } - + async write_to_file() { var new_contents = document.getElementById("nav-edit-contents-textarea").value; try { @@ -135,7 +136,7 @@ export class NavFile extends NavEntry { this.nav_window_ref.refresh(); this.hide_edit_file_contents(); } - + hide_edit_file_contents() { window.addEventListener("keydown", this.nav_window_ref); document.getElementById("nav-edit-contents-textarea").removeEventListener("keydown", this); @@ -145,7 +146,7 @@ export class NavFile extends NavEntry { } } -export class NavFileLink extends NavFile{ +export class NavFileLink extends NavFile { /** * * @param {string} path @@ -187,10 +188,10 @@ export class NavFileLink extends NavFile{ async open() { var target_path = this.get_link_target_path(); - var proc_output = await cockpit.spawn(["file", "--mime-type", target_path], {superuser: "try"}); + var proc_output = await cockpit.spawn(["file", "--mime-type", target_path], { superuser: "try" }); var fields = proc_output.split(/:(?=[^:]+$)/); // ensure it's the last : with lookahead var type = fields[1].trim(); - + if ((/^text/.test(type) || /^inode\/x-empty$/.test(type) || this.stat["size"] === 0)) { this.show_edit_file_contents(); } else { @@ -206,8 +207,8 @@ export class NavFileLink extends NavFile{ var target_path = this.get_link_target_path(); var contents = ""; try { - contents = await cockpit.file(target_path, {superuser: "try"}).read(); - } catch(e) { + contents = await cockpit.file(target_path, { superuser: "try" }).read(); + } catch (e) { this.nav_window_ref.enable_buttons(); this.nav_window_ref.modal_prompt.alert(e.message); return; From c6f132bcb5f492de6b8fa5363630a85a6165424f Mon Sep 17 00:00:00 2001 From: joshuaboud Date: Wed, 26 Oct 2022 17:38:42 -0300 Subject: [PATCH 2/3] disallow changing selection while editing perms fixes #45 --- navigator/components/NavWindow.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/navigator/components/NavWindow.js b/navigator/components/NavWindow.js index 29d56ef..37570f3 100644 --- a/navigator/components/NavWindow.js +++ b/navigator/components/NavWindow.js @@ -210,6 +210,8 @@ export class NavWindow { } clear_selected() { + if (this.editing_permissions) + return; for (let entry of this.selected_entries) { entry.unstyle_selected(); } @@ -221,11 +223,15 @@ export class NavWindow { * @param {NavEntry} entry */ select_one(entry) { + if (this.editing_permissions) + return; entry.style_selected(); this.selected_entries.add(entry); } deselect_one(entry) { + if (this.editing_permissions) + return; entry.unstyle_selected(); this.selected_entries.delete(entry); } @@ -236,6 +242,8 @@ export class NavWindow { * @param {NavEntry} end */ select_range(start, end) { + if (this.editing_permissions) + return; let start_ind = this.entries.indexOf(start); let end_ind = this.entries.indexOf(end); if (start_ind === -1 || end_ind === -1) @@ -252,6 +260,8 @@ export class NavWindow { } reset_selection() { + if (this.editing_permissions) + return; this.clear_selected(); this.select_one(this.pwd()); this.last_selected_entry = null; @@ -268,6 +278,8 @@ export class NavWindow { * @param {Boolean} ctrl */ set_selected(target, shift, ctrl) { + if (this.editing_permissions) + return; if (!ctrl && !shift) this.clear_selected(); if (!shift || !this.last_selected_entry) @@ -299,6 +311,8 @@ export class NavWindow { } select_all() { + if (this.editing_permissions) + return; this.clear_selected(); this.select_range(this.entries[0], this.entries[this.entries.length - 1]); this.update_selection_info(); @@ -395,11 +409,13 @@ export class NavWindow { document.getElementById("nav-mode-preview").innerText = "unchanged"; document.getElementById("nav-edit-properties").style.display = "flex"; document.getElementById("nav-show-properties").style.display = "none"; + this.editing_permissions = true; } hide_edit_selected() { document.getElementById("nav-show-properties").style.display = "flex"; document.getElementById("nav-edit-properties").style.display = "none"; + this.editing_permissions = false; } /** From 147d9ae7ca25051036830f5463c7820b92145ed6 Mon Sep 17 00:00:00 2001 From: joshuaboud Date: Wed, 26 Oct 2022 17:45:28 -0300 Subject: [PATCH 3/3] package 0.5.10 --- CHANGELOG.md | 5 +++-- README.md | 10 +++++----- manifest.json | 4 ++-- packaging/el7/main.spec | 3 +++ packaging/el8/main.spec | 3 +++ packaging/focal/changelog | 7 +++++++ 6 files changed, 23 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6ab1644..1a93e19 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,4 @@ -## Cockpit Navigator 0.5.9-1 +## Cockpit Navigator 0.5.10-1 -* Fix CSS for Cockpit 273 and greater \ No newline at end of file +* Disallow changing selected file/folder while editing permissions +* Allow opening non-text file for editing via prompt \ No newline at end of file diff --git a/README.md b/README.md index 1111f20..6a3849a 100644 --- a/README.md +++ b/README.md @@ -23,17 +23,17 @@ With no command line use needed, you can: # Installation ## From Github Release ### Ubuntu -1. `$ wget https://github.com/45Drives/cockpit-navigator/releases/download/v0.5.8/cockpit-navigator_0.5.8-1focal_all.deb` -1. `# apt install ./cockpit-navigator_0.5.8-1focal_all.deb` +1. `$ wget https://github.com/45Drives/cockpit-navigator/releases/download/v0.5.10/cockpit-navigator_0.5.10-1focal_all.deb` +1. `# apt install ./cockpit-navigator_0.5.10-1focal_all.deb` ### EL7 -1. `# yum install https://github.com/45Drives/cockpit-navigator/releases/download/v0.5.8/cockpit-navigator-0.5.8-1.el7.noarch.rpm` +1. `# yum install https://github.com/45Drives/cockpit-navigator/releases/download/v0.5.10/cockpit-navigator-0.5.10-1.el7.noarch.rpm` ### EL8 -1. `# dnf install https://github.com/45Drives/cockpit-navigator/releases/download/v0.5.8/cockpit-navigator-0.5.8-1.el8.noarch.rpm` +1. `# dnf install https://github.com/45Drives/cockpit-navigator/releases/download/v0.5.10/cockpit-navigator-0.5.10-1.el8.noarch.rpm` ## From Source 1. Ensure dependencies are installed: `cockpit`, `python3`, `rsync`, `zip`. 1. `$ git clone https://github.com/45Drives/cockpit-navigator.git` 1. `$ cd cockpit-navigator` -1. `$ git checkout ` (v0.5.8 is latest) +1. `$ git checkout ` (v0.5.10 is latest) 1. `# make install` ## From 45Drives Repositories ### Automatic Repo Setup with Script diff --git a/manifest.json b/manifest.json index 7961ca5..a881320 100644 --- a/manifest.json +++ b/manifest.json @@ -3,7 +3,7 @@ "name": "cockpit-navigator", "title": "Cockpit Navigator", "prerelease": false, - "version": "0.5.9", + "version": "0.5.10", "buildVersion": "1", "author": "Josh Boudreau ", "url": "https://github.com/45Drives/cockpit-navigator", @@ -59,7 +59,7 @@ ], "changelog": { "urgency": "medium", - "version": "0.5.9", + "version": "0.5.10", "buildVersion": "1", "ignore": [], "date": null, diff --git a/packaging/el7/main.spec b/packaging/el7/main.spec index ece1a35..163ac29 100644 --- a/packaging/el7/main.spec +++ b/packaging/el7/main.spec @@ -32,6 +32,9 @@ rm -rf %{buildroot} /usr/share/cockpit/navigator/* %changelog +* Wed Oct 26 2022 Joshua Boudreau 0.5.10-1 +- Disallow changing selected file/folder while editing permissions +- Allow opening non-text file for editing via prompt * Fri Aug 05 2022 Joshua Boudreau 0.5.9-1 - Fix CSS for Cockpit 273 and greater * Mon Jun 06 2022 Joshua Boudreau 0.5.8-2 diff --git a/packaging/el8/main.spec b/packaging/el8/main.spec index ece1a35..163ac29 100644 --- a/packaging/el8/main.spec +++ b/packaging/el8/main.spec @@ -32,6 +32,9 @@ rm -rf %{buildroot} /usr/share/cockpit/navigator/* %changelog +* Wed Oct 26 2022 Joshua Boudreau 0.5.10-1 +- Disallow changing selected file/folder while editing permissions +- Allow opening non-text file for editing via prompt * Fri Aug 05 2022 Joshua Boudreau 0.5.9-1 - Fix CSS for Cockpit 273 and greater * Mon Jun 06 2022 Joshua Boudreau 0.5.8-2 diff --git a/packaging/focal/changelog b/packaging/focal/changelog index 77c9a05..7abc0e1 100644 --- a/packaging/focal/changelog +++ b/packaging/focal/changelog @@ -1,3 +1,10 @@ +cockpit-navigator (0.5.10-1focal) focal; urgency=medium + + * Disallow changing selected file/folder while editing permissions + * Allow opening non-text file for editing via prompt + + -- Joshua Boudreau Wed, 26 Oct 2022 14:40:50 -0300 + cockpit-navigator (0.5.9-1focal) focal; urgency=medium * Fix CSS for Cockpit 273 and greater