From 6db8f15d1c94b52f09ca8299251623ab09bf0cc1 Mon Sep 17 00:00:00 2001 From: Matthew Dillon Date: Sat, 16 Sep 2006 16:47:29 +0000 Subject: [PATCH] Fix a bug when '-f -H' is used and the target already exists. cpdup was copying the file in that case instead of hardlinking. --- bin/cpdup/cpdup.1 | 4 ++-- bin/cpdup/cpdup.c | 10 ++++++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/bin/cpdup/cpdup.1 b/bin/cpdup/cpdup.1 index 550ec41f45..2b4ad46e93 100644 --- a/bin/cpdup/cpdup.1 +++ b/bin/cpdup/cpdup.1 @@ -3,7 +3,7 @@ .\" USE WITH EXTREME CAUTION. .\" .\" -.\" $DragonFly: src/bin/cpdup/cpdup.1,v 1.16 2006/09/13 19:41:41 swildner Exp $ +.\" $DragonFly: src/bin/cpdup/cpdup.1,v 1.17 2006/09/16 16:47:29 dillon Exp $ .Dd October 28, 1999 .Dt CPDUP 1 .Os @@ -84,7 +84,7 @@ will cause cpdup to print a summary at the end with performance counter. Forces file updates to occur even if the files appear to be the same. If the .Fl H -option is used, this option will also force a byte for byte comparison +option is used, this option will force a byte for byte comparison between the original file and the file in the hardlink path, even if all the stat info matches, but will still use a hardlink if they match. .It Fl s0 diff --git a/bin/cpdup/cpdup.c b/bin/cpdup/cpdup.c index b10995421c..9f3422e0f0 100644 --- a/bin/cpdup/cpdup.c +++ b/bin/cpdup/cpdup.c @@ -45,7 +45,7 @@ * - Is able to do incremental mirroring/backups via hardlinks from * the 'previous' version (supplied with -H path). * - * $DragonFly: src/bin/cpdup/cpdup.c,v 1.16 2006/08/18 16:05:00 dillon Exp $ + * $DragonFly: src/bin/cpdup/cpdup.c,v 1.17 2006/09/16 16:47:29 dillon Exp $ */ /*- @@ -852,9 +852,15 @@ relink: /* * Not quite ready to do the copy yet. If UseHLPath is defined, * see if we can hardlink instead. + * + * If we can hardlink, and the target exists, we have to remove it + * first or the hardlink will fail. This can occur in a number of + * situations but must typically when the '-f -H' combination is + * used. */ - if (UseHLPath && (hpath = checkHLPath(&st1, spath, dpath)) != NULL) { + if (st2Valid) + hc_remove(&DstHost, dpath); if (hc_link(&DstHost, hpath, dpath) == 0) { if (VerboseOpt) { logstd("%-32s hardlinked(-H)\n", -- 2.41.0