Directory Snapshot Diff
MetaOnsiteMedium
A tool compares two snapshots of a directory. A snapshot is a list of [path, digest] pairs, one per file, where digest is a string that changes when the file's contents change. Paths are unique within a snapshot and the list is in no particular order.
Implement diff_snapshots(before, after), which returns the report lines for turning before into after. Each test gives two snapshots and checks the exact list of lines.
Part 1: Added, deleted, modified
Report each added path as + path (only in after), each deleted path as - path (only in before) and each modified path as ~ path (in both snapshots with different digests).
List all + lines first, then all - lines, then all ~ lines. Within each group, sort by path. Unchanged files are not listed.
- Example 1
- after
[["a.txt","h1"],["b.txt","h9"],["src/d.py","h4"]]- before
[["a.txt","h1"],["b.txt","h2"],["src/c.py","h3"]]- Output
["+ src/d.py","- src/c.py","~ b.txt"]
Why:
src/d.pyappears only inafter, so it is added.src/c.pyappears only inbefore, so it is deleted.b.txtis in both with a different digest, so it is modified.a.txtis unchanged and is not listed.
Constraints
0 <= len(before) <= 10^40 <= len(after) <= 10^41 <= len(path) <= 301 <= len(digest) <= 30- All
pathvalues inbeforeare distinct, and allpathvalues inafterare distinct - No
digestof a path only inbeforeequals adigestof a path only inafter