]> git.mxchange.org Git - quix0rs-apt-p2p.git/blobdiff - apt_dht/db.py
Use the new DB in the main code.
[quix0rs-apt-p2p.git] / apt_dht / db.py
index 7f8c4493a2071643f4243fbbb1023bf51aeadafb..9725aa88f10c36e0bd137de1cb5051850d7cde91 100644 (file)
@@ -69,7 +69,11 @@ class DB:
         return res
         
     def storeFile(self, path, hash, directory):
-        """Store or update a file in the database."""
+        """Store or update a file in the database.
+        
+        @return: the urlpath to access the file, and whether a
+            new url top-level directory was needed
+        """
         path = os.path.abspath(path)
         directory = os.path.abspath(directory)
         assert path.startswith(directory)
@@ -81,13 +85,14 @@ class DB:
             c.execute("UPDATE files SET hash = ?, size = ?, mtime = ?, refreshed = ?", 
                       (khash(hash), stat.st_size, stat.st_mtime, datetime.now()))
             newdir = False
+            urldir = row['urldir']
         else:
             urldir, newdir = self.findDirectory(directory)
             c.execute("INSERT OR REPLACE INTO files VALUES(?, ?, ?, ?, ?, ?, ?)",
                       (path, khash(hash), urldir, len(directory), stat.st_size, stat.st_mtime, datetime.now()))
         self.conn.commit()
         c.close()
-        return newdir
+        return '/~' + str(urldir) + path[len(directory):], newdir
         
     def getFile(self, path):
         """Get a file from the database.