From 0c6be5e398e9fe6eb23c6110f17c4ea233c2bc15 Mon Sep 17 00:00:00 2001 From: Tim Byrne Date: Fri, 5 Apr 2019 07:46:56 -0500 Subject: [PATCH] Fix bug with alternate linked directories Previously the tracked files were sorted, and then the files and their parent directories were considered for possible alternates. Depending on the length of directories and names of files, inconsistencies would occur because the directory separator (/) would be part of the sorting. To fix this, a unique list of tracked files and their parent directories are sorted into a single list which is processed. --- yadm | 36 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/yadm b/yadm index 2190614..2e762aa 100755 --- a/yadm +++ b/yadm @@ -181,29 +181,27 @@ function alt() { for match in $match1 $match2; do last_linked='' local IFS=$'\n' - for tracked_file in $("$GIT_PROGRAM" ls-files | sort) "${ENCRYPT_INCLUDE_FILES[@]}"; do - tracked_file="$YADM_WORK/$tracked_file" - # process both the path, and it's parent directory - for alt_path in "$tracked_file" "${tracked_file%/*}"; do - if [ -e "$alt_path" ] ; then - if [[ $alt_path =~ $match ]] ; then - if [ "$alt_path" != "$last_linked" ] ; then - new_link="${BASH_REMATCH[1]}" - debug "Linking $alt_path to $new_link" - [ -n "$loud" ] && echo "Linking $alt_path to $new_link" - if [ "$do_copy" -eq 1 ]; then - if [ -L "$new_link" ]; then - rm -f "$new_link" - fi - cp -f "$alt_path" "$new_link" - else - ln -nfs "$alt_path" "$new_link" + # the alt_paths looped over here are a unique sorted list of both files and their immediate parent directory + for alt_path in $(for tracked in $("$GIT_PROGRAM" ls-files); do printf "%s\n" "$tracked" "${tracked%/*}"; done | sort -u) "${ENCRYPT_INCLUDE_FILES[@]}"; do + alt_path="$YADM_WORK/$alt_path" + if [ -e "$alt_path" ] ; then + if [[ $alt_path =~ $match ]] ; then + if [ "$alt_path" != "$last_linked" ] ; then + new_link="${BASH_REMATCH[1]}" + debug "Linking $alt_path to $new_link" + [ -n "$loud" ] && echo "Linking $alt_path to $new_link" + if [ "$do_copy" -eq 1 ]; then + if [ -L "$new_link" ]; then + rm -f "$new_link" fi - last_linked="$alt_path" + cp -f "$alt_path" "$new_link" + else + ln -nfs "$alt_path" "$new_link" fi + last_linked="$alt_path" fi fi - done + fi done done