Make handle_unknown_path
more readable
This commit is contained in:
parent
8ee84344e8
commit
45ab4501ee
@ -382,23 +382,29 @@ class Bitrot(object):
|
|||||||
"""Either add a new entry to the database or update the existing entry
|
"""Either add a new entry to the database or update the existing entry
|
||||||
on rename.
|
on rename.
|
||||||
|
|
||||||
Returns `new_path` if the entry was indeed new or the `stored_path` (e.g.
|
`cur` is the database cursor. `new_path` is the new Unicode path.
|
||||||
outdated path) if there was a rename.
|
`paths_uni` are Unicode paths seen on disk during this run of Bitrot.
|
||||||
|
`hashes` is a dictionary selected from the database, keys are hashes, values
|
||||||
|
are sets of Unicode paths that are stored in the DB under the given hash.
|
||||||
|
|
||||||
|
Returns `new_path` if the entry was indeed new or the `old_path` (e.g.
|
||||||
|
outdated path stored in the database for this hash) if there was a rename.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
try: # if the path isn't in the database
|
for old_path in hashes.get(new_sha1, ()):
|
||||||
found = [path for path in hashes[new_sha1] if path not in paths_uni]
|
if old_path not in paths_uni:
|
||||||
renamed = found.pop()
|
# File of the same hash used to exist but no longer does.
|
||||||
# update the path in the database
|
# Let's treat `new_path` as a renamed version of that `old_path`.
|
||||||
cur.execute(
|
cur.execute(
|
||||||
'UPDATE bitrot SET mtime=?, path=?, timestamp=? WHERE path=?',
|
'UPDATE bitrot SET mtime=?, path=?, timestamp=? WHERE path=?',
|
||||||
(new_mtime, new_path, ts(), renamed),
|
(new_mtime, new_path, ts(), old_path),
|
||||||
)
|
)
|
||||||
|
return old_path
|
||||||
|
|
||||||
return renamed
|
else:
|
||||||
|
# Either we haven't found `new_sha1` at all in the database, or all
|
||||||
# From hashes[new_sha1] or found.pop()
|
# currently stored paths for this hash still point to existing files.
|
||||||
except (KeyError,IndexError):
|
# Let's insert a new entry for what appears to be a new file.
|
||||||
cur.execute(
|
cur.execute(
|
||||||
'INSERT INTO bitrot VALUES (?, ?, ?, ?)',
|
'INSERT INTO bitrot VALUES (?, ?, ?, ?)',
|
||||||
(new_path, new_mtime, new_sha1, ts()),
|
(new_path, new_mtime, new_sha1, ts()),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user