adding code to track if read error was on src or dest side
@@ -448,11 +448,15 @@ static int dcmp_compare_data(
off_t offset,
size_t length,
size_t buff_size,
- mfu_copy_opts_t* mfu_copy_opts)
+ mfu_copy_opts_t* mfu_copy_opts,
+ int* is_src_err)
{
/* open source file */
int src_fd = mfu_open(src_name, O_RDONLY);
if (src_fd < 0) {
+ if (src_fd < 0) {
+ *is_src_err = 1;
+ }
return -1;
}
@@ -474,6 +478,7 @@ static int dcmp_compare_data(
if (mfu_lseek(src_name, src_fd, offset, SEEK_SET) == (off_t)-1) {
mfu_close(dst_name, dst_fd);
mfu_close(src_name, src_fd);
+ *is_src_err = 1;
return -1;
}
@@ -513,7 +518,11 @@ 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 file/dir with is_src_err */
+ if (src_read < 0) {
+ *is_src_err = 1;
+ }
rc = -1;
break;
}
@@ -711,6 +720,11 @@ static void dcmp_strmap_compare_data(
int* ltr = (int*) MFU_MALLOC(list_count * sizeof(int));
int* rtl = (int*) MFU_MALLOC(list_count * sizeof(int));
+ /* var to keep track of whether or not the error was on the
+ * read or dest side, if it was the src then is_src_err
+ * will be equal to 1, and 0 means it was the dest dir/file */
+ int is_src_err = 0;
+
/* compare bytes for each file section and set flag based on what we find */
uint64_t i = 0;
char* name_ptr = keys;
@@ -725,15 +739,20 @@ static void dcmp_strmap_compare_data(
/* compare the contents of the files */
int rc = dcmp_compare_data(src_p->name, dst_p->name, offset,
- (size_t)length, 1048576, mfu_copy_opts);
+ (size_t)length, 1048576, mfu_copy_opts, &is_src_err);
if (rc == -1) {
/* we hit an error while reading, consider files to be different,
* they could be the same, but we'll draw attention to them this way */
rc = 1;
+ if (is_src_err) {
+ MFU_LOG(MFU_LOG_ERR,
+ "Failed to read %s. Asumming contents are different.", src_p->name);
+ } else {
MFU_LOG(MFU_LOG_ERR,
- "Failed to read %s and/or %s. Asumming contents are different.", src_p->name, dst_p->name);
+ "Failed to read %s. Asumming contents are different.", 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.");
