From 4d1ca47777468cc89f23b7cf28ffc3c7adb62642 Mon Sep 17 00:00:00 2001 From: Jean-Louis Fuchs Date: Wed, 10 Sep 2014 15:48:33 +0200 Subject: [PATCH] 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. --- src/bitrot.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/bitrot.py b/src/bitrot.py index bfc5811..1041b72 100644 --- a/src/bitrot.py +++ b/src/bitrot.py @@ -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