mirror of
https://github.com/45Drives/cockpit-navigator.git
synced 2025-07-30 00:55:30 +02:00
create script to write to file without changing ownership
This commit is contained in:
parent
45b72df38b
commit
f269505719
@ -20,7 +20,7 @@
|
||||
import { NavEntry } from "./NavEntry.js";
|
||||
import { NavDownloader } from "./NavDownloader.js";
|
||||
import { NavWindow } from "./NavWindow.js";
|
||||
import { property_entry_html } from "../functions.js";
|
||||
import { property_entry_html, simple_spawn } from "../functions.js";
|
||||
|
||||
export class NavFile extends NavEntry {
|
||||
/**
|
||||
@ -128,12 +128,9 @@ export class NavFile extends NavEntry {
|
||||
async write_to_file() {
|
||||
var new_contents = document.getElementById("nav-edit-contents-textarea").value;
|
||||
try {
|
||||
if (new_contents.length)
|
||||
await cockpit.file(this.path_str(), {superuser: "try"}).replace(new_contents);
|
||||
else
|
||||
await cockpit.script("echo -n > $1", [this.path_str()], {superuser: "try"});
|
||||
await simple_spawn(["/usr/share/cockpit/navigator/scripts/write-to-file.py3", this.path_str()], new_contents);
|
||||
} catch (e) {
|
||||
this.nav_window_ref.modal_prompt.alert(e.message);
|
||||
this.nav_window_ref.modal_prompt.alert(e);
|
||||
}
|
||||
this.nav_window_ref.refresh();
|
||||
this.hide_edit_file_contents();
|
||||
@ -229,9 +226,9 @@ export class NavFileLink extends NavFile{
|
||||
var target_path = this.get_link_target_path();
|
||||
var new_contents = document.getElementById("nav-edit-contents-textarea").value;
|
||||
try {
|
||||
await cockpit.file(target_path, {superuser: "try"}).replace(new_contents);
|
||||
await simple_spawn(["/usr/share/cockpit/navigator/scripts/write-to-file.py3", target_path], new_contents);
|
||||
} catch (e) {
|
||||
this.nav_window_ref.modal_prompt.alert(e.message);
|
||||
this.nav_window_ref.modal_prompt.alert(e);
|
||||
}
|
||||
this.nav_window_ref.refresh();
|
||||
this.hide_edit_file_contents();
|
||||
|
Loading…
x
Reference in New Issue
Block a user