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

Draft
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

ian-h-chamberlain
Copy link

What does this PR do?

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 (previous behavior).

What issues does this PR fix or reference?

Closes #490
Related: #328, #356

Previous Behavior

A tracked file had to be a direct child of the ## alt directory for linking the directory to work properly.

New Behavior

Any descendant of the ## alt directory will cause it to be treated as an alt, and the directory itself will be linked (same as previous behavior).

Have tests been written for this change?

Yes: Updated test_alt to use a subdirectory for its contained file as part of the tests. Verified the test failed before my changes and passes after.

Have these commits been signed with GnuPG?

Yes


Please review yadm's Contributing Guide for best practices.

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.
@@ -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?

@ian-h-chamberlain ian-h-chamberlain marked this pull request as draft November 26, 2024 15:45
@ian-h-chamberlain
Copy link
Author

This doesn't work quite how I thought it did, drafting for now until I maybe eventually get some time to work on a more robust solution.

@erijo
Copy link
Collaborator

erijo commented Nov 27, 2024

I'm currently working on refactoring the alt handling a bit and can try to incorporate a fix for this as well. So give me a week or two and we'll see if it turned out successful or not :)

erijo added a commit that referenced this pull request Nov 28, 2024
* Simplify score_file() by using case in instead of nested ifs with regexps.
* Merge record_score() and record_template().
* Alt condition processing no longer stops when a template condition is seen
  but continues processing to verify that all conditions are valid (as the
  documentation says it should). Fixes #478.
* Support alt dirs with deeply nested tracked files (fixes #495).
* Use git ls-files to filter out which tracked files to consider for alt
  processing. Should speed up auto-alt (#505).
@erijo
Copy link
Collaborator

erijo commented Nov 29, 2024

@ian-h-chamberlain: If you have the time, could you please test with the deep-alt branch and see if it works as you expect?

@ian-h-chamberlain
Copy link
Author

ian-h-chamberlain commented Nov 29, 2024

@ian-h-chamberlain: If you have the time, could you please test with the deep-alt branch and see if it works as you expect?

@erijo wow, quick turnaround! I think the changes in that branch do work, but it has the same problem my attempt had; there's no way to merge the linked directory, and if it already exists the symlink will be created as a child instead of what I thought the behavior should be (symlink all the children to their respective locations).

Here's an example that hopefully shows what I mean (current behavior):

$ yadm ls-files .config/yadm/alt/Services* | tree --fromfile
./
└── .config/
    └── yadm/
        └── alt/
            └── Services##os.Darwin/
                └── Open in Visual Studio Code.workflow/
                    └── Contents/
                        ├── Info.plist 
                        ├── QuickLook/
                        │   └── Thumbnail.png
                        ├── Resources/
                        │   └── workflowCustomImage.icns
                        └── document.wflow

9 directories, 4 files

$ yadm alt 
[...]
Linking /Users/ianchamberlain/.config/yadm/alt/Services##os.Darwin to /Users/ianchamberlain/Services

$ tree -F ~/Services
/Users/ianchamberlain/Services/
└── Services##os.Darwin -> .config/yadm/alt/Services##os.Darwin

1 directory, 2 files

I think ideally, what it should do is something like this:

$ yadm alt 
[...]
Linking /Users/ianchamberlain/.config/yadm/alt/Services##os.Darwin/Open in Visual Studio Code.workflow/Contents/Info.plist to /Users/ianchamberlain/Services/Open in Visual Studio Code.workflow/Contents/Info.plist
Linking /Users/ianchamberlain/.config/yadm/alt/Services##os.Darwin/Open in Visual Studio Code.workflow/Contents/QuickLook/Thumbnail.png to /Users/ianchamberlain/Services/Open in Visual Studio Code.workflow/Contents/QuickLook/Thumbnail.png
Linking /Users/ianchamberlain/.config/yadm/alt/Services##os.Darwin/Open in Visual Studio Code.workflow/Contents/Resources/workflowCustomImage.icns to /Users/ianchamberlain/Services/Open in Visual Studio Code.workflow/Contents/Resources/workflowCustomImage.icns
Linking /Users/ianchamberlain/.config/yadm/alt/Services##os.Darwin/Open in Visual Studio Code.workflow/Contents/document.wflow to /Users/ianchamberlain/Services/Open in Visual Studio Code.workflow/Contents/document.wflow

$ tree -F ~/Services
/Users/ianchamberlain/Services/
└── Open in Visual Studio Code.workflow/
    └── Contents/
        ├── Info.plist -> .config/yadm/alt/Services##os.Darwin/Open in Visual Studio Code.workflow/Contents/Info.plist
        ├── QuickLook/
        │   └── Thumbnail.png -> .config/yadm/alt/Services##os.Darwin/Open in Visual Studio Code.workflow/Contents/QuickLook/Thumbnail.png
        ├── Resources/
        │   └── workflowCustomImage.icns -> .config/yadm/alt/Services##os.Darwin/Open in Visual Studio Code.workflow/Contents/Resources/workflowCustomImage.icns
        └── document.wflow -> .config/yadm/alt/Services##os.Darwin/Open in Visual Studio Code.workflow/Contents/document.wflow

Hopefully that makes sense... it might be slightly trickier to implement but maybe your refactors will make it a little easier?

@erijo
Copy link
Collaborator

erijo commented Nov 29, 2024

there's no way to merge the linked directory, and if it already exists the symlink will be created as a child instead of what I thought the behavior should be (symlink all the children to their respective locations).

Aha, I didn't even consider that way of doing it, but it sounds like a reasonable way to handle this case. I'll look into soon (tm) :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants