diff options
| author | tv <tv@krebsco.de> | 2026-11-13 04:49:28 +0000 |
|---|---|---|
| committer | tv <tv@krebsco.de> | 2026-11-13 04:49:28 +0000 |
| commit | b3c671bed4e785c732fdd881cf1cc39d852eb3bb (patch) | |
| tree | 136d29e5b909638cc8245df9b9c69b18f7911bad | |
| parent | 400006448a470d7f71393aaa461542b4764df4dd (diff) | |
populate: name the target's user in messages unless it's root
Messages naming the target, i.e. pruning's lines and the errors about
the sentinel, name the user as well, as user@host:path, unless the user
is root, the usual one, so deploying as another user, e.g. with sudo,
shows.
| -rw-r--r-- | pkgs/populate/default.nix | 17 | ||||
| -rw-r--r-- | tests/scenarios.nix | 8 |
2 files changed, 17 insertions, 8 deletions
diff --git a/pkgs/populate/default.nix b/pkgs/populate/default.nix index ae61aec..1a44044 100644 --- a/pkgs/populate/default.nix +++ b/pkgs/populate/default.nix @@ -78,9 +78,16 @@ let ''; # The path on the target, as populate names it in what it prints: - # prefixed by the host if the target isn't local. + # prefixed by the host if the target isn't local, and by the user as well + # if that isn't root. targetName = target: path: - optionalString (!isLocalTarget target) "${target.host}:" + path; + optionalString (!isLocalTarget target) ( + optionalString + (!elem target.user [ null "" "root" ]) + "${target.user}@" + + "${target.host}:" + ) + + path; # Shell code that removes the entries of the directory dir, a shell word, # that aren't named names. find, unlike a loop reading names, copes with @@ -92,14 +99,14 @@ let removeOthers = { dir, names, log ? null }: /* sh */ '' find ${dir} -mindepth 1 -maxdepth 1 \ ${concatMapStringsSep " " (name: "! -name ${quote name}") names} \ - -exec sh -c ' + -exec sh -c ${quote /* sh */ '' ${optionalString (log != null) /* sh */ '' log=$1 shift ''} for path; do ${optionalString (log != null) /* sh */ '' - >&2 printf "pruning %s/%s\n" "$log" "''${path##*/}" + >&2 printf "pruning '%s/%s'...\n" "$log" "''${path##*/}" ''} ${if log != null then /* sh */ '' rm -fR "$path" @@ -113,7 +120,7 @@ let fi ''} done - ' sh ${optionalString (log != null) log} {} + + ''} sh ${optionalString (log != null) log} {} + ''; # Shell code that removes a symlink at path, saying so, because the link diff --git a/tests/scenarios.nix b/tests/scenarios.nix index fea0a5a..90fe3cb 100644 --- a/tests/scenarios.nix +++ b/tests/scenarios.nix @@ -1050,9 +1050,11 @@ assert !(krops.isLocalTarget (targets.remote "/")); sources = { inherit (sources) a; b.symlink = "a"; }; prune = true; output = map - (name: "pruning ${ - optionalString (targetKind != "local") "${remoteHost}:" - }/var/krops/prune-${targetKind}/${name}") + (name: "pruning '${{ + local = ""; + remote = "${remoteHost}:"; + sudo = "deploy@${remoteHost}:"; + }.${targetKind}}/var/krops/prune-${targetKind}/${name}'...") [ "c" "d" "other" ]; check = '' test -e "$T"/a/flake.nix || fail "a removed" |
