Add is_new_file_time db helper function
authorDavid Stainton <dstainton415@gmail.com>
Sat, 12 Sep 2015 18:09:10 +0000 (20:09 +0200)
committerDaira Hopwood <daira@jacaranda.org>
Thu, 1 Oct 2015 00:19:48 +0000 (01:19 +0100)
this is for comparing mtimes

src/allmydata/backupdb.py

index 3f43eee0ca54cec8046eb485760b0090b44320f4..9e8b52739aa1cc990c55389cabcf853cd53aa563 100644 (file)
@@ -415,3 +415,28 @@ class MagicFolderDB(BackupDB):
                                 " WHERE path=?",
                                 (size, mtime, ctime, fileid, version, path))
         self.connection.commit()
+
+    def is_new_file_time(self, path, relpath_u):
+        """recent_file_time returns true if the file is recent...
+        meaning it's current mtime matched the mtime that was previously stored in the db.
+        """
+        print "check_file_time %s %s" % (path, relpath_u)
+        path = abspath_expanduser_unicode(path)
+        s = os.stat(path)
+        size = s[stat.ST_SIZE]
+        ctime = s[stat.ST_CTIME]
+        mtime = s[stat.ST_MTIME]
+        now = time.time()
+        c = self.cursor
+        c.execute("SELECT size,mtime,ctime,fileid"
+                  " FROM local_files"
+                  " WHERE path=?",
+                  (relpath_u,))
+        row = self.cursor.fetchone()
+        if not row:
+            return True
+        (last_size,last_mtime,last_ctime,last_fileid) = row
+        if int(mtime) == int(last_mtime):
+            return False
+        else:
+            return True