From ea2247511fb4dc84f42961781bba8f562a1094dd Mon Sep 17 00:00:00 2001 From: Steven vanZyl Date: Mon, 6 Jun 2022 00:09:37 -0400 Subject: [PATCH] Improved error message for irregular file types When trashing an irregular file like a fifo pipe, it cannot reliably be moved across filesystems. Even cp seems to have issues with this. Closes #12 --- source/trash/opers.d | 4 +++- source/trash/util.d | 6 ++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/source/trash/opers.d b/source/trash/opers.d index a29b4c2..aae2237 100644 --- a/source/trash/opers.d +++ b/source/trash/opers.d @@ -62,7 +62,9 @@ int trashOrRm(in string path) { log("trashing: %s", tfile.orig_path); // Move the file to the trash files dir - path.renameOrCopy(tfile.file_path); + bool res = path.renameOrCopy(tfile.file_path); + if (!res) + return 1; // Write the .trashinfo file tfile.info_path.append(tfile.infoString); diff --git a/source/trash/util.d b/source/trash/util.d index 0c31dc5..863515a 100644 --- a/source/trash/util.d +++ b/source/trash/util.d @@ -95,7 +95,7 @@ void createMissingFolders() { needed. Symlinks are NOT followed recursively */ -void renameOrCopy(in string src, in string tgt) { +bool renameOrCopy(in string src, in string tgt) { try { // Bit of an odd workaround to prevent recursive trashing if (src.endsWith("/") && src.chop().isSymlink) { @@ -120,9 +120,11 @@ void renameOrCopy(in string src, in string tgt) { } src.rmdir(); } else { - err("path was neither file or directory"); + err("'%s' is not a regular file and cannot be trashed across devices", src); + return false; } } + return true; } /**