Directory Snapshot Diff
Asked at Meta· Onsite
Reported by the problem's creator, not verified
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.
Examples
Example 1
Input: before =
[["a.txt","h1"],["b.txt","h2"],["src/c.py","h3"]], after =[["a.txt","h1"],["b.txt","h9"],["src/d.py","h4"]]Output:
["+ src/d.py","- src/c.py","~ b.txt"]Explanation:
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.