From e12172d31584a5083a01fc89af6b8a7561a54743 Mon Sep 17 00:00:00 2001 From: Ian Chamberlain Date: Mon, 9 Sep 2024 23:24:07 -0400 Subject: [PATCH] Support deeply nested alts Now, as long as there is a tracked file *somewhere* under the alt directory, it will be linked correctly, instead of requiring the tracked files to be direct children of the alt dir. --- test/utils.py | 2 +- yadm | 20 ++++++++++++++++---- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/test/utils.py b/test/utils.py index c36ecac..f7aa5eb 100644 --- a/test/utils.py +++ b/test/utils.py @@ -12,7 +12,7 @@ ALT_DIR = "test alt/test alt dir" # Directory based alternates must have a tracked contained file. # This will be the test contained file name -CONTAINED = "contained_file" +CONTAINED = "contained_dir/contained_file" # These variables are used for making include files which will be processed # within jinja templates diff --git a/yadm b/yadm index 09da278..06c00b9 100755 --- a/yadm +++ b/yadm @@ -461,7 +461,7 @@ EOF -v distro="$local_distro" \ -v distro_family="$local_distro_family" \ -v source="$input" \ - -v source_dir="$(dirname "$input")" \ + -v source_dir="$(builtin_dirname "$input")" \ -v classes="$(join_string $'\n' "${local_classes[@]}")" \ "$awk_pgm" \ "$input" > "$temp_file" || rm -f "$temp_file" @@ -692,9 +692,21 @@ function alt_linking() { local alt_sources=() local alt_template_cmds=() - for alt_path in $(for tracked in "${tracked_files[@]}"; do printf "%s\n" "$tracked" "${tracked%/*}"; done | LC_ALL=C sort -u) "${ENCRYPT_INCLUDE_FILES[@]}"; do - alt_path="$YADM_BASE/$alt_path" - if [[ "$alt_path" =~ .\#\#. ]]; then + for tracked_file in $(printf "%s\n" "${tracked_files[@]}" | LC_ALL=C sort -u) "${ENCRYPT_INCLUDE_FILES[@]}"; do + tracked_file="$YADM_BASE/$tracked_file" + if [[ "$tracked_file" =~ .\#\#. ]]; then + local alt_path=$tracked_file + + # Walk up the path until we find the last component with a ## marker; + # that will be the source of the alt symlink + while : ; do + local tmp; + tmp="$(builtin_dirname "$alt_path")" + [[ "$tmp" =~ .\#\#. ]] || break + alt_path=$tmp + done + + debug "Found alt at '$alt_path'" if [ -e "$alt_path" ] ; then score_file "$alt_path" fi