diff --git a/navigator/components/NavDragDrop.js b/navigator/components/NavDragDrop.js index 6d0ee19..5872a3c 100644 --- a/navigator/components/NavDragDrop.js +++ b/navigator/components/NavDragDrop.js @@ -98,10 +98,30 @@ export class NavDragDrop { * @returns {FileUpload[]} */ async handle_conflicts(uploads) { + let test_paths = []; + for (let upload of uploads) + test_paths.push(upload.path); + let proc = cockpit.spawn( + ["/usr/share/cockpit/navigator/scripts/return-exists.py3", ... test_paths], + {error: "out", superuser: "try"} + ); + let exist_result; + proc.done((data) => { + exist_result = JSON.parse(data); + }); + proc.fail((e, data) => { + this.nav_window_ref.modal_prompt.alert(e, data); + }); + try { + await proc; + } catch { + return; + } + console.log(exist_result); let keepers = []; let requests = {}; for (let upload of uploads) { - if (!await check_if_exists(upload.path)) { + if (!exist_result[upload.path]) { keepers.push(upload.filename); continue; } @@ -163,8 +183,10 @@ export class NavDragDrop { } } this.drop_area.classList.remove("drag-enter"); - if (uploads.length === 0) + if (uploads.length === 0) { + this.nav_window_ref.stop_load(); break; + } uploads = await this.handle_conflicts(uploads); this.nav_window_ref.stop_load(); uploads.forEach((upload) => {upload.upload()}); diff --git a/navigator/scripts/return-exists.py3 b/navigator/scripts/return-exists.py3 new file mode 100755 index 0000000..38ce962 --- /dev/null +++ b/navigator/scripts/return-exists.py3 @@ -0,0 +1,44 @@ +#!/usr/bin/env python3 + +""" + Cockpit Navigator - A File System Browser for Cockpit. + Copyright (C) 2021 Josh Boudreau + + 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 . +""" + +""" +Synopsys: return-exists.py3 /full/path1 [/full/path2 ...] +replys with JSON formatted dictionary of path : boolean where true means the file exists +""" + +import os +import sys +import json + +def main(): + argv = sys.argv + argc = len(sys.argv) + if argc <= 1: + print("No arguments provided") + sys.exit(1) + response = {} + for i in range (1, argc): + path = argv[i] + response[path] = os.path.lexists(path) + print(json.dumps(response)) + sys.exit(0) + + +if __name__ == "__main__": + main() \ No newline at end of file