Author: poeml Date: Thu May 6 21:44:59 2010 New Revision: 8056 URL: http://svn.mirrorbrain.org/viewvc/mirrorbrain?rev=8056&view=rev Log: mb makehashes: - hashes of obsolete directory (hierarchies) are now cleaned up. It's a kludge, because it relies on local directories in the old file-based hash store. Modified: trunk/mb/mb.py trunk/mb/mb/files.py Modified: trunk/mb/mb.py URL: http://svn.mirrorbrain.org/viewvc/mirrorbrain/trunk/mb/mb.py?rev=8056&r1=8055&r2=8056&view=diff ============================================================================== --- trunk/mb/mb.py (original) +++ trunk/mb/mb.py Thu May 6 21:44:59 2010 _at_@ -1107,6 +1107,11 @@ else: sys.exit('Recursive removing failed for %r: %s\n' \ % (i_path, os.strerror(e.errno))) + + relpath = os.path.join(dst_dir_db, i) + print 'Recursively removing hashes in database: %s/*' % relpath + mb.files.hashes_dir_delete(self.conn, relpath) + unlinked_dirs += 1 else: _at_@ -1127,11 +1132,12 @@ print 'Obsolete hash in db: %r (id %s)' % (relpath, dbid) ids_to_delete.append(dbid) else: - print 'hm:', relpath + pass # not in the hash table + if len(ids_to_delete): print 'Deleting %s obsolete hashes from hash table' % len(ids_to_delete) if not opts.dry_run: - mb.files.hash_list_delete(self.conn, ids_to_delete) + mb.files.hashes_list_delete(self.conn, ids_to_delete) if opts.verbose: print 'unlocking', lockfile Modified: trunk/mb/mb/files.py URL: http://svn.mirrorbrain.org/viewvc/mirrorbrain/trunk/mb/mb/files.py?rev=8056&r1=8055&r2=8056&view=diff ============================================================================== --- trunk/mb/mb/files.py (original) +++ trunk/mb/mb/files.py Thu May 6 21:44:59 2010 _at_@ -160,14 +160,39 @@ result = conn.Server._connection.queryAll(query) return result -def hash_list_delete(conn, idlist): - """deletes all rows from the hash table with ids contained in the id list + +def hashes_list_delete(conn, idlist): + """Deletes all rows from the hash table with ids contained in the id list which is passed as argument""" if not len(idlist): return - query = """BEGIN; DELETE FROM hash - WHERE file_id IN ( %s ); COMMIT""" % ', '.join([ str(i) for i in idlist]) - print query + query = """BEGIN; + DELETE FROM hash + WHERE file_id IN ( %s ); + COMMIT""" % ', '.join([ str(i) for i in idlist]) conn.Filearr._connection.query(query) + + +#def hashdir_add(conn, d): +# """Adds a directory to the hashdir table""" +# +# query = """INSERT INTO hashdir (path) +# VALUES ('%s')""" % d +# try: +# conn.Filearr._connection.query(query) +# except: +# pass + +def hashes_dir_delete(conn, base): + """Deletes all rows from the hash table which correspond to paths in the + filearr table starting with 'base'. + This means we recursively delete hashes below a given directory.""" + + query = """DELETE FROM hash + WHERE file_id IN ( + SELECT filearr.id FROM filearr + WHERE path LIKE '%s/%%' + )""" % base + conn.Filearr._connection.query(query) _______________________________________________ mirrorbrain-commits mailing list Archive: http://mirrorbrain.org/archive/mirrorbrain-commits/ Note: To remove yourself from this list, send a mail with the content unsubscribe to the address mirrorbrain-commits-request_at_mirrorbrain.orgReceived on Thu May 06 2010 - 19:45:01 GMT
This archive was generated by hypermail 2.3.0 : Mon Feb 20 2012 - 23:47:04 GMT