Pyinfra: files.sync() does not preserve original file mode.

Created on 8 May 2021  路  5Comments  路  Source: Fizzadar/pyinfra

Describe the bug

Some of my uploaded directories contain code files in mode 750 (-rwx-r-x----), they are being re-mode to 664 (rw-rw-r--). I suspect files.sync() is not checking the original mode of the file on host machine.

Seems like mode is only applied if it is supplied explicitly: https://github.com/Fizzadar/pyinfra/blob/e150ddb4794044418aeabb7d49c8e0ce265163a5/pyinfra/operations/files.py#L695

Expected behavior

files.sync() should preserve the original mode from the host. Otherwise unintentional permission breakage will ensue.

Bug

All 5 comments

Not such a big deal for file.put(), but for file.sync() I think it's reasonable to expect mode consistency. Would be nice for file.put() too, though.

I'm definitely considering this a bug in files.sync, as you say could lead to some sketchy permissions issues for sure!

Will have a think about files.put, there's also files.get which should really replicate in reverse. Quite like the explicit-ness of passing mode= there.

Will have a think about files.put, there's also files.get which should really replicate in reverse. Quite like the explicit-ness of passing mode= there.

Agreed. Honestly not a high priority compared to files.sync()

Now fixed/implemented for files.sync in https://github.com/Fizzadar/pyinfra/commit/40377d98b43aa041661676a1c1e0a58675d46636 and released in v1.4.1! I've added https://github.com/Fizzadar/pyinfra/issues/590 to track potential implementation for files.put/files.get.

Thanks @Fizzadar, works perfectly.

Was this page helpful?
0 / 5 - 0 ratings