If a file is missing or truncated, output the error message only on the first block
Some checks failed
Build / build-mac (push) Has been cancelled
Build / build-linux (push) Has been cancelled
Build / build-win (push) Has been cancelled
CodeQL Advanced / Analyze (c-cpp) (push) Has been cancelled
CodeQL Advanced / Analyze (actions) (push) Has been cancelled

This commit is contained in:
Andrea Mazzoleni 2026-01-27 00:07:41 +01:00
parent 6d6a975154
commit edcec26506
2 changed files with 17 additions and 2 deletions

View file

@ -1194,7 +1194,13 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna
}
/* read from the file */
read_size = handle_read(&handle[j], file_pos, buffer[j], state->block_size, log_error, state->opt.expected_missing ? log_expected : 0);
if (file_flag_has(file, FILE_IS_MISSING)) {
/* if the file is reported missing, don't even try to read it */
errno = ENOENT;
read_size = -1;
} else {
read_size = handle_read(&handle[j], file_pos, buffer[j], state->block_size, log_error, state->opt.expected_missing ? log_expected : 0);
}
if (read_size == -1) {
/* save the failed block for the check/fix */
failed[failed_count].is_bad = 1; /* it's bad because we cannot read it */
@ -1214,6 +1220,11 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna
} else {
++soft_error;
}
/* if we are reading at the end, mark the file as missing to avoid to try to read it again at the next block */
if (errno == ENOENT) {
file_flag_set(file, FILE_IS_MISSING);
}
continue;
}

View file

@ -253,7 +253,11 @@ int handle_read(struct snapraid_handle* handle, block_off_t file_pos, unsigned c
if (offset >= handle->valid_size) {
/* if the file is missing, it's at 0 size, or it's rebuilt while reading */
if (offset == handle->valid_size || handle->valid_size == 0) {
out_missing("Reading missing file '%s' at offset %" PRIu64 ".\n", handle->path, offset);
if (offset == 0) {
out_missing("Missing file '%s'.\n", handle->path);
} else {
out_missing("Missing data in file '%s' at offset %" PRIu64 ".\n", handle->path, offset);
}
errno = ENOENT;
} else {
out("Reading over the end from file '%s' at offset %" PRIu64 ".\n", handle->path, offset);