On 16/01/2019 09:02, Lars wrote:
What is the most "atomic" way to move two files from a local disk to a server location? The meaning of atomic in this context means that either both files are moved or both files stay in original location. No intermediate files should be present once operation is finished.
When you detect that the source and target are on different filesystems, you should first perform a regular copy of the file to the target filesystem (using a different filename). Then perform the rename from this temporary file to the actual target filename. Usually you can put the temporary file in the same target directory but with a different file pattern that you know will not be observed by consuming directory watchers. If watchers might be looking for all files, then you may need to put temporary files in a different directory, as long as it's on the same filesystem. Using the same target directory also reduces the risk of permissions problems, although whatever installation process you use can require that the target directory and the temp directory have the same permissions, along with ensuring that they're suitably configured so your app can find them in the first place.