pyinfra
pyinfra copied to clipboard
files.block is not working as expected when path exists and line missing
files.block is not working as expected
Describe the bug
The document (both 2x and next) says:
Content appended if line not found in the file
If content is not in the file but is required (present=True) and line is not found in the file, content (surrounded by markers) will be appended to the file. The file is created if necessary.
But in the case of the actual empty file, there is no addition.
To Reproduce
Steps to reproduce the behavior, please include where possible:
from pyinfra.operations import files
files.block(
name="Block Test",
path="test.txt",
line="foo",
content="bar",
present=True,
after=True,
)
$ rm test.txt
$ touch test.txt
$ pyinfra @local test.py
$ cat test.txt #just empty line
Expected behavior
$ cat test.txt
# BEGIN PYINFRA BLOCK
bar
# END PYINFRA BLOCK
Meta
- Include output of
pyinfra --support
.
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: Darwin
Platform: macOS-14.0-x86_64-i386-64bit
Release: 23.0.0
Machine: x86_64
pyinfra: v3.0b0
Executable: /Users/who/OneClick/LunaticDaemon/.venv/bin/pyinfra
Python: 3.11.7 (CPython, Clang 15.0.0 (clang-1500.1.0.2.5))
- How was pyinfra installed (source/pip)?
pip
- Include pyinfra-debug.log (if one was created)
None
- Consider including output with
-vv
and--debug
.