瀏覽代碼

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.
Tim Byrne 6 年之前
父節點
當前提交
0c6be5e398
共有 1 個文件被更改,包括 17 次插入19 次删除
  1. 17 19
      yadm

+ 17 - 19
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