Master

A rename tool as a plan that is checked before it runs

A rename changes names, and names are what other things point at. The plan is the reason a change is a decision about a map rather than a walk.

What you will see

refuse prints both pairs. Two pairs is the whole answer.

About 1 min of reading

Try It

Refuse a collision

1

Write the map

printf 'a.txt b.txt\nc.txt b.txt\n' > /tmp/m.txt; wc -l < /tmp/m.txt

Before you run it, say out loud what it will print. Then open the answer.

What it prints
2. Two pairs is the map, which is a file.
2

Find a collision

cut -f2 -d' ' /tmp/m.txt | sort | uniq -d

Before you run it, say out loud what it will print. Then open the answer.

What it prints
b.txt. One name twice is the collision.
3

Refuse before the write

printf 'collisions 1\n' | awk '{print ($2>0) ? "refuse prints both pairs" : "apply"}'

Before you run it, say out loud what it will print. Then open the answer.

What it prints
refuse prints both pairs. Two pairs is the whole answer.

Data Flow

A rename to a plan and an apply
1 The pairs are written as a map
↓
2 The map is checked for a collision
↓
3 A collision refuses with both pairs
↓
4 The apply reads the map and writes
Why this works
Why the plan is written before the apply

Before is the order that makes a refusal cheap. A refusal after a write is a write that already happened.

The one thing the plan never contains

A delete. A delete in a rename is a change that no pair names, and every change must be named.

Examples

The plan is a map

An old name to a new name. A map is a file, and a file is what a reader checks line by line.

A collision is refused before the write

Two names to one name. The refusal prints both pairs, and two pairs is the whole answer.

The apply reads the plan

The apply does not decide. One decision is what makes the apply and the plan the same change.

Words this lesson uses

Each one is defined here on this site. Open the entry for the full definition and the other words it points at.

← Quiet and loud as one dial with a default
Previous Lesson
Quiet and loud as one dial with a default
Next Lesson
A batch over many files as a queue with a point
A batch over many files as a queue with a point →