From a01e574a8fec65caa6d39a1c3c0ccce6e23e9499 Mon Sep 17 00:00:00 2001 From: j Date: Sun, 13 Jan 2019 00:28:01 +0530 Subject: [PATCH] unlink target if move failed --- oml/item/models.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/oml/item/models.py b/oml/item/models.py index f894cfc..27e4191 100644 --- a/oml/item/models.py +++ b/oml/item/models.py @@ -797,6 +797,8 @@ class File(db.Model): shutil.move(current_path, path) except: logger.debug('failed to move %s to %s', current_path, path, exc_info=True) + if os.path.exists(path) and os.path.exists(current_path): + os.unlink(path) return self.path = new_path self.save()