pyinfra-dev / pyinfra

pyinfra turns Python code into shell commands and runs them on your servers. Execute ad-hoc commands and write declarative operations. Target SSH servers, local machine and Docker containers. Fast and scales from one server to thousands.
https://pyinfra.com
MIT License
3.91k stars 382 forks source link

`force_backup_dir` in files operations incorrectly combines full path + backup directory #786

Closed Fizzadar closed 2 years ago

Fizzadar commented 2 years ago

(from discord, cc @pylang)

Describe the bug

Using the new backup parameters in the link operation won't allow me to backup to a custom directory.

Problem if i'm linking a ~/dotfiles/.bashrc to ~ and pass in /my/custom/path/ to the new backup_dir param, something like this:

files.link("~/", "~/dotfiles/.bashrc", ..., True, True, "/my/custom/path/")

it errors saying "/my/custom/path//home/user/.bashrc doesn't exist."

Expected Since a .bashrc could already exist, i'd like to back it up and remove it from the destination prior to linking. I'd prefer to put all backups in a specific folder to declutter my homedir.

Solution (?) I think the backup_dir option should be appending the target stem (basename) instead of the full path.

Fizzadar commented 2 years ago

Now fixed in v2 (https://github.com/Fizzadar/pyinfra/commit/637d492c02c8666cd51dbe6e3535379f53eecf12) + v1.7.3 (https://github.com/Fizzadar/pyinfra/commit/f744418692ffc8d97a5d1dfbef07eb766f0bfa95)