From 56ca6f9bc7d0093cdf38289bd5f6a18e00224a4a Mon Sep 17 00:00:00 2001 From: Chris Dunlop Date: Sat, 17 Dec 2011 13:18:43 +1100 Subject: [PATCH] link-by-hash: checksum hash required when copying file link-by-hash requires the checksum hash when it's copying a file so that it can properly link into the link farm. In the absence of this patch I'm seeing it trying to link to the all-zeros hash name (perhaps if a previous file had carried a checksum the copy file would link to that previous checksum?). Signed-off-by: Chris Dunlop --- util.c | 16 ++++++++++++++++ 1 files changed, 16 insertions(+), 0 deletions(-) diff --git a/util.c b/util.c index ea9ca7d..7ea9487 100644 --- a/util.c +++ b/util.c @@ -31,9 +31,13 @@ extern int relative_paths; extern int preserve_times; extern int preserve_xattrs; extern int preallocate_files; +extern int checksum_len; +extern int checksum_seed; extern char *module_dir; extern unsigned int module_dirlen; extern char *partial_dir; +extern char *link_by_hash_dir; +extern char sender_file_sum[MAX_DIGEST_LEN]; extern filter_rule_list daemon_filter_list; int sanitize_paths = 0; @@ -322,6 +326,10 @@ int copy_file(const char *source, const char *dest, int ofd, mode_t mode) OFF_T preallocated_len = 0, offset = 0; #endif + if (link_by_hash_dir) { + sum_init(checksum_seed); + } + if ((ifd = do_open(source, O_RDONLY, 0)) < 0) { int save_errno = errno; rsyserr(FERROR_XFER, errno, "open %s", full_fname(source)); @@ -379,6 +387,9 @@ int copy_file(const char *source, const char *dest, int ofd, mode_t mode) errno = save_errno; return -1; } + if (link_by_hash_dir) { + sum_update(buf, len); + } #ifdef PREALLOCATE_NEEDS_TRUNCATE offset += len; #endif @@ -398,6 +409,11 @@ int copy_file(const char *source, const char *dest, int ofd, mode_t mode) full_fname(source)); } + if (link_by_hash_dir) { + if (sum_end(sender_file_sum) != checksum_len) + overflow_exit("checksum_len"); /* Impossible... */ + } + #ifdef PREALLOCATE_NEEDS_TRUNCATE /* Source file might have shrunk since we fstatted it. * Cut off any extra preallocated zeros from dest file. */ -- 1.7.0.4