diff options
author | Rémi Verschelde <rverschelde@gmail.com> | 2023-07-11 11:30:21 +0200 |
---|---|---|
committer | Rémi Verschelde <rverschelde@gmail.com> | 2023-07-11 11:30:21 +0200 |
commit | 5dbbdaf27b9e7cad9441b5b8e3d67e0d513061c9 (patch) | |
tree | 81ea1ff05e0052820e6c7af8c8bb5af6e17a82fd /platform/linuxbsd/os_linuxbsd.cpp | |
parent | 659ccb3c5b814813b20709f5e6fb7f53fb79263d (diff) | |
parent | a6e75f397127c9a1a99aed7ae41ea22e34d91a08 (diff) | |
download | redot-engine-5dbbdaf27b9e7cad9441b5b8e3d67e0d513061c9.tar.gz |
Merge pull request #79284 from akien-mga/fix-linux-os-move_to_trash
Fix Linux `move_to_trash` wrongly reporting files as not found
Diffstat (limited to 'platform/linuxbsd/os_linuxbsd.cpp')
-rw-r--r-- | platform/linuxbsd/os_linuxbsd.cpp | 34 |
1 files changed, 11 insertions, 23 deletions
diff --git a/platform/linuxbsd/os_linuxbsd.cpp b/platform/linuxbsd/os_linuxbsd.cpp index 310778388b..14d02a73c8 100644 --- a/platform/linuxbsd/os_linuxbsd.cpp +++ b/platform/linuxbsd/os_linuxbsd.cpp @@ -954,45 +954,33 @@ static String get_mountpoint(const String &p_path) { } Error OS_LinuxBSD::move_to_trash(const String &p_path) { - String path = p_path.rstrip("/"); // Strip trailing slash when path points to a directory + // We try multiple methods, until we find one that works. + // So we only return on success until we exhausted possibilities. + String path = p_path.rstrip("/"); // Strip trailing slash when path points to a directory. int err_code; List<String> args; args.push_back(path); - args.push_front("trash"); // The command is `gio trash <file_name>` so we need to add it to args. + + args.push_front("trash"); // The command is `gio trash <file_name>` so we add it before the path. Error result = execute("gio", args, nullptr, &err_code); // For GNOME based machines. - if (result == OK) { // The `execute` function has done its job without errors. - if (!err_code) { // The shell command has been executed without errors. - return OK; - } else if (err_code == 1) { - ERR_PRINT("move_to_trash: No such file or directory as " + path + "."); - return ERR_FILE_NOT_FOUND; - } + if (result == OK && err_code == 0) { // Success. + return OK; } args.pop_front(); args.push_front("move"); args.push_back("trash:/"); // The command is `kioclient5 move <file_name> trash:/`. result = execute("kioclient5", args, nullptr, &err_code); // For KDE based machines. - if (result == OK) { // The `execute` function has done its job without errors. - if (!err_code) { // The shell command has been executed without errors. - return OK; - } else if (err_code == 1) { - ERR_PRINT("move_to_trash: No such file or directory as " + path + "."); - return ERR_FILE_NOT_FOUND; - } + if (result == OK && err_code == 0) { + return OK; } args.pop_front(); args.pop_back(); result = execute("gvfs-trash", args, nullptr, &err_code); // For older Linux machines. - if (result == OK) { // The `execute` function has done its job without errors. - if (!err_code) { // The shell command has been executed without errors. - return OK; - } else if (err_code == 1) { - ERR_PRINT("move_to_trash: No such file or directory as " + path + "."); - return ERR_FILE_NOT_FOUND; - } + if (result == OK && err_code == 0) { + return OK; } // If the commands `kioclient5`, `gio` or `gvfs-trash` don't work on the system we do it manually. |