mirror of
https://github.com/amadvance/snapraid.git
synced 2026-10-26 19:01:57 -04:00
Rechecks the hash of imported files before using them.
This commit is contained in:
parent
0ab9066a4f
commit
8c7332cfda
3 changed files with 16 additions and 2 deletions
4
TODO
4
TODO
|
|
@ -5,6 +5,10 @@ This is the list of TODO items for SnapRAID.
|
|||
|
||||
- v3.1
|
||||
|
||||
* In the import list, uses also all the blocks in the array.
|
||||
But we must cover the case of bad blocks. Likely we can just check the
|
||||
hash after reading, and in case, skip it, and retry with another copy.
|
||||
|
||||
* If a content file is missing, sync should rewrite it, even if no change was done at the content.
|
||||
|
||||
* A new 'init' command to differentiate the first 'sync' operation.
|
||||
|
|
|
|||
4
check.c
4
check.c
|
|
@ -275,11 +275,11 @@ static int repair(struct snapraid_state* state, unsigned pos, unsigned diskmax,
|
|||
}
|
||||
} else {
|
||||
assert(block_state == BLOCK_STATE_CHG || block_state == BLOCK_STATE_NEW);
|
||||
|
||||
|
||||
/* otherwise it's CHG or NEW and we try to recover it */
|
||||
failed_map[n] = j;
|
||||
++n;
|
||||
|
||||
|
||||
/* we have something to try to recover */
|
||||
something_to_recover = 1;
|
||||
}
|
||||
|
|
|
|||
10
import.c
10
import.c
|
|
@ -125,6 +125,7 @@ int state_import_fetch(struct snapraid_state* state, const unsigned char* hash,
|
|||
int f;
|
||||
unsigned block_size = state->block_size;
|
||||
unsigned read_size;
|
||||
unsigned char buffer_hash[HASH_SIZE];
|
||||
const char* path;
|
||||
|
||||
block = tommy_hashdyn_search(&state->importset, import_block_compare, hash, import_block_hash(hash));
|
||||
|
|
@ -162,6 +163,15 @@ int state_import_fetch(struct snapraid_state* state, const unsigned char* hash,
|
|||
memset(buffer + read_size, 0, block_size - read_size);
|
||||
}
|
||||
|
||||
/* recheck the hash */
|
||||
memhash(state->hash, buffer_hash, buffer, read_size);
|
||||
|
||||
if (memcmp(buffer_hash, hash, HASH_SIZE) != 0) {
|
||||
fprintf(stderr, "Error in data reading file '%s'.\n", path);
|
||||
fprintf(stderr, "Please don't change imported files while running.\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue