More consistent in error reporting for files with garbage at the end.

This commit is contained in:
Andrea Mazzoleni 2011-06-12 14:18:36 +02:00
parent 46fb4a311a
commit 8b3075a023
3 changed files with 21 additions and 13 deletions

View file

@ -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) {