aboutsummaryrefslogtreecommitdiffstats
path: root/pkgs
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-11-24 04:53:59 +0000
committertv <tv@krebsco.de>2026-11-24 04:53:59 +0000
commit4daacdbad12cf333da0f1783def2364935672752 (patch)
tree4b884a0e7bba99ac5cff160ba2b180e9913c3c0f /pkgs
parent6ea379dbf3aad696f3aab3a145a877c4986e64e3 (diff)
populate: remove what's at a target path with remove_tree
What a source replaces at its target path, e.g. what a source of another type delivered there, may have directories that aren't writable, e.g. a copy of a store path, which rm -fR can't empty unless populate runs as root. make_room_for_link (derivations, links to flakes), git sources, and materializing remove it with remove_tree instead, which makes directories writable first, and only directories.
Diffstat (limited to 'pkgs')
-rw-r--r--pkgs/populate/src/sh.rs17
1 files changed, 10 insertions, 7 deletions
diff --git a/pkgs/populate/src/sh.rs b/pkgs/populate/src/sh.rs
index 7f179e4..77d2463 100644
--- a/pkgs/populate/src/sh.rs
+++ b/pkgs/populate/src/sh.rs
@@ -61,7 +61,8 @@ remove_tree() {
/// the link points into the store, like the links populate puts there
/// itself, and make_room_for_link PATH NAME makes room at PATH for a link
/// into the store, which Nix only puts in place of another link into the
-/// store.
+/// store, removing what else is there with remove_tree, which REMOVE_TREE
+/// defines.
pub const LINKS: &str = r#"
remove_link() {
if test -L "$1"; then
@@ -82,7 +83,7 @@ remove_foreign_link() {
make_room_for_link() {
remove_foreign_link "$1" "$2"
if ! test -L "$1" && test -e "$1"; then
- rm -fR "$1"
+ remove_tree "$1"
fi
}
"#;
@@ -329,7 +330,8 @@ fi
/// with a link to the result at PATH, printing the result, and changed if
/// the link changed.
pub fn derivation() -> String {
- LINKS.to_string()
+ REMOVE_TREE.to_string()
+ + LINKS
+ r#"
old=$(readlink "$1") || old=
make_room_for_link "$1" "$2"
@@ -454,7 +456,8 @@ git_problems() (
/// the commit checked out, on lines of their own; what commands print goes
/// to standard error.
pub fn git() -> String {
- LINKS.to_string()
+ REMOVE_TREE.to_string()
+ + LINKS
+ GIT_PROBLEMS
+ r#"
# What commands print goes to standard error. None of them gets the
@@ -485,7 +488,7 @@ deliver_git() {
# elsewhere.
remove_link "$path" "$name"
if test -L "$path"/.git || ! test -d "$path"/.git; then
- rm -fR "$path"
+ remove_tree "$path"
fi
# A .git directory can name places elsewhere too, which Git's commands
# change, or commands, which they run. Populate only uses a work tree
@@ -499,7 +502,7 @@ deliver_git() {
if test -n "$reclone"; then
>&2 printf "replacing the Git work tree '%s', because %s...\n" \
"$name" "$problems"
- rm -fR "$path"
+ remove_tree "$path"
else
>&2 printf 'error: populate doesn'"'"'t use the Git work tree %s, because %s. Fix that, remove the work tree, or set the source'"'"'s reclone to true to replace it by a fresh clone.\n' \
"$name" "$problems"
@@ -1217,7 +1220,7 @@ if test -n "$patch_dir"; then
)
fi
remove_foreign_link "$target_path" "$target_name"
-rm -fR "$target_path"
+remove_tree "$target_path"
mv "$work" "$target_path"
write_key "$key_file" "$key"
echo changed