Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ and listed with their assets on the

### Fixed

- **A directory renamed or removed in a worktree goes from the lane's copy**
(#628). The copy removed the files but kept their directories, empty: a
service that reads one folder per entry saw a phantom one. Now a directory
the removal leaves empty, and the worktree no longer has, goes too; one
that holds anything else (a build's output) stays. The same holds for a
lane on a node and for the snapshot builds run in. Empty directories a
copy kept before this release stay until the copy is made anew.
- **A stopped stack no longer shows the memory of its containers.** When
the last container stopped, the daemon kept its last load, so a group and
the lane card showed gigabytes after `down` (and the lane's estimate for
Expand Down
52 changes: 52 additions & 0 deletions crates/devstack-build/src/snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ impl Snapshot {
.filter(|k| !listed.contains(k.as_str()))
{
let _ = fs::remove_file(self.dir.join(gone));
self.remove_emptied(gone);
removed += 1;
}
// A first sync has no watcher to wait for: nothing runs from the
Expand Down Expand Up @@ -221,6 +222,21 @@ impl Snapshot {
})
}

/// The directories of `rel`, a file just removed from the copy, that it
/// left empty and the source no longer has (#628): a directory renamed or
/// removed in the worktree goes from the copy too, where a service that
/// reads one folder per entry would see it still. One that holds
/// anything else (a build's output) stays.
fn remove_emptied(&self, rel: &str) {
let mut parent = Path::new(rel).parent();
while let Some(dir) = parent.filter(|d| !d.as_os_str().is_empty()) {
if self.source.join(dir).is_dir() || fs::remove_dir(self.dir.join(dir)).is_err() {
return;
}
parent = dir.parent();
}
}

/// Clear the way for the copy of `rel`: a file where one of its parent
/// directories goes, or a directory where the file goes, is what an
/// earlier sync left of a path that changed its type.
Expand Down Expand Up @@ -413,6 +429,42 @@ mod tests {
assert_eq!(snap.list().unwrap(), vec!["devstack.toml", "src/a/x.cs"]);
}

/// #628: a directory renamed or removed in the worktree goes from the
/// copy too; a service that reads one folder per entry saw it still.
/// What the copy holds beyond the snapshot (a build's output) stays.
#[test]
fn a_directory_gone_from_the_source_goes_from_the_copy() {
let src = tempfile::tempdir().unwrap();
let a = src.path().join("org/agents/a/v1");
std::fs::create_dir_all(&a).unwrap();
std::fs::write(a.join("agent.yaml"), "a").unwrap();
std::fs::write(a.join("prompt.md"), "a").unwrap();
std::fs::create_dir_all(src.path().join("org/tools")).unwrap();
std::fs::write(src.path().join("org/tools/t.yaml"), "t").unwrap();
let state = tempfile::tempdir().unwrap();
let mut snap = super::Snapshot::open(src.path(), state.path()).unwrap();
snap.sync().unwrap();
// Written in the copy by a build: not the snapshot's.
std::fs::create_dir_all(snap.dir.join("org/tools/bin")).unwrap();
std::fs::write(snap.dir.join("org/tools/bin/out.dll"), "built").unwrap();

// `git mv org/agents/a org/agents/b`, and the tools' file removed.
std::fs::rename(
src.path().join("org/agents/a"),
src.path().join("org/agents/b"),
)
.unwrap();
std::fs::remove_file(src.path().join("org/tools/t.yaml")).unwrap();
snap.sync().unwrap();

assert!(snap.dir.join("org/agents/b/v1/agent.yaml").is_file());
assert!(
!snap.dir.join("org/agents/a").exists(),
"the renamed directory stayed in the copy"
);
assert!(snap.dir.join("org/tools/bin/out.dll").is_file());
}

/// A watcher like `@parcel/watcher` on Linux (Angular's dev server,
/// #507): inotify on each directory, a new directory watched when its
/// creation is seen in a watched one, never by reading it. Every
Expand Down
Loading