]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/blobdiff - src/allmydata/frontends/magic_folder.py
Don't download the deletion marker file unnecessarily.
[tahoe-lafs/tahoe-lafs.git] / src / allmydata / frontends / magic_folder.py
index 8d34bddd21b689c8e0eefeaa922f35b181fd1f0b..f9e0433bcc0b6990cc656f4328113d34d45628b6 100644 (file)
@@ -1,7 +1,6 @@
 
 import sys, os
 import os.path
-import shutil
 from collections import deque
 import time
 
@@ -481,6 +480,15 @@ class WriteFileMixin(object):
         fileutil.rename_no_overwrite(replacement_path_u, conflict_path_u)
         return conflict_path_u
 
+    def _rename_deleted_file(self, abspath_u):
+        self._log('renaming deleted file to backup: %s' % (abspath_u,))
+        try:
+            fileutil.rename_no_overwrite(abspath_u, abspath_u + u'.backup')
+        except IOError:
+            # XXX is this the correct error?
+            self._log("Already gone: '%s'" % (abspath_u,))
+        return abspath_u
+
 
 class Downloader(QueueMixin, WriteFileMixin):
     REMOTE_SCAN_INTERVAL = 3  # facilitates tests
@@ -688,20 +696,26 @@ class Downloader(QueueMixin, WriteFileMixin):
                 local_last_downloaded_uri = self._db.get_last_downloaded_uri(relpath_u)
                 print "metadata %r" % (metadata,)
                 print "<<<<--- if %r != %r" % (dmd_last_downloaded_uri, local_last_downloaded_uri)
-                if dmd_last_downloaded_uri is not None and dmd_last_downloaded_uri != local_last_downloaded_uri:
-                    is_conflict = True
+                if dmd_last_downloaded_uri is not None and local_last_downloaded_uri is not None:
+                    if dmd_last_downloaded_uri != local_last_downloaded_uri:
+                        is_conflict = True
+                        self._count('objects_conflicted')
+
                 #dmd_last_uploaded_uri = metadata.get('last_uploaded_uri', None)
                 #local_last_uploaded_uri = ...
 
             if relpath_u.endswith(u"/"):
-                self._log("mkdir(%r)" % (abspath_u,))
-                d.addCallback(lambda ign: fileutil.make_dirs(abspath_u))
-                d.addCallback(lambda ign: abspath_u)
+                if metadata.get('deleted', False):
+                    self._log("rmdir(%r) ignored" % (abspath_u,))
+                else:
+                    self._log("mkdir(%r)" % (abspath_u,))
+                    d.addCallback(lambda ign: fileutil.make_dirs(abspath_u))
+                    d.addCallback(lambda ign: abspath_u)
             else:
-                d.addCallback(lambda ign: file_node.download_best_version())
                 if metadata.get('deleted', False):
-                    d.addCallback(lambda result: self._unlink_deleted_file(abspath_u, result))
+                    d.addCallback(lambda ign: self._rename_deleted_file(abspath_u))
                 else:
+                    d.addCallback(lambda ign: file_node.download_best_version())
                     d.addCallback(lambda contents: self._write_downloaded_file(abspath_u, contents,
                                                                                is_conflict=is_conflict))
 
@@ -716,11 +730,3 @@ class Downloader(QueueMixin, WriteFileMixin):
             return None
         d.addErrback(trap_conflicts)
         return d
-
-    def _unlink_deleted_file(self, abspath_u, result):
-        try:
-            self._log('unlinking: %s' % (abspath_u,))
-            shutil.move(abspath_u, abspath_u + '.backup')
-        except IOError:
-            self._log("Already gone: '%s'" % (abspath_u,))
-        return abspath_u