Permalink
Browse files

Merge pull request #88 from hpc/dcmp-reporting

adding code to track if read error was on src or dest side
  • Loading branch information...
dsikich committed Aug 28, 2017
2 parents 1bb5d0b + 455af2d commit 08d29e4593ce2556efbffcc540a9d89d3cca7da5
Showing with 34 additions and 4 deletions.
  1. +34 −4 src/dcmp/dcmp.c
View
@@ -453,12 +453,21 @@ static int dcmp_compare_data(
/* open source file */
int src_fd = mfu_open(src_name, O_RDONLY);
if (src_fd < 0) {
return -1;
/* log error if there is an open failure on the
* src side */
MFU_LOG(MFU_LOG_ERR, "Failed to open %s, error msg: %s",
src_name, strerror(errno));
mfu_close(src_name, src_fd);
return -1;
}
/* open destination file */
int dst_fd = mfu_open(dst_name, O_RDWR);
if (dst_fd < 0) {
/* log error if there is an open failure on the
* dst side */
MFU_LOG(MFU_LOG_ERR, "Failed to open %s, error msg: %s",
dst_name, strerror(errno));
mfu_close(src_name, src_fd);
return -1;
}
@@ -472,13 +481,21 @@ static int dcmp_compare_data(
/* seek to offset in source file */
if (mfu_lseek(src_name, src_fd, offset, SEEK_SET) == (off_t)-1) {
/* log error if there is an lseek failure on the
* src side */
MFU_LOG(MFU_LOG_ERR, "Failed to lseek %s, offset: %x, error msg: %s",
src_name, (unsigned long)offset, strerror(errno));
mfu_close(dst_name, dst_fd);
mfu_close(src_name, src_fd);
return -1;
}
/* seek to offset in destination file */
if(mfu_lseek(dst_name, dst_fd, offset, SEEK_SET) == (off_t)-1) {
/* log error if there is an lseek failure on the
* dst side */
MFU_LOG(MFU_LOG_ERR, "Failed to lseek %s, offset: %x, error msg: %s",
dst_name, (unsigned long)offset, strerror(errno));
mfu_close(dst_name, dst_fd);
mfu_close(src_name, src_fd);
return -1;
@@ -513,7 +530,19 @@ static int dcmp_compare_data(
/* check for read errors */
if (src_read < 0 || dst_read < 0) {
/* hit a read error */
/* hit a read error, now figure out if it was the
* src or dest, and print file */
if (src_read < 0) {
MFU_LOG(MFU_LOG_ERR, "Failed to read %s, error msg: %s",
src_name, strerror(errno));
}
/* added this extra check in case both are less
* than zero -- we'd want both files read
* errors reported */
if (dst_read < 0) {
MFU_LOG(MFU_LOG_ERR, "Failed to read %s, error msg: %s",
dst_name, strerror(errno));
}
rc = -1;
break;
}
@@ -731,9 +760,10 @@ static void dcmp_strmap_compare_data(
* they could be the same, but we'll draw attention to them this way */
rc = 1;
MFU_LOG(MFU_LOG_ERR,
"Failed to read %s and/or %s. Asumming contents are different.", src_p->name, dst_p->name);
"Failed to open, lseek, or read %s and/or %s. Assuming contents are different.",
src_p->name, dst_p->name);
/* consider this to a fatal error if syncing */
/* consider this to be a fatal error if syncing */
if (mfu_copy_opts->do_sync) {
/* TODO: fall back more gracefully here, e.g., delete dest and overwrite */
MFU_LOG(MFU_LOG_ERR, "Files not synced, aborting.");

0 comments on commit 08d29e4

Please sign in to comment.