]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
Refactor is_new_file.
authorDaira Hopwood <daira@jacaranda.org>
Wed, 4 Nov 2015 14:38:53 +0000 (14:38 +0000)
committerDaira Hopwood <daira@jacaranda.org>
Mon, 28 Dec 2015 15:32:37 +0000 (15:32 +0000)
Signed-off-by: Daira Hopwood <daira@jacaranda.org>
src/allmydata/frontends/magic_folder.py
src/allmydata/magicfolderdb.py
src/allmydata/test/test_magic_folder.py

index 8fa3143c341f79dbf6f8a517ab4e9c968f99a988..55eb47011740356fef7f8930380eedf930eb5a91 100644 (file)
@@ -42,6 +42,17 @@ def get_inotify_module():
         raise
 
 
+def is_new_file(pathinfo, db_entry):
+    if db_entry is None:
+        return True
+
+    if not pathinfo.exists and db_entry.size is None:
+        return False
+
+    return ((pathinfo.size, pathinfo.ctime, pathinfo.mtime) !=
+            (db_entry.size, db_entry.ctime, db_entry.mtime))
+
+
 class MagicFolder(service.MultiService):
     name = 'magic-folder'
 
@@ -336,7 +347,7 @@ class Uploader(QueueMixin):
 
                 last_downloaded_timestamp = now  # is this correct?
 
-                if self._db.is_new_file(pathinfo, relpath_u):
+                if is_new_file(pathinfo, db_entry):
                     new_version = db_entry.version + 1
                 else:
                     self._log("Not uploading %r" % (relpath_u,))
@@ -389,7 +400,7 @@ class Uploader(QueueMixin):
 
                 if db_entry is None:
                     new_version = 0
-                elif self._db.is_new_file(pathinfo, relpath_u):
+                elif is_new_file(pathinfo, db_entry):
                     new_version = db_entry.version + 1
                 else:
                     self._log("Not uploading %r" % (relpath_u,))
index 3f168328945e462998205cdc3934b98b41c2dbfb..0db1857c26bda82dc2859cab0bbd5889931879c7 100644 (file)
@@ -96,20 +96,3 @@ class MagicFolderDB(object):
                                 (pathinfo.size, pathinfo.mtime, pathinfo.ctime, version, last_uploaded_uri, last_downloaded_uri, last_downloaded_timestamp, relpath_u))
         self.connection.commit()
         print "committed"
-
-    def is_new_file(self, pathinfo, relpath_u):
-        """
-        Returns true if the file's current pathinfo (size, mtime, and ctime) has
-        changed from the pathinfo previously stored in the db.
-        """
-        c = self.cursor
-        c.execute("SELECT size, mtime, ctime"
-                  " FROM local_files"
-                  " WHERE path=?",
-                  (relpath_u,))
-        row = self.cursor.fetchone()
-        if not row:
-            return True
-        if not pathinfo.exists and row[0] is None:
-            return False
-        return (pathinfo.size, pathinfo.mtime, pathinfo.ctime) != row
index c724e080cc55c357a001669a369708ab20bd6634..ab6b1ef0ec6dc6c5bf656bcf3d112cce87853d6a 100644 (file)
@@ -80,18 +80,19 @@ class MagicFolderTestMixin(MagicFolderCLITestMixin, ShouldFailMixin, ReallyEqual
         row = c.fetchone()
         self.failUnlessEqual(row, (pathinfo.size, pathinfo.mtime, pathinfo.ctime))
 
-        # Second test uses db.is_new_file instead of SQL query directly
+        # Second test uses magic_folder.is_new_file instead of SQL query directly
         # to confirm the previous upload entry in the db.
         relpath2 = u"myFile2"
         path2 = os.path.join(self.basedir, relpath2)
         fileutil.write(path2, "meow\n")
         pathinfo = fileutil.get_pathinfo(path2)
         db.did_upload_version(relpath2, 0, 'URI:LIT:2', 'URI:LIT:1', 0, pathinfo)
-        self.failUnlessFalse(db.is_new_file(pathinfo, relpath2))
+        db_entry = db.get_db_entry(relpath2)
+        self.failUnlessFalse(magic_folder.is_new_file(pathinfo, db_entry))
 
         different_pathinfo = fileutil.PathInfo(isdir=False, isfile=True, islink=False,
                                                exists=True, size=0, mtime=pathinfo.mtime, ctime=pathinfo.ctime)
-        self.failUnlessTrue(db.is_new_file(different_pathinfo, relpath2))
+        self.failUnlessTrue(magic_folder.is_new_file(different_pathinfo, db_entry))
 
     def test_magicfolder_start_service(self):
         self.set_up_grid()