From fb975d41c6f80a242e2b0dc25a7fe4ee8a6f54d4 Mon Sep 17 00:00:00 2001 From: Tito Date: Tue, 7 Jan 2014 05:50:03 -0200 Subject: [PATCH] Apply patch for ubuntu encrypted folder bug. --- send2trash/plat_other.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/send2trash/plat_other.py b/send2trash/plat_other.py index 3e2e7b119..78cce01f7 100644 --- a/send2trash/plat_other.py +++ b/send2trash/plat_other.py @@ -1,7 +1,7 @@ # Copyright 2010 Hardcoded Software (http://www.hardcoded.net) -# This software is licensed under the "BSD" License as described in the "LICENSE" file, -# which should be included with this package. The terms are also available at +# This software is licensed under the "BSD" License as described in the "LICENSE" file, +# which should be included with this package. The terms are also available at # http://www.hardcoded.net/licenses/bsd_license # This is a reimplementation of plat_other.py with reference to the @@ -19,6 +19,7 @@ import os.path as op from datetime import datetime import stat +import shutil from urllib.parse import quote FILES_DIR = 'files' @@ -70,11 +71,13 @@ def trash_move(src, dst, topdir=None): while op.exists(op.join(filespath, destname)) or op.exists(op.join(infopath, destname + INFO_SUFFIX)): counter += 1 destname = '%s %s%s' % (base_name, counter, ext) - + check_create(filespath) check_create(infopath) - - os.rename(src, op.join(filespath, destname)) + try: + os.rename(src, op.join(filespath, destname)) + except: + shutil.move(src, op.join(filespath, destname)) f = open(op.join(infopath, destname + INFO_SUFFIX), 'w') f.write(info_for(src, topdir)) f.close() @@ -93,7 +96,7 @@ def find_ext_volume_global_trash(volume_root): trash_dir = op.join(volume_root, TOPDIR_TRASH) if not op.exists(trash_dir): return None - + mode = os.lstat(trash_dir).st_mode # vol/.Trash must be a directory, cannot be a symlink, and must have the # sticky bit set. @@ -137,12 +140,12 @@ def send2trash(path): # if the file to be trashed is on the same device as HOMETRASH we # want to move it there. path_dev = get_dev(path) - + # If XDG_DATA_HOME or HOMETRASH do not yet exist we need to stat the # home directory, and these paths will be created further on if needed. trash_dev = get_dev(op.expanduser('~')) - if path_dev == trash_dev: + if path_dev == trash_dev or ( os.path.exists(XDG_DATA_HOME) and os.path.exists(HOMETRASH) ): topdir = XDG_DATA_HOME dest_trash = HOMETRASH else: