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

facts.files.File does not properly handle the ~ (relative) directory in Ubuntu/Debian #1025

Closed
stone-w4tch3r opened this issue Nov 6, 2023 · 4 comments · Fixed by #1175
Closed
Assignees
Labels
bug Label for all kind of bugs.

Comments

@stone-w4tch3r
Copy link
Contributor

Describe the bug

Addressing file via ~/file notation resolves to wrong path using facts.files.File, operations.files.file and so on

To Reproduce

  1. Spin up Ubuntu/Debian vm
  2. Create file test.txt in ~ directory
  3. Run main.py:
from pyinfra.facts import files
from pyinfra import host

relative_file = host.get_fact(files.File, '~/test.txt')
absolute_file = host.get_fact(files.File, '/home/ubuntu/test.txt')

print()
print()
print('+++\n' + str(relative_file) + '\n+++')
print('+++\n' + str(absolute_file) + '\n+++')
print()
  1. See output:
(...)
+++
None
+++
+++
{'user': 'ubuntu', 'group': 'ubuntu', 'mode': 664, 'atime': datetime.datetime(2023, 11, 6, 8, 5, 43), 'mtime': datetime.datetime(2023, 11, 6, 8, 5, 43), 'ctime': datetime.datetime(2023, 11, 6, 8, 5, 43), 'size': 0}
+++
(...)
  • Target system information
    Ubuntu 20.04.6 LTS (GNU/Linux 5.4.0-164-generic x86_64)
    Debian GNU/Linux 12 (bookworm) Linux 6.1.0-13-amd64 x86-64

Expected behavior

Explicit warning/error about using of ~ in path, or support for this notation

Meta

  • Include output of pyinfra --support.
pyinfra --support
--> Support information:

    If you are having issues with pyinfra or wish to make feature requests, please
    check out the GitHub issues at https://github.com/Fizzadar/pyinfra/issues .
    When adding an issue, be sure to include the following:

    System: Linux
      Platform: Linux-6.2.0-36-generic-x86_64-with-glibc2.37
      Release: 6.2.0-36-generic
      Machine: x86_64
    pyinfra: v2.8
    Executable: /home/user/Projects/Test/venv/bin/pyinfra
    Python: 3.11.4 (CPython, GCC 12.3.0)

  • How was pyinfra installed (source/pip)?
    pip
  • Include pyinfra-debug.log (if one was created)
    none
  • Consider including output with -vv and --debug.
    nothing special in verbose output
@stone-w4tch3r stone-w4tch3r added the bug Label for all kind of bugs. label Nov 6, 2023
@Fizzadar
Copy link
Member

Yeah this should work, it's a gotcha currently that it doesn't just work as one would expect.

@Fizzadar Fizzadar self-assigned this Nov 25, 2023
@simonhammes
Copy link
Contributor

simonhammes commented Aug 12, 2024

I believe this is caused by the fact that ~ is not expanded when wrapped inside quotes (does not matter if single or double quotes).

It might be a viable solution to check if the path starts with ~ and if it does, only quote the part after the tilde.

I'll try to create a PR later.

@Fizzadar Just saw that you assigned yourself, are you fine with me giving this a try?

@simonhammes
Copy link
Contributor

It seems like #1175 only fixed this issue for the File fact - file operations still seem to be broken :/

@simonhammes
Copy link
Contributor

It seems like #1175 only fixed this issue for the File fact - file operations still seem to be broken :/

I've opened #1235 to track this bug

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Label for all kind of bugs.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants