From d60a8a71b708f2c1fab16c8ffa996e3db72f8268 Mon Sep 17 00:00:00 2001 From: Ruud Date: Sat, 8 Mar 2014 18:18:06 +0100 Subject: [PATCH 1/2] Check if file has moved, ignore copystat errors. close #2936 --- couchpotato/core/plugins/renamer/main.py | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/couchpotato/core/plugins/renamer/main.py b/couchpotato/core/plugins/renamer/main.py index fe698d2..436107f 100755 --- a/couchpotato/core/plugins/renamer/main.py +++ b/couchpotato/core/plugins/renamer/main.py @@ -736,8 +736,15 @@ Remove it if you want it to be renamed (again, or at least let it try again) def moveFile(self, old, dest, forcemove = False): dest = ss(dest) try: - if forcemove: - shutil.move(old, dest) + if forcemove or self.conf('file_action') not in ['copy', 'link']: + try: + shutil.move(old, dest) + except: + if os.path.exists(dest): + log.error('Successfully moved file "%s", but something went wrong: %s', (dest, traceback.format_exc())) + os.unlink(old) + else: + raise elif self.conf('file_action') == 'copy': shutil.copy(old, dest) elif self.conf('file_action') == 'link': @@ -755,8 +762,6 @@ Remove it if you want it to be renamed (again, or at least let it try again) os.rename(old + '.link', old) except: log.error('Couldn\'t symlink file "%s" to "%s". Copied instead. Error: %s. ', (old, dest, traceback.format_exc())) - else: - shutil.move(old, dest) try: os.chmod(dest, Env.getPermission('file')) @@ -764,15 +769,6 @@ Remove it if you want it to be renamed (again, or at least let it try again) os.popen('icacls "' + dest + '"* /reset /T') except: log.error('Failed setting permissions for file: %s, %s', (dest, traceback.format_exc(1))) - - except OSError as err: - # Copying from a filesystem with octal permission to an NTFS file system causes a permission error. In this case ignore it. - if not hasattr(os, 'chmod') or err.errno != errno.EPERM: - raise - else: - if os.path.exists(dest): - os.unlink(old) - except: log.error('Couldn\'t move file "%s" to "%s": %s', (old, dest, traceback.format_exc())) raise From 75f22f44a1ad1ea47e44091a5000b2df9cef05e7 Mon Sep 17 00:00:00 2001 From: Ruud Date: Sat, 8 Mar 2014 18:55:38 +0100 Subject: [PATCH 2/2] Reference before assigned --- couchpotato/core/plugins/base.py | 1 + 1 file changed, 1 insertion(+) diff --git a/couchpotato/core/plugins/base.py b/couchpotato/core/plugins/base.py index 81ffcec..d7487a1 100644 --- a/couchpotato/core/plugins/base.py +++ b/couchpotato/core/plugins/base.py @@ -309,6 +309,7 @@ class Plugin(object): def checkFilesChanged(self, files, unchanged_for = 60): now = time.time() + file_too_new = False for cur_file in files: