1
0
Fork 0
mirror of synced 2024-12-13 02:45:45 -05:00

Use relative symlinks for alt (#100)

* Fix broken support for .config/yadm/alt
* Removes dependence on external basename / dirname
This commit is contained in:
Tim Byrne 2019-11-17 13:07:29 -06:00
parent 98392b9a9c
commit 61576a6ae1
No known key found for this signature in database
GPG key ID: 14DB4FC2465A4B12

27
yadm
View file

@ -422,7 +422,12 @@ function alt() {
local IFS=$'\n'
for possible_alt in "${tracked_files[@]}" "${ENCRYPT_INCLUDE_FILES[@]}"; do
if [[ $possible_alt =~ .\#\#. ]]; then
possible_alts+=("$YADM_WORK/${possible_alt%%##*}")
base_alt="${possible_alt%%##*}"
yadm_alt="${YADM_WORK}/${base_alt}"
if [ "${yadm_alt#$YADM_ALT/}" != "${yadm_alt}" ]; then
base_alt="${yadm_alt#$YADM_ALT/}"
fi
possible_alts+=("$YADM_WORK/${base_alt}")
fi
done
local alt_linked
@ -449,7 +454,6 @@ function remove_stale_links() {
if [ -n "$link_target" ]; then
for review_link in "${alt_linked[@]}"; do
[ "$link_target" = "$review_link" ] && continue 2
[ "$link_target" = "$(basename "$review_link")" ] && continue 2
done
rm -f "$stale_candidate"
fi
@ -527,7 +531,6 @@ function alt_future_linking() {
cp -f "$target" "$filename"
else
alt_ln "$target" "$filename"
alt_linked+=("$target")
fi
fi
done
@ -571,7 +574,6 @@ function alt_past_linking() {
cp -f "$alt_path" "$new_link"
else
alt_ln "$alt_path" "$new_link"
alt_linked+=("$alt_path")
fi
last_linked="$alt_path"
fi
@ -608,17 +610,12 @@ function alt_past_linking() {
}
function alt_ln() {
local alt_dir alt_base new_base
alt_dir="$(dirname "$1")"
alt_base="$(basename "$1")"
new_base="$(basename "$2")"
if pushd "$alt_dir" >/dev/null ; then
ln -nfs "$alt_base" "$new_base"
popd &>/dev/null
else
ln -nfs "$1" "$2"
fi
local full_link base
full_link="$2"
base="${full_link%/*}"
rel_source=$(relative_path "$base" "$1")
ln -nfs "$rel_source" "$full_link"
alt_linked+=("$rel_source")
}
function bootstrap() {