mirror of
https://github.com/amadvance/snapraid.git
synced 2026-10-26 19:01:57 -04:00
More consistent in error reporting for files with garbage at the end.
This commit is contained in:
parent
46fb4a311a
commit
8b3075a023
3 changed files with 21 additions and 13 deletions
21
check.c
21
check.c
|
|
@ -278,7 +278,7 @@ static int state_check_process(struct snapraid_state* state, int fix, int parity
|
|||
}
|
||||
|
||||
/* keep track if at least one hashed block has no parity */
|
||||
/* if at least one block has no parity, doesn't make sense to check/fix it */
|
||||
/* if at least one block has no parity, doesn't make sense to check/fix the parity */
|
||||
/* as errors are the normal condition */
|
||||
if (!block_flag_has(block, BLOCK_HAS_PARITY))
|
||||
all_parity = 0;
|
||||
|
|
@ -305,11 +305,15 @@ static int state_check_process(struct snapraid_state* state, int fix, int parity
|
|||
goto bail;
|
||||
}
|
||||
|
||||
/* notify the warning condition of a file larger than expected */
|
||||
if (ret > 0) {
|
||||
error += ret;
|
||||
/* this is always a recovered error */
|
||||
recovered_error += ret;
|
||||
/* check if the file was larger and now truncated */
|
||||
if (ret == 1) {
|
||||
fprintf(stderr, "File '%s' is larger than expected.\n", handle[j].path);
|
||||
fprintf(stderr, "%u: Size error for file %s\n", i, block_file_get(block)->sub);
|
||||
++error;
|
||||
|
||||
/* this is already a recovered error */
|
||||
fprintf(stderr, "%u: Fixed size for file %s\n", i, block_file_get(block)->sub);
|
||||
++recovered_error;
|
||||
}
|
||||
} else {
|
||||
/* if checking, open the file for reading */
|
||||
|
|
@ -331,13 +335,12 @@ static int state_check_process(struct snapraid_state* state, int fix, int parity
|
|||
&& handle[j].st.st_size > block_file_get(block)->size
|
||||
) {
|
||||
fprintf(stderr, "File '%s' is larger than expected.\n", handle[j].path);
|
||||
fprintf(stderr, "%u: Size error for file %s\n", i, block_file_get(block)->sub);
|
||||
++error;
|
||||
|
||||
/* if fragmented, it may be reopened, so store the notification */
|
||||
/* to prevent to signal and count the error more than one time */
|
||||
file_flag_set(block_file_get(block), FILE_IS_LARGER);
|
||||
|
||||
/* this is always a recoverable error */
|
||||
++error;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
9
handle.c
9
handle.c
|
|
@ -177,9 +177,8 @@ int handle_create(struct snapraid_handle* handle, struct snapraid_file* file)
|
|||
}
|
||||
#endif
|
||||
|
||||
/* return the warning condition of a larger file */
|
||||
/* return if the file size was truncated */
|
||||
if (handle->st.st_size > file->size) {
|
||||
fprintf(stderr, "File '%s' truncated to size %"PRIu64".\n", handle->path, file->size);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
@ -272,10 +271,14 @@ int handle_read(struct snapraid_handle* handle, struct snapraid_block* block, un
|
|||
|
||||
read_ret = read(handle->f, block_buffer, read_size);
|
||||
#endif
|
||||
if (read_ret != (ssize_t)read_size) { /* conversion is safe because block_size is always small */
|
||||
if (read_ret < 0) {
|
||||
fprintf(stderr, "Error reading file '%s'. %s.\n", handle->path, strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
if (read_ret != (ssize_t)read_size) {
|
||||
fprintf(stderr, "File '%s' is smaller than expected.\n", handle->path);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* pad with 0 */
|
||||
if (read_size < block_size) {
|
||||
|
|
|
|||
4
handle.h
4
handle.h
|
|
@ -37,7 +37,9 @@ int handle_close_if_different(struct snapraid_handle* handle, struct snapraid_fi
|
|||
/**
|
||||
* Creates a file.
|
||||
* The file is created if missing, and opened with write access.
|
||||
* If the file is larger than expected, the value 1 is returned, and the file is truncated to the correct size.
|
||||
* If the file has a different size than expected, it's enlarged or truncated to the correct size.
|
||||
* If the file is truncated 1 is returned.
|
||||
* The initial size of the file is stored in the file->st struct.
|
||||
* If the file cannot be opened for write access, it's opened with read-only access.
|
||||
* The read-only access works only if the file has already the correct size and doesn't need to be modified.
|
||||
*/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue