[Sugar-devel] [PATCH sugar-datastore 3/3] don't destroy unchanged data store entries (SL#2668)

Sascha Silbe silbe at activitycentral.com
Sat Mar 5 15:26:36 EST 2011


Calling datastore.get() and passing the file name back into datastore.update()
for the same entry with transfer_ownership set to False destroyed the data
file.

This was because source and destination file are identical (hard links) and we
overwrote the destination file in AsyncCopy.start() without unlinking it
first.

Fix this by unlinking the destination file if it exists.

Reported-By: Daniel Drake <dsd at laptop.org>
Signed-off-by: Sascha Silbe <silbe at activitycentral.com>
---
 src/carquinyol/filestore.py |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/src/carquinyol/filestore.py b/src/carquinyol/filestore.py
index a614329..0b34b69 100644
--- a/src/carquinyol/filestore.py
+++ b/src/carquinyol/filestore.py
@@ -213,6 +213,9 @@ class AsyncCopy(object):
         self.completion(*args)
 
     def start(self):
+        if os.path.exists(self.dest):
+            os.unlink(self.dest)
+
         self.src_fp = os.open(self.src, os.O_RDONLY)
         self.dest_fp = os.open(self.dest, os.O_RDWR | os.O_TRUNC | os.O_CREAT,
                 0444)
-- 
1.7.2.3



More information about the Sugar-devel mailing list