filesystem_spec
filesystem_spec copied to clipboard
`LocalFileSystem` clobbers file permissions after cp_file
Hi,
I am trying to copy a local file with the following permissions:
-rwxrwxr-x 1 rhorvath rhorvath 7994
after copying the file it becomes:
-rw-rw-r-- 1 rhorvath rhorvath 7994
I have narrowed the reason for this down to the cp_file function in LocalFileSystem where shutil.copyfile(path1, path2) doesn't copy the permission mode. This could be solved by using shutil.copy() and preserving the source file's permission mode.
could be solved by using shutil.copy() and preserving the source file's permission mode
Am I right in remembering that this does not do atomic operations, or that it operates differently across discs?
copyfile: "in the most efficient way possible" copy: "data and mode bits" (may copy into t directory, not to the specific path given)
This really should use shutil.copy2: https://docs.python.org/3/library/shutil.html#shutil.copy2
https://stackoverflow.com/questions/20873723/is-pythons-shutil-copyfile-atomic copyfile does not do atomic operations either so nothing will be lost. I think the issue you are worried about is the semantics if the destination path is a directory, but that can be handled with an isdir check.
Alternatively, if you really want to keep shutil.copyfile call, just add a copystat call as well.
shutil.copyfile and shutil.copy can both copy between disks, while the relevant os calls cannot.
can be handled with an isdir check
We would rather not add checks if possible - it turns out that things can go really slowly with bulk file operations.
Would you like to propose the PR?
This stackoverflow post gives a good behavior of what the different shutil calls do: https://stackoverflow.com/a/44996087