diff options
| author | tv <tv@krebsco.de> | 2026-11-24 04:52:13 +0000 |
|---|---|---|
| committer | tv <tv@krebsco.de> | 2026-11-24 04:52:13 +0000 |
| commit | 6ea379dbf3aad696f3aab3a145a877c4986e64e3 (patch) | |
| tree | fb5a1704be1b5900c74edb6f14297af3c87ea3ac /pkgs/populate/src/sh.rs | |
| parent | a021d211906d23c9e3454da974806454e9ec74c2 (diff) | |
populate symlink: replace a directory at the target path
ln -f replaces files and links, but not directories, so a symlink source
failed where a directory was, e.g. the Git work tree of a source that had
another type: "cannot overwrite directory". The symlink script removes
what isn't a link first, with remove_tree, which also copes with
directories that aren't writable.
Diffstat (limited to 'pkgs/populate/src/sh.rs')
| -rw-r--r-- | pkgs/populate/src/sh.rs | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/pkgs/populate/src/sh.rs b/pkgs/populate/src/sh.rs index 71f5ebf..7f179e4 100644 --- a/pkgs/populate/src/sh.rs +++ b/pkgs/populate/src/sh.rs @@ -343,14 +343,22 @@ fi } /// symlink PATH TARGET: makes PATH a symlink to TARGET, printing changed -/// if it wasn't one. -pub const SYMLINK: &str = r#" +/// if it wasn't one. What else is at PATH, e.g. the Git work tree of a +/// source that had another type, gets removed first: ln -f replaces files +/// and links, but not directories. +pub fn symlink() -> String { + REMOVE_TREE.to_string() + + r#" old=$(readlink "$1") || old= +if ! test -L "$1" && test -e "$1"; then + remove_tree "$1" +fi ln -fnsT -- "$2" "$1" if test "$old" != "$2"; then echo changed fi -"#; +"# +} /// Defines git_problems PATH, which prints why populate can't use the .git /// directory of the Git work tree at PATH, or nothing. A .git directory |
