From 46163315ca8f90f7ce35ba7949cc6503fc33e0a9 Mon Sep 17 00:00:00 2001 From: Robert Rothenberg Date: Wed, 22 Jun 2011 07:11:51 +0100 Subject: [PATCH] Fixed bug with trashing directories --- trash | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/trash b/trash index 202d08f..c2afcc1 100755 --- a/trash +++ b/trash @@ -15,7 +15,7 @@ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. -version="0.3.9 \$Id: trash 2011/06/18 13:24:35 BST rr@newfie $" +version="0.3.10 \$Id: trash 2011/06/22 07:10:41 BST rr@newfie $" progname=`basename $0` @@ -233,7 +233,10 @@ function trash_file { ext="" fi - deletedfile=$(mktemp --tmpdir="${trashdir}/files" --suffix="${ext}" "${trashname}_XXXXXXXX" ) + # Use --dry-run option because we cannot mv a directory into a file. + # This is technically "unsafe" but we use --no-clobber option in mv. + + deletedfile=$(mktemp --dry-run --tmpdir="${trashdir}/files" --suffix="${ext}" "${trashname}_XXXXXXXX" ) deletedbase=$( basename "${deletedfile}" ) deletedinfo="$trashdir/info/${deletedbase}.trashinfo" @@ -245,7 +248,7 @@ Path=$canon DeletionDate=`date +"%FT%H:%M:%S"` END - mv $mv_opts "$filename" "$deletedfile" + mv $mv_opts --no-clobber "${filename}" "${deletedfile}" } for f in "$@"