Meta questions

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.

  1. 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.py appears only in after, so it is added. src/c.py appears only in before, so it is deleted. b.txt is in both with a different digest, so it is modified. a.txt is unchanged and is not listed.

Constraints

  • 0 <= len(before) <= 10^4
  • 0 <= len(after) <= 10^4
  • 1 <= len(path) <= 30
  • 1 <= len(digest) <= 30
  • All path values in before are distinct, and all path values in after are distinct
  • No digest of a path only in before equals a digest of a path only in after