Example #1
0
/* robustly move a file, creating new directory structures if necessary */
static int robust_move(const char *src, char *dst)
{
	if (robust_rename(src, dst, NULL, 0755) < 0
	 && (errno != ENOENT || make_bak_dir(dst) < 0
	  || robust_rename(src, dst, NULL, 0755) < 0))
		return -1;
	return 0;
}
Example #2
0
/* finish off a file transfer, renaming the file and setting the permissions
   and ownership */
void finish_transfer(char *fname, char *fnametmp, struct file_struct *file)
{
	if (make_backups && !make_backup(fname))
		return;

	/* move tmp file over real file */
	if (robust_rename(fnametmp,fname) != 0) {
		if (errno == EXDEV) {
			/* rename failed on cross-filesystem link.  
			   Copy the file instead. */
			if (copy_file(fnametmp,fname, file->mode & INITACCESSPERMS)) {
				rprintf(FERROR,"copy %s -> %s : %s\n",
					fnametmp,fname,strerror(errno));
			} else {
				set_perms(fname,file,NULL,0);
			}
		} else {
			rprintf(FERROR,"rename %s -> %s : %s\n",
				fnametmp,fname,strerror(errno));
		}
		do_unlink(fnametmp);
	} else {
		set_perms(fname,file,NULL,0);
	}
}
Example #3
0
/* robustly move a file, creating new directory structures if necessary */
static int robust_move(const char *src, char *dst)
{
	if (robust_rename(src, dst, NULL, 0755) < 0) {
		int save_errno = errno ? errno : EINVAL; /* 0 paranoia */
		if (errno == ENOENT && make_bak_dir(dst) == 0) {
			if (robust_rename(src, dst, NULL, 0755) < 0)
				save_errno = errno ? errno : save_errno;
			else
				save_errno = 0;
		}
		if (save_errno) {
			errno = save_errno;
			return -1;
		}
	}
	return 0;
}
Example #4
0
/* robustly move a file, creating new directory structures if necessary */
static int robust_move(char *src, char *dst)
{
	int keep_trying = 4;
	int keep_path_extfs = 0;
	int failed;

	while (keep_trying) {
		if (keep_path_extfs) {
			failed = copy_file(src, dst, 0755);
			if (!failed) {
				do_unlink(src);
			}
		} else {
			failed = robust_rename (src, dst);
		}

		if (failed) {
			if (verbose > 2)
				rprintf (FERROR, "robust_move failed: %s(%d)\n",
					strerror (errno), errno);
			switch (errno) {
				/* external filesystem */
				case EXDEV:
					keep_path_extfs = 1;
					keep_trying--;
					break;
				/* no directory to write to */
				case ENOENT:
					make_dir (dst, 0755);
					keep_trying--;
					break;
				default:
					keep_trying = 0;
			} /* switch */
		} else
			keep_trying = 0;
	} /* while */
	return (!failed);
} /* robust_move */