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

Symlinks in paths causes Path.relative_to() to fail #119

Closed
kodek opened this issue Mar 13, 2023 · 2 comments
Closed

Symlinks in paths causes Path.relative_to() to fail #119

kodek opened this issue Mar 13, 2023 · 2 comments

Comments

@kodek
Copy link

kodek commented Mar 13, 2023

It looks like the created worktree uses an absolute path (/private/var/..., [1]) whereas the process path is using the symlink path (/var/...).

This is probably hacky, but calling Path.resolve() in PathSelector.relative_to solves the issue:

        return self.process_path.resolve().relative_to(self.root.resolve())

Stack trace:

❯ fl diff hr datalore -n datalore --path k8s/
Traceback (most recent call last):
  File "/opt/homebrew/bin/flux-local", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/flux_local/tool/flux_local.py", line 86, in main
    asyncio.run(action.run(**vars(args)))
  File "/opt/homebrew/Cellar/python@3.11/3.11.2_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/asyncio/runners.py", line 190, in run
    return runner.run(main)
           ^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/python@3.11/3.11.2_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/asyncio/runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/python@3.11/3.11.2_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/asyncio/base_events.py", line 653, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/flux_local/tool/diff.py", line 308, in run
    await git_repo.build_manifest(selector=query)
  File "/opt/homebrew/lib/python3.11/site-packages/flux_local/git_repo.py", line 516, in build_manifest
    clusters = await get_clusters(
               ^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/flux_local/git_repo.py", line 400, in get_clusters
    kustomizations = await kustomization_traversal(path_selector)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/flux_local/git_repo.py", line 289, in kustomization_traversal
    path_queue.put(path_selector.relative_path)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/flux_local/git_repo.py", line 141, in relative_path
    return self.process_path.relative_to(self.root)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/python@3.11/3.11.2_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/pathlib.py", line 730, in relative_to
    raise ValueError("{!r} is not in the subpath of {!r}"
ValueError: '/var/folders/24/vvv5svzx1xb2q1qpsq8zc8bw0000gn/T/tmpgjrnx0em/k8s' is not in the subpath of '/private/var/folders/24/vvv5svzx1xb2q1qpsq8zc8bw0000gn/T/tmpgjrnx0em' OR one path is relative and the other is absolute.

[1] Under MacOS:

❯ ls -lsah /
total 10
 0 drwxr-xr-x   20 root  wheel   640B Jan 13 16:57 .
 0 drwxr-xr-x   20 root  wheel   640B Jan 13 16:57 ..
 <...>
 0 drwxr-xr-x    6 root  wheel   192B Feb 19 23:41 private
 0 lrwxr-xr-x@   1 root  wheel    11B Jan 13 16:57 tmp -> private/tmp
 0 lrwxr-xr-x@   1 root  wheel    11B Jan 13 16:57 var -> private/var
allenporter added a commit that referenced this issue Mar 18, 2023
Resolve the process and root paths when comparing so that any sym links
will be resolved. This allows paths to be compared against each other so
we can determine the relative path to process within the repo.

Fixes Issue #119
@allenporter
Copy link
Owner

Fixed in #129

@allenporter
Copy link
Owner

Thank you @kodek 👍🏼

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

No branches or pull requests

2 participants