Skip to content

Fix bug templating subdomain static dirs via Ansible module#244

Merged
jdavcs merged 4 commits intogalaxyproject:mainfrom
kysrpex:themes_symlink_clone_module
Mar 12, 2026
Merged

Fix bug templating subdomain static dirs via Ansible module#244
jdavcs merged 4 commits intogalaxyproject:mainfrom
kysrpex:themes_symlink_clone_module

Conversation

@kysrpex
Copy link
Contributor

@kysrpex kysrpex commented Mar 11, 2026

This PR fixes two problems.


FileNotFoundError when a directory doesn't exist in the target subdomain static dir

If the target path does not exist, dst_stat = dst_path.lstat() leads to an error FileNotFoundError: [Errno 2] No such file or directory: ....

Rearrange the line dst_stat = dst_path.lstat() and add a check based on dst_path.exists() for the case where src_path.is_dir() == False and dst_path.exists() == False; for example when the source is a file and the target does not exist.

Given that we are not dealing with file types other than symlinks, directories and regular files, that should be enough.


Directory comparisons are not recursive.

filecmp.dircmp() does not compare directories recursively. To detect if subdomain static dirs contents have changed, use a new function compare_dirs() that runs filecmp.dircmp() recursively.

kysrpex added 3 commits March 11, 2026 17:12
If the target path does not exist, `dst_stat = dst_path.lstat()` leads to an error `FileNotFoundError: [Errno 2] No such file or directory: ...`.

Rearrange the line `dst_stat = dst_path.lstat()` and add a check based on `dst_path.exists()` for the case where `src_path.is_dir() == False` and `dst_path.exists() == False`; for example when the source is a file and the target does not exist.
…dirs

The function `compare_permissions()` is meant to compare permissions, ownership and type (file or directory). But only if both paths exist.

The case in which files exist only in the source directory is handled by `filecmp.dircmp().left_only` within `run_module()`.
`filecmp.dircmp()` does not compare directories recursively.

To detect if subdomain static dirs contents have changed, use a new function `compare_dirs()` that runs `filecmp.dircmp()` recursively.
@kysrpex kysrpex marked this pull request as ready for review March 12, 2026 10:32
@kysrpex
Copy link
Contributor Author

kysrpex commented Mar 12, 2026

@jdavcs this is a follow-up for #232.

The first error was detected because it was showing up on the CI, but I noticed also the second while fixing the former. It's surprising that it went under the radar for so long, especially considering it severly breaks the functionality (directories are only merged if a change is detected).

kysrpex added a commit to usegalaxy-eu/infrastructure-playbook that referenced this pull request Mar 12, 2026
Apply the bugfixes introduced in galaxyproject/ansible-galaxy#244 related to the deployment of subdomain static dirs.
@jdavcs jdavcs self-assigned this Mar 12, 2026
Copy link
Member

@jdavcs jdavcs left a comment

Choose a reason for hiding this comment

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

Great catch!
Works for me. I have just one request. It was not obvious to me what compare_dirs returns. I expected the opposite: True if there is no difference - i.e., similar to how filecmp.cmp() works. I don't switching to logic makes sense here since it's not a straightforward comparison like the cmp() function. However, maybe change the function name to something more explicit? (like dirs_have_changed?) Or, maybe even better, specify in the function docstring what it returns. Either one is fine - as long as it's obvious what it returns.

@jdavcs jdavcs merged commit c9481cd into galaxyproject:main Mar 12, 2026
0 of 23 checks passed
@kysrpex
Copy link
Contributor Author

kysrpex commented Mar 12, 2026

Thanks for creating the release!

@kysrpex kysrpex deleted the themes_symlink_clone_module branch March 12, 2026 15:11
@jdavcs
Copy link
Member

jdavcs commented Mar 12, 2026

@kysrpex new release imported to ansible galaxy. (I saw you updated your infrastructure playbook)

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