aboutsummaryrefslogtreecommitdiffstats
path: root/backup.c
diff options
context:
space:
mode:
authorWayne Davison <wayned@samba.org>2009-04-11 06:32:25 -0700
committerWayne Davison <wayned@samba.org>2009-04-11 06:37:49 -0700
commit5e2d51ee0675dc39d89c9ec11297a33c12b9181d (patch)
tree0417284ba6b8cee8f4f7a1ae26f46df96a0a8e33 /backup.c
parentd735fe20146bc4deedd0b23f3f489240ea9b5a7f (diff)
downloadandroid_external_rsync-5e2d51ee0675dc39d89c9ec11297a33c12b9181d.tar.gz
android_external_rsync-5e2d51ee0675dc39d89c9ec11297a33c12b9181d.tar.bz2
android_external_rsync-5e2d51ee0675dc39d89c9ec11297a33c12b9181d.zip
Fix "just in case" unlink. Prefer renaming of normal files
if hard-linking fails.
Diffstat (limited to 'backup.c')
-rw-r--r--backup.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/backup.c b/backup.c
index ed99ee93..5f860f78 100644
--- a/backup.c
+++ b/backup.c
@@ -155,18 +155,18 @@ static inline int link_or_rename(const char *from, const char *to,
if (IS_SPECIAL(stp->st_mode) || IS_DEVICE(stp->st_mode))
return 0; /* Use copy code. */
#endif
- if (!S_ISDIR(stp->st_mode)) {
- if (do_link(from, to) == 0)
- return 2;
+ if (do_link(from, to) == 0)
+ return 2;
+ /* We prefer to rename a regular file rather than copy it. */
+ if (!S_ISREG(stp->st_mode) || errno == EEXIST || errno == EISDIR)
return 0;
- }
}
#endif
if (do_rename(from, to) == 0) {
if (stp->st_nlink > 1 && !S_ISDIR(stp->st_mode)) {
/* If someone has hard-linked the file into the backup
* dir, rename() might return success but do nothing! */
- robust_unlink(to); /* Just in case... */
+ robust_unlink(from); /* Just in case... */
}
return 1;
}