From c52966ffa44b59d6c25d699053a607ed55458ab2 Mon Sep 17 00:00:00 2001 From: John Schember Date: Sat, 16 May 2009 08:25:42 -0400 Subject: [PATCH] Prevent truncating of files when using save file to disk to save a file to itself. --- src/calibre/gui2/device.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/calibre/gui2/device.py b/src/calibre/gui2/device.py index 005e278552..b176c25062 100644 --- a/src/calibre/gui2/device.py +++ b/src/calibre/gui2/device.py @@ -220,9 +220,11 @@ class DeviceManager(Thread): '''Copy books from device to disk''' for path in paths: name = path.rpartition('/')[2] - f = open(os.path.join(target, name), 'wb') - self.device.get_file(path, f) - f.close() + dest = os.path.join(target, name) + if os.path.abspath(dest) != os.path.abspath(path): + f = open(dest, 'wb') + self.device.get_file(path, f) + f.close() def save_books(self, done, paths, target): return self.create_job(self._save_books, done, args=[paths, target],