MCPcopy Index your code
hub / github.com/RsyncProject/rsync / open_tmpfile

Function open_tmpfile

receiver.c:256–303  ·  view source on GitHub ↗

Opens a temporary file for writing. * Success: Writes name into fnametmp, returns fd. * Failure: Clobbers fnametmp, returns -1. * Calling cleanup_set() is the caller's job. */

Source from the content-addressed store, hash-verified

254 * Failure: Clobbers fnametmp, returns -1.
255 * Calling cleanup_set() is the caller's job. */
256int open_tmpfile(char *fnametmp, const char *fname, struct file_struct *file)
257{
258 int fd;
259 mode_t added_perms;
260
261 if (!get_tmpname(fnametmp, fname, False))
262 return -1;
263
264 if (am_root < 0) {
265 /* For --fake-super, the file must be useable by the copying
266 * user, just like it would be for root. */
267 added_perms = S_IRUSR|S_IWUSR;
268 } else {
269 /* For a normal copy, we need to be able to tweak things like xattrs. */
270 added_perms = S_IWUSR;
271 }
272
273 /* We initially set the perms without the setuid/setgid bits or group
274 * access to ensure that there is no race condition. They will be
275 * correctly updated after the right owner and group info is set.
276 * (Thanks to snabb@epipe.fi for pointing this out.) */
277 /* When use_secure_symlinks is on (non-chroot daemon with munge_symlinks),
278 * use secure_mkstemp to prevent symlink race attacks on parent directories. */
279 if (use_secure_symlinks)
280 fd = secure_mkstemp(fnametmp, (file->mode|added_perms) & INITACCESSPERMS);
281 else
282 fd = do_mkstemp(fnametmp, (file->mode|added_perms) & INITACCESSPERMS);
283
284#if 0
285 /* In most cases parent directories will already exist because their
286 * information should have been previously transferred, but that may
287 * not be the case with -R */
288 if (fd == -1 && relative_paths && errno == ENOENT
289 && make_path(fnametmp, MKP_SKIP_SLASH | MKP_DROP_NAME) == 0) {
290 /* Get back to name with XXXXXX in it. */
291 get_tmpname(fnametmp, fname, False);
292 fd = do_mkstemp(fnametmp, (file->mode|added_perms) & INITACCESSPERMS);
293 }
294#endif
295
296 if (fd == -1) {
297 rsyserr(FERROR_XFER, errno, "mkstemp %s failed",
298 full_fname(fnametmp));
299 return -1;
300 }
301
302 return fd;
303}
304
305static int receive_data(int f_in, char *fname_r, int fd_r, OFF_T size_r,
306 const char *fname, int fd, struct file_struct *file, int inplace_sizing)

Callers 2

copy_altdest_fileFunction · 0.85
recv_filesFunction · 0.85

Calls 6

get_tmpnameFunction · 0.85
secure_mkstempFunction · 0.85
do_mkstempFunction · 0.85
make_pathFunction · 0.85
full_fnameFunction · 0.85
rsyserrFunction · 0.70

Tested by

no test coverage detected