4

I am having difficulties finding how Rsync "chooses" the extension for the temporary file created while copying the file if I don't use the --inplace option.

Example : I want to copy sourceDirectory/myFile.txt into targetDirectory/ with Rsync.

While copying myFile.txt into targetDirectory/ Rsync will create a file named .myFile.txt.W4zvLi in targetDirectory/.

Then Rsync will rename .myFile.txt.W4zvLi into myFile.txt.

The question is how why Rsync uses the W4zvLi extension and why it seems to change each time I execute the Rsync program?

2 Answers 2

5

rsync uses the mktemp(3) POSIX function to generate a unique temporary file name. You pass a template string to the mktemp function, and it will return a file name with any X characters in the template replaced by a random character.

In particular, rsync passes .XXXXXX to mktemp. If you want to try it out from the command line you can use the mktemp(1) binary like so:

mktemp -u "/tmp/foo.XXXXXX"
1
  • Exactly what I was searching for Commented Nov 7, 2016 at 15:12
0

man rsync:

Beginning with rsync 3.1.1, the  temp-file  names  inside
              the specified DIR will not be prefixed with an extra dot (though
              they will still have a random suffix added).
4
  • Explaining that the extension is chosen randomly might be a good idea.
    – terdon
    Commented Nov 7, 2016 at 14:07
  • Any clue about how the "random" suffix is calculated? Commented Nov 7, 2016 at 14:08
  • The clue is in the source of rsync and kernel. Commented Nov 7, 2016 at 14:12
  • The man quote refers to the specific case when temp files are created in a temp-dir specifed by the -T --temp-dir option. The default behavior seems to be unchanged in 3.1.1: temporary files starts with a dot in the same directory as the target file. Commented May 6, 2020 at 8:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .