mirror of
https://github.com/45Drives/cockpit-navigator.git
synced 2025-07-20 20:25:09 +02:00
don't upload file if it already exists
This commit is contained in:
parent
efd09793e8
commit
73e4a09751
@ -521,7 +521,6 @@ input:checked + .slider:before {
|
|||||||
.nav-notification-header {
|
.nav-notification-header {
|
||||||
position: relative;
|
position: relative;
|
||||||
z-index: 10;
|
z-index: 10;
|
||||||
font-size: 120%;
|
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -854,6 +854,14 @@ class FileUpload {
|
|||||||
this.chunk_index = 0;
|
this.chunk_index = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
check_if_exists() {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
var proc = cockpit.spawn(["/usr/share/cockpit/navigator/scripts/fail-if-exists.py", this.path], {superuser: "try"});
|
||||||
|
proc.done((data) => {resolve(false)});
|
||||||
|
proc.fail((e, data) => {resolve(true)});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
make_html_element() {
|
make_html_element() {
|
||||||
var notification = document.createElement("div");
|
var notification = document.createElement("div");
|
||||||
notification.classList.add("nav-notification");
|
notification.classList.add("nav-notification");
|
||||||
@ -892,14 +900,20 @@ class FileUpload {
|
|||||||
return chunks;
|
return chunks;
|
||||||
}
|
}
|
||||||
|
|
||||||
upload() {
|
async upload() {
|
||||||
|
if (await this.check_if_exists()) {
|
||||||
|
window.alert(this.filename + ": File exists.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
this.make_html_element();
|
this.make_html_element();
|
||||||
this.proc = cockpit.spawn(["/usr/share/cockpit/navigator/scripts/write-chunks.py", this.path], {err: "out", superuser: "try"});
|
this.proc = cockpit.spawn(["/usr/share/cockpit/navigator/scripts/write-chunks.py", this.path], {err: "out", superuser: "try"});
|
||||||
this.proc.fail((e, data) => {
|
this.proc.fail((e, data) => {
|
||||||
|
this.reader.onload = () => {}
|
||||||
|
this.done();
|
||||||
window.alert(data);
|
window.alert(data);
|
||||||
})
|
})
|
||||||
this.proc.done((data) => {
|
this.proc.done((data) => {
|
||||||
this.nav_window_ref.stop_load();
|
|
||||||
})
|
})
|
||||||
this.reader.onload = (function(uploader_ref) {
|
this.reader.onload = (function(uploader_ref) {
|
||||||
return async function(evt) {
|
return async function(evt) {
|
||||||
|
26
navigator/scripts/fail-if-exists.py
Executable file
26
navigator/scripts/fail-if-exists.py
Executable file
@ -0,0 +1,26 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
"""
|
||||||
|
Cockpit Navigator - A File System Browser for Cockpit.
|
||||||
|
Copyright (C) 2021 Josh Boudreau <jboudreau@45drives.com>
|
||||||
|
|
||||||
|
This file is part of Cockpit Navigator.
|
||||||
|
Cockpit Navigator is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
Cockpit Navigator is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with Cockpit Navigator. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
"""
|
||||||
|
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
|
if os.path.exists(sys.argv[1]):
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
sys.exit(0)
|
@ -34,7 +34,7 @@ def main():
|
|||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
path = sys.argv[1]
|
path = sys.argv[1]
|
||||||
try:
|
try:
|
||||||
file = open(path, "a+b")
|
file = open(path, "xb")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(e)
|
print(e)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user