11//! What a task can rebuild, so a later run may find it missing.
22//!
3- //! Inputs are fingerprinted as the task left them, so they include the files
4- //! a task read and then wrote, such as a tool's cache file. A clean checkout
5- //! (CI, a fresh clone) doesn't have those files yet, and running the task
6- //! would write them again, so a later run may find them missing. A file that
7- //! is there must still be as the task left it.
3+ //! Inputs are fingerprinted as the task left them, including files it read
4+ //! and then wrote. A rebuildable file may be missing on a later run, as on
5+ //! a clean checkout. A file that is there must still match the fingerprint.
86//!
9- //! The same goes for an empty folder the task made (built-in ignored paths
10- //! such as `.DS_Store` aside), and for a folder that holds only what the task
11- //! can rebuild: every file (or symlink) in it is one the task wrote, and every
12- //! folder in it is rebuildable too. None of these is fingerprinted at all. A hit
13- //! restores the files and the empty folders, which are archived as folders, if
14- //! they're among the task's outputs, and the files recreate the folders holding
15- //! them; explicit output config can leave them out. Such folders are found after
16- //! the run by climbing from the written paths and the empty folders through
17- //! their parent folders inside the workspace, listing each one once in the real
18- //! file system. A written path or folder that is gone by then plays no part. A
19- //! listing of any other folder leaves out its entries that the task can rebuild,
20- //! which a later run may find missing too.
7+ //! A folder is rebuildable when the task made it and it is empty, or when it
8+ //! contains at least one entry and all entries are rebuildable. Both checks
9+ //! skip built- in ignored entries such as `.DS_Store`. None of these is
10+ //! fingerprinted at all. A hit restores the files and the empty folders, which
11+ //! are archived as folders, if they're among the task's outputs, and the files
12+ //! recreate the folders holding them; explicit output config can leave them
13+ //! out. Such folders are found after the run by climbing from the written
14+ //! paths and the empty folders through their parent folders inside the
15+ //! workspace, listing each one once in the real file system. A written path or
16+ //! folder that is gone by then plays no part. A listing of any other folder
17+ //! leaves out its entries that the task can rebuild, which a later run may
18+ //! find missing too.
2119//!
22- //! The written paths are fspy's records before output exclusions and
23- //! tool-reported `ignoreOutput` paths are applied: those decide what is
24- //! archived, not what the task can rebuild. A rename target that is a folder
25- //! after the run, like Vite's `deps` folder renamed into place, stands for
26- //! writes of every file (and symlink) under it; the folder itself and the
27- //! folders in it don't count as written. The archive takes those files like
28- //! any written file. The rename's source, like Vite's `deps_temp_*` folder,
29- //! isn't recorded, but a path that is gone after the run and that the task
30- //! wrote in counts as written: the task made or removed it. It is
31- //! fingerprinted as missing, which a later run must match either way, so this
20+ //! The written paths come from fspy. A file the task reads and writes is a
21+ //! required input when `ignoreOutput` covers it and the read survives input
22+ //! filtering. Its absence makes the next run miss. Output negative globs
23+ //! only decide what is archived.
24+ //!
25+ //! A rename target that is a folder after the run, like Vite's `deps` folder
26+ //! renamed into place, stands for writes of every file (and symlink) under
27+ //! it. The folder itself and the folders in it don't count as written.
28+ //! The archive takes those files like any written file. The rename's source,
29+ //! like Vite's `deps_temp_*` folder, isn't recorded. A path that is gone after
30+ //! the run counts as written if the task wrote in it. It is fingerprinted
31+ //! as missing, which a later run must match either way, so this
3232//! only tells it apart from a path the task looked for and didn't find. A
3333//! write record on a path that is a folder, from opening it with write
3434//! access, is ignored. A mkdir record counts only for a folder that is empty
@@ -45,12 +45,12 @@ use vt_path::{AbsolutePath, RelativePath, RelativePathBuf};
4545
4646use super :: { fingerprint:: PathFingerprint , ignored_paths:: IgnoredDirEntries } ;
4747
48- /// The paths a task wrote, the empty folders it made, and the folders
49- /// holding only what it can rebuild, relative to the workspace root.
48+ /// The rebuildable paths a task wrote, the empty folders it made, and the
49+ /// folders holding only what it can rebuild, relative to the workspace root.
5050#[ derive( Debug , Default ) ]
5151pub struct Rebuildable {
5252 written : FxHashSet < RelativePathBuf > ,
53- /// The folders the task made, or tried to make, inside the workspace .
53+ /// The folders the task made or tried to make, excluding required paths .
5454 mkdirs : FxHashSet < RelativePathBuf > ,
5555 /// The `mkdirs` that are empty folders.
5656 empty_folders : FxHashSet < RelativePathBuf > ,
@@ -61,19 +61,13 @@ pub struct Rebuildable {
6161}
6262
6363impl Rebuildable {
64- /// Takes the `written` paths and the `rename_targets` as written, with the
65- /// files under a renamed folder in place of the folder, by looking under
66- /// `workspace_root`, which must be done after the run, and the `mkdirs`.
64+ /// Takes the rebuildable `written` paths and `mkdirs`.
6765 /// No folder is rebuildable, and none of the `mkdirs` is an empty folder,
68- /// until [`Self::with_folders `] or [`Self::with_empty_folders`] finds them.
69- pub fn new (
66+ /// until [`Self::with_folders_excluding `] or [`Self::with_empty_folders`] finds them.
67+ pub ( super ) fn from_written (
7068 written : FxHashSet < RelativePathBuf > ,
71- rename_targets : FxHashSet < RelativePathBuf > ,
7269 mkdirs : FxHashSet < RelativePathBuf > ,
73- workspace_root : & AbsolutePath ,
74- cache_root : Option < & RelativePath > ,
7570 ) -> Self {
76- let written = files_written ( written, rename_targets, workspace_root, cache_root) ;
7771 let mut written_in = FxHashSet :: default ( ) ;
7872 for path in & written {
7973 let mut dir = path. parent ( ) ;
@@ -101,13 +95,14 @@ impl Rebuildable {
10195 /// Only fingerprints of the paths the task read ask about folders, so a
10296 /// run without such reads takes [`Self::with_empty_folders`] instead.
10397 #[ must_use]
104- pub fn with_folders (
98+ pub ( super ) fn with_folders_excluding (
10599 mut self ,
106100 workspace_root : & AbsolutePath ,
107101 cache_root : Option < & RelativePath > ,
102+ required_writes : & FxHashSet < RelativePathBuf > ,
108103 ) -> Self {
109104 ( self . folders , self . empty_folders ) =
110- find_folders ( & self . written , & self . mkdirs , workspace_root, cache_root) ;
105+ find_folders ( & self . written , required_writes , & self . mkdirs , workspace_root, cache_root) ;
111106 self
112107 }
113108
@@ -129,8 +124,8 @@ impl Rebuildable {
129124 self
130125 }
131126
132- /// The paths the task wrote or renamed a file to, and the files under the
133- /// folders it renamed.
127+ /// The rebuildable paths the task wrote or renamed a file to, and the
128+ /// rebuildable files under the folders it renamed.
134129 pub const fn written ( & self ) -> & FxHashSet < RelativePathBuf > {
135130 & self . written
136131 }
@@ -141,12 +136,12 @@ impl Rebuildable {
141136 & self . empty_folders
142137 }
143138
144- /// Whether a later run may find ` path`, which a read found as
145- /// `fingerprint`, missing: the task wrote it, or it is gone after the run
146- /// and the task wrote in it . A write record on a folder, from opening it
147- /// with write access, is ignored. Only a written path that the read found
148- /// as a folder is stat'd under `workspace_root`, to tell a folder from a
149- /// link the task made to one.
139+ /// Whether a later run may find the path missing. A rebuildable write
140+ /// allows this. A post-run `NotFound` also allows it if the task has a
141+ /// rebuildable write below the path . A write record on a folder, from
142+ /// opening it with write access, is ignored. Only a written path that the
143+ /// read found as a folder is stat'd under `workspace_root`, to tell a
144+ /// folder from a link the task made to one.
150145 pub fn may_be_missing (
151146 & self ,
152147 path : & RelativePath ,
@@ -195,7 +190,7 @@ impl Rebuildable {
195190/// under it counts, folder entries are checked against the rebuildable
196191/// folders, and the archive skips folders, so only a read of it has to tell
197192/// (see [`Rebuildable::may_be_missing`]).
198- fn files_written (
193+ pub ( super ) fn files_written (
199194 mut written : FxHashSet < RelativePathBuf > ,
200195 rename_targets : FxHashSet < RelativePathBuf > ,
201196 workspace_root : & AbsolutePath ,
@@ -276,8 +271,11 @@ fn is_empty_folder(
276271/// candidates too. Climbing stops at the first folder that isn't rebuildable,
277272/// since no folder above it can be, and at the workspace root. A folder that
278273/// is gone plays no part: its parent is decided by the entries it holds.
274+ /// Required writes are skipped so a tracked directory link stays required
275+ /// even if the task wrote through it.
279276fn find_folders (
280277 written : & FxHashSet < RelativePathBuf > ,
278+ required_writes : & FxHashSet < RelativePathBuf > ,
281279 mkdirs : & FxHashSet < RelativePathBuf > ,
282280 workspace_root : & AbsolutePath ,
283281 cache_root : Option < & RelativePath > ,
@@ -300,7 +298,8 @@ fn find_folders(
300298 empty_folders. insert ( dir. to_relative_path_buf ( ) ) ;
301299 }
302300 }
303- let mut candidates: Vec < & RelativePath > = candidates. into_iter ( ) . collect ( ) ;
301+ let mut candidates: Vec < & RelativePath > =
302+ candidates. into_iter ( ) . filter ( |dir| !required_writes. contains ( * dir) ) . collect ( ) ;
304303 sort_deepest_first ( & mut candidates) ;
305304
306305 let mut folders = empty_folders. clone ( ) ;
@@ -351,8 +350,7 @@ fn sort_deepest_first(dirs: &mut [&RelativePath]) {
351350/// aside, which don't count, as in directory listing fingerprints.
352351enum Holds {
353352 Nothing ,
354- /// At least one entry, each a file (or symlink) the task wrote or a
355- /// rebuildable folder.
353+ /// At least one entry, with every entry rebuildable.
356354 OnlyRebuildable ,
357355 /// Anything else, or entries that can't be read or named.
358356 Other ,
@@ -415,3 +413,27 @@ fn is_rebuildable(
415413) -> bool {
416414 if is_dir { folders. contains ( path) } else { written. contains ( path) }
417415}
416+
417+ #[ cfg( test) ]
418+ impl Rebuildable {
419+ pub ( super ) fn new (
420+ written : FxHashSet < RelativePathBuf > ,
421+ rename_targets : FxHashSet < RelativePathBuf > ,
422+ mkdirs : FxHashSet < RelativePathBuf > ,
423+ workspace_root : & AbsolutePath ,
424+ cache_root : Option < & RelativePath > ,
425+ ) -> Self {
426+ Self :: from_written (
427+ files_written ( written, rename_targets, workspace_root, cache_root) ,
428+ mkdirs,
429+ )
430+ }
431+
432+ pub ( super ) fn with_folders (
433+ self ,
434+ workspace_root : & AbsolutePath ,
435+ cache_root : Option < & RelativePath > ,
436+ ) -> Self {
437+ self . with_folders_excluding ( workspace_root, cache_root, & FxHashSet :: default ( ) )
438+ }
439+ }
0 commit comments