1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
//! What:
//! Reading `Cargo.lock` before a `cargo clean` and putting it back as it was afterwards.
//! Why:
//! A clean may rewrite the lock file, and a new worktree must stay as checked out; the two steps need nothing from
//! the repair itself, so they live in a file of their own that `package_repair_cargo.rs` imports.
//!
//! In TS you'd write (pseudocode):
//! ```ts
//! const before = readLock(root); await clean(); restoreLock(root, before);
//! ```
/// The debug log of the repair.
use cratedebug;
/// `Path`/`PathBuf` are borrowed/owned filesystem paths.
use ;
/// Tag used for diagnostics from this module.
const TAG: &str = "packageRepairCargoLock";
/// The lock file beside a workspace's root manifest.
const LOCK_FILE: &str = "Cargo.lock";
/// What:
/// The bytes of the workspace's `Cargo.lock`, or none when it has none.
/// Why:
/// `cargo clean --package` resolves the workspace, and Cargo rewrites a lock that no longer matches its manifest; the
/// new worktree must stay as checked out, so the file is put back afterwards.
///
/// In TS you'd write (pseudocode):
/// ```ts
/// const lock = readLock(root); // Uint8Array | undefined
/// ```
/// What:
/// Put `Cargo.lock` back as `before` read it, removing a lock that did not exist before.
/// Why:
/// A write is made only when the content changed, so an untouched lock keeps its file time. A lock that cannot be put back
/// is logged, and left for the person: it is the worktree's own file and the checkout shows the difference.
///
/// In TS you'd write (pseudocode):
/// ```ts
/// restoreLock(root, before);
/// ```