Skip to content

Commit

Permalink
Merge pull request #55 from 45Drives/0.5.10-fixes
Browse files Browse the repository at this point in the history
0.5.10 fixes
  • Loading branch information
joshuaboud authored Oct 26, 2022
2 parents d70d66f + 147d9ae commit cf7910c
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 34 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
## Cockpit Navigator 0.5.9-1
## Cockpit Navigator 0.5.10-1

* Fix CSS for Cockpit 273 and greater
* Disallow changing selected file/folder while editing permissions
* Allow opening non-text file for editing via prompt
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <version>` (v0.5.8 is latest)
1. `$ git checkout <version>` (v0.5.10 is latest)
1. `# make install`
## From 45Drives Repositories
### Automatic Repo Setup with Script
Expand Down
4 changes: 2 additions & 2 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -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 <[email protected]>",
"url": "https://github.com/45Drives/cockpit-navigator",
Expand Down Expand Up @@ -59,7 +59,7 @@
],
"changelog": {
"urgency": "medium",
"version": "0.5.9",
"version": "0.5.10",
"buildVersion": "1",
"ignore": [],
"date": null,
Expand Down
51 changes: 26 additions & 25 deletions navigator/components/NavFile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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();
Expand All @@ -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();
}
}
}

Expand All @@ -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);
Expand All @@ -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 {
Expand All @@ -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);
Expand All @@ -145,7 +146,7 @@ export class NavFile extends NavEntry {
}
}

export class NavFileLink extends NavFile{
export class NavFileLink extends NavFile {
/**
*
* @param {string} path
Expand Down Expand Up @@ -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 {
Expand All @@ -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;
Expand Down
16 changes: 16 additions & 0 deletions navigator/components/NavWindow.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,8 @@ export class NavWindow {
}

clear_selected() {
if (this.editing_permissions)
return;
for (let entry of this.selected_entries) {
entry.unstyle_selected();
}
Expand All @@ -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);
}
Expand All @@ -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)
Expand All @@ -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;
Expand All @@ -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)
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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;
}

/**
Expand Down
3 changes: 3 additions & 0 deletions packaging/el7/main.spec
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ rm -rf %{buildroot}
/usr/share/cockpit/navigator/*

%changelog
* Wed Oct 26 2022 Joshua Boudreau <[email protected]> 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 <[email protected]> 0.5.9-1
- Fix CSS for Cockpit 273 and greater
* Mon Jun 06 2022 Joshua Boudreau <[email protected]> 0.5.8-2
Expand Down
3 changes: 3 additions & 0 deletions packaging/el8/main.spec
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ rm -rf %{buildroot}
/usr/share/cockpit/navigator/*

%changelog
* Wed Oct 26 2022 Joshua Boudreau <[email protected]> 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 <[email protected]> 0.5.9-1
- Fix CSS for Cockpit 273 and greater
* Mon Jun 06 2022 Joshua Boudreau <[email protected]> 0.5.8-2
Expand Down
7 changes: 7 additions & 0 deletions packaging/focal/changelog
Original file line number Diff line number Diff line change
@@ -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 <[email protected]> Wed, 26 Oct 2022 14:40:50 -0300

cockpit-navigator (0.5.9-1focal) focal; urgency=medium

* Fix CSS for Cockpit 273 and greater
Expand Down

0 comments on commit cf7910c

Please sign in to comment.