]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
delete files based on metadata
authormeejah <meejah@meejah.ca>
Thu, 8 Oct 2015 19:00:47 +0000 (13:00 -0600)
committermeejah <meejah@meejah.ca>
Mon, 26 Oct 2015 14:07:23 +0000 (08:07 -0600)
src/allmydata/frontends/magic_folder.py

index 5c4d6c31024a45d8fa58f9d357afb0593cfd6066..b204227a8cf1e1aa53680e3a5a77803910d08347 100644 (file)
@@ -646,7 +646,10 @@ class Downloader(QueueMixin, WriteFileMixin):
             d.addCallback(lambda ign: 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=False))
+            if metadata.get('deleted', False):
+                d.addCallback(lambda result: self._unlink_deleted_file(abspath_u, result))
+            else:
+                d.addCallback(lambda result: self._write_downloaded_file(abspath_u, result, is_conflict=False))
 
         def do_update_db(written_abspath_u):
             filecap = file_node.get_uri()
@@ -654,7 +657,7 @@ class Downloader(QueueMixin, WriteFileMixin):
             last_downloaded_uri = filecap
             last_downloaded_timestamp = now
             written_pathinfo = get_pathinfo(written_abspath_u)
-            if not written_pathinfo.exists:
+            if not written_pathinfo.exists and not metadata.get('deleted', False):
                 raise Exception("downloaded object %s disappeared" % quote_local_unicode_path(written_abspath_u))
 
             self._db.did_upload_version(relpath_u, metadata['version'], last_uploaded_uri,
@@ -670,3 +673,10 @@ class Downloader(QueueMixin, WriteFileMixin):
             return res
         d.addBoth(remove_from_pending)
         return d
+
+    def _unlink_deleted_file(self, abspath_u, result):
+        try:
+            os.unlink(abspath_u)
+        except OSError:
+            self._log("Already gone: '%s'" % (abspath_u,))
+        return abspath_u