Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the conditions for firing 'No such file or directory' error on Linux move_to_trash #67158

Merged
merged 1 commit into from
Jun 19, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 22 additions & 13 deletions platform/linuxbsd/os_linuxbsd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -622,32 +622,41 @@ Error OS_LinuxBSD::move_to_trash(const String &p_path) {
args.push_back(path);
args.push_front("trash"); // The command is `gio trash <file_name>` so we need to add it to args.
Error result = execute("gio", args, nullptr, &err_code); // For GNOME based machines.
if (result == OK && !err_code) {
return OK;
} else if (err_code == 2) {
return ERR_FILE_NOT_FOUND;
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;
}
}

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 && !err_code) {
return OK;
} else if (err_code == 2) {
return ERR_FILE_NOT_FOUND;
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;
}
}

args.pop_front();
args.pop_back();
result = execute("gvfs-trash", args, nullptr, &err_code); // For older Linux machines.
if (result == OK && !err_code) {
return OK;
} else if (err_code == 2) {
return ERR_FILE_NOT_FOUND;
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 the commands `kioclient5`, `gio` or `gvfs-trash` don't exist on the system we do it manually.
// If the commands `kioclient5`, `gio` or `gvfs-trash` don't work on the system we do it manually.
String trash_path = "";
String mnt = get_mountpoint(path);

Expand Down