Rsync and write permissions at the target

permissionsrsync

I always wondered why rsync tries to transfer a file to a remote location where it has read/execute permissions for the target dir, but no write permissions to create the actual destination file. This can be simulated even locally when trying to copy a file as a regular user to /, rsync will transfer the whole file (also taking rather long for large files) and finally fails with

rsync: mkstemp "/.myTargetFile" failed: Permission denied (13)

So it already seems to fail at startup when trying to create the temporary file (the dot-file) during transfer. Why doesn't it notice this and aborts early instead of trying to copy the whole file without having any write permissions?

And where does it copy the file to if it can't create the temporary file? I can't see any memory increase of the rsync processes and also no corresponding file in /tmp. Seems like it directly discards the data at the destination but still keeps on with transferring.

Best Answer

If you need to copy into a directory without write permission, add --inplace to command options. This is sometimes cheaper that it doesn't create a temporary copy, but during updating the file is in inconsistent state.

On the question why it doesn't check own rights beforehand: it could miss some additional specifics as extended access ACLs, so rsync doesn't believe into standard 3*3+3 scheme. OTOH this intentional policy doesn't make any real difference in result - anyway file isn't updated.

Related Question