Skip to content

Commit

Permalink
Fix "just in case" unlink. Prefer renaming of normal files
Browse files Browse the repository at this point in the history
if hard-linking fails.
  • Loading branch information
Wayne Davison committed Apr 11, 2009
1 parent d735fe2 commit 5e2d51e
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions backup.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 5e2d51e

Please sign in to comment.