Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support alt dirs with deeply nested tracked files #495

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion test/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

# 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
Expand Down
20 changes: 16 additions & 4 deletions yadm
Original file line number Diff line number Diff line change
Expand Up @@ -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")" \
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was just a drive-by cleanup I noticed, from reading builtin_dirname's comment it seems like it should be more portable?

-v classes="$(join_string $'\n' "${local_classes[@]}")" \
"$awk_pgm" \
"$input" > "$temp_file" || rm -f "$temp_file"
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion yadm.1
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,7 @@ If no "##default" version exists and no files have valid conditions, then no
link will be created.

Links are also created for directories named this way, as long as they have at
least one yadm managed file within them (at the top level).
least one yadm managed file as a descendant.

yadm will automatically create these links by default. This can be disabled
using the
Expand Down
2 changes: 1 addition & 1 deletion yadm.md
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@
then no link will be created.

Links are also created for directories named this way, as long as they
have at least one yadm managed file within them (at the top level).
have at least one yadm managed file as a descendant.

yadm will automatically create these links by default. This can be dis‐
abled using the yadm.auto-alt configuration. Even if disabled, links
Expand Down