From 24df60614ca3de8db863bda45f882bbfd27e926e Mon Sep 17 00:00:00 2001 From: ahmedr2001 Date: Wed, 12 Apr 2023 14:58:06 +0200 Subject: [PATCH] NavWindow: fix file permissions bug NavWindow: fix file permissions bug NavWindow: fix folder permissions bug --- navigator/components/NavWindow.js | 36 +++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/navigator/components/NavWindow.js b/navigator/components/NavWindow.js index 37570f3..cddf5e6 100644 --- a/navigator/components/NavWindow.js +++ b/navigator/components/NavWindow.js @@ -498,6 +498,9 @@ export class NavWindow { } async mkdir() { + let current_user; + var user_promise = cockpit.user(); + user_promise.then(user => current_user = user.name); let response = await this.modal_prompt.prompt("Creating Directory", { new_name: { @@ -519,14 +522,23 @@ export class NavWindow { } var promise = new Promise((resolve, reject) => { var proc = cockpit.spawn( - ["mkdir", this.pwd().path_str() + "/" + new_dir_name], - {superuser: "try", err: "out"} + ["runuser", "-u", current_user, "mkdir", this.pwd().path_str() + "/" + new_dir_name], + {superuser: "require", err: "out"} ); proc.done((data) => { resolve(); }); proc.fail((e, data) => { - reject(data); + var proc2 = cockpit.spawn( + ["mkdir", this.pwd().path_str() + "/" + new_dir_name], + {superuser: "try", err: "out"} + ); + proc2.done((data) => { + resolve(); + }); + proc2.fail((e, data) => { + reject(data); + }) }); }); try { @@ -538,6 +550,9 @@ export class NavWindow { } async touch() { + let current_user; + var user_promise = cockpit.user(); + user_promise.then(user => current_user = user.name); let response = await this.modal_prompt.prompt("Creating File", { new_name: { @@ -559,14 +574,23 @@ export class NavWindow { } var promise = new Promise((resolve, reject) => { var proc = cockpit.spawn( - ["/usr/share/cockpit/navigator/scripts/touch.py3", this.pwd().path_str() + "/" + new_file_name], - {superuser: "try", err: "out"} + ["runuser", "-u", current_user, "/usr/share/cockpit/navigator/scripts/touch.py3", this.pwd().path_str() + "/" + new_file_name], + {superuser: "require", err: "out"} ); proc.done((data) => { resolve(); }); proc.fail((e, data) => { - reject(data); + var proc2 = cockpit.spawn( + ["/usr/share/cockpit/navigator/scripts/touch.py3", this.pwd().path_str() + "/" + new_file_name], + {superuser: "try", err: "out"} + ); + proc2.done((data) => { + resolve(); + }); + proc2.fail((e, data) => { + reject(data); + }) }); }); try {