Fixed possible unique constraint exception

When renaming a file its hash can't be used in the WHERE
condition in the UPDATE statement since there _can_ be more
than one file having the same hash and not all of them are
renamed just the one not existing anymore. So we need to use
the old path (now non-existent) to specify the record to
update.

To make the code more clear I also added setting the hash
explicitly in the UPDATE statement.
This commit is contained in:
Jean-Louis Fuchs 2014-09-10 15:48:33 +02:00
parent e5f737b09d
commit 4d1ca47777

View File

@ -169,8 +169,14 @@ def run(verbosity=1, test=False, follow_links=False, commit_interval=300,
renamed_paths.append((stored_path, p_uni))
missing_paths.discard(stored_path)
cur.execute('UPDATE bitrot SET mtime=?, path=?, '
'timestamp=? WHERE hash=?',
(new_mtime, p_uni, update_ts, new_sha1))
'timestamp=?, hash=? WHERE path=?',
(
new_mtime,
p_uni,
update_ts,
new_sha1,
stored_path
))
last_commit_time = tcommit(last_commit_time)
break