summaryrefslogtreecommitdiff
path: root/backup.c
diff options
context:
space:
mode:
Diffstat (limited to 'backup.c')
-rw-r--r--backup.c32
1 files changed, 23 insertions, 9 deletions
diff --git a/backup.c b/backup.c
index a994e189..00e3e96d 100644
--- a/backup.c
+++ b/backup.c
@@ -55,23 +55,37 @@ char *get_backup_name(char *fname)
/* simple backup creates a backup with a suffix in the same directory */
static int make_simple_backup(char *fname)
{
+ int rename_errno;
char *fnamebak = get_backup_name(fname);
if (!fnamebak)
return 0;
- if (do_rename(fname, fnamebak) != 0) {
- /* cygwin (at least version b19) reports EINVAL */
- if (errno != ENOENT && errno != EINVAL) {
- rsyserr(FERROR, errno,
- "rename %s to backup %s",
- safe_fname(fname), safe_fname(fnamebak));
- return 0;
+ while (1) {
+ if (do_rename(fname, fnamebak) == 0) {
+ if (verbose > 1) {
+ rprintf(FINFO, "backed up %s to %s\n",
+ safe_fname(fname),
+ safe_fname(fnamebak));
+ }
+ break;
}
- } else if (verbose > 1) {
- rprintf(FINFO, "backed up %s to %s\n",
+ /* cygwin (at least version b19) reports EINVAL */
+ if (errno == ENOENT || errno == EINVAL)
+ break;
+
+ rename_errno = errno;
+ if (errno == EISDIR && do_rmdir(fnamebak) == 0)
+ continue;
+ if (errno == ENOTDIR && do_unlink(fnamebak) == 0)
+ continue;
+
+ rsyserr(FERROR, rename_errno, "rename %s to backup %s",
safe_fname(fname), safe_fname(fnamebak));
+ errno = rename_errno;
+ return 0;
}
+
return 1;
}