Skip to content

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

Closed
@stone-w4tch3r

Description

@stone-w4tch3r

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

Metadata

Metadata

Assignees

Labels

bugLabel for all kind of bugs.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions