Fix thread error reporting.

Update error condition tests to not truncate archive.
This commit is contained in:
Moinak Ghosh 2012-11-25 15:12:45 +05:30
parent d250322490
commit deecbadac4
2 changed files with 34 additions and 3 deletions

11
main.c
View file

@ -91,7 +91,7 @@ static const char *algo = NULL;
static int do_compress = 0;
static int do_uncompress = 0;
static int cksum_bytes, mac_bytes;
static int cksum = 0;
static int cksum = 0, t_errored = 0;
static int rab_blk_size = 0;
static dedupe_context_t *rctx;
static crypto_ctx_t crypto_ctx;
@ -332,6 +332,7 @@ redo:
fprintf(stderr, "Chunk %d, HMAC verification failed\n", tdat->id);
main_cancel = 1;
tdat->len_cmp = 0;
t_errored = 1;
sem_post(&tdat->cmp_done_sem);
return;
}
@ -374,6 +375,7 @@ redo:
fprintf(stderr, "Chunk %d, Header CRC verification failed\n", tdat->id);
main_cancel = 1;
tdat->len_cmp = 0;
t_errored = 1;
sem_post(&tdat->cmp_done_sem);
return;
}
@ -412,6 +414,7 @@ redo:
if (rv == -1) {
tdat->len_cmp = 0;
fprintf(stderr, "ERROR: Chunk %d, decompression failed.\n", tdat->id);
t_errored = 1;
goto cont;
}
} else {
@ -446,6 +449,7 @@ redo:
if (rv == -1) {
tdat->len_cmp = 0;
fprintf(stderr, "ERROR: Chunk %d, decompression failed.\n", tdat->id);
t_errored = 1;
goto cont;
}
/* Rebuild chunk from dedup blocks. */
@ -461,6 +465,7 @@ redo:
fprintf(stderr, "ERROR: Chunk %d, dedup recovery failed.\n", tdat->id);
rv = -1;
tdat->len_cmp = 0;
t_errored = 1;
goto cont;
}
_chunksize = tdat->len_cmp;
@ -480,6 +485,7 @@ redo:
if (memcmp(checksum, tdat->checksum, cksum_bytes) != 0) {
tdat->len_cmp = 0;
fprintf(stderr, "ERROR: Chunk %d, checksums do not match.\n", tdat->id);
t_errored = 1;
}
}
@ -1010,6 +1016,7 @@ start_decompress(const char *filename, const char *to_filename)
thread = 0;
}
uncomp_done:
if (t_errored) err = t_errored;
if (thread) {
for (i = 0; i < nprocs; i++) {
tdat = dary[i];
@ -1203,6 +1210,7 @@ plain_compress:
*/
main_cancel = 1;
tdat->len_cmp = 0;
t_errored = 1;
sem_post(&tdat->cmp_done_sem);
return (0);
}
@ -1802,6 +1810,7 @@ start_compress(const char *filename, uint64_t chunksize, int level)
}
comp_done:
if (t_errored) err = t_errored;
if (thread) {
for (i = 0; i < nprocs; i++) {
tdat = dary[i];

View file

@ -35,6 +35,7 @@ done
for feat in "-S CRC64" "-S SKEIN256" "-S SKEIN512" "-S SHA256" "-S SHA512"
do
rm -f combined.dat.1.pz
rm -f combined.dat.pz
rm -f combined.dat.1
@ -49,7 +50,7 @@ do
fi
echo "Corrupting file header ..."
dd if=/dev/urandom of=combined.dat.pz bs=4 seek=1 count=1
dd if=/dev/urandom conv=notrunc of=combined.dat.pz bs=4 seek=1 count=1
cmd="../../pcompress -d combined.dat.pz combined.dat.1"
eval $cmd
if [ $? -eq 0 ]
@ -73,8 +74,9 @@ do
exit 1
fi
cp combined.dat.pz combined.dat.1.pz
echo "Corrupting file ..."
dd if=/dev/urandom of=combined.dat.pz bs=4 seek=100 count=1
dd if=/dev/urandom conv=notrunc of=combined.dat.pz bs=4 seek=100 count=1
cmd="../../pcompress -d combined.dat.pz combined.dat.1"
eval $cmd
if [ $? -eq 0 ]
@ -82,10 +84,30 @@ do
echo "${cmd} DID NOT ERROR where expected."
rm -f combined.dat.pz
rm -f combined.dat.1
rm -f combined.dat.1.pz
exit 1
fi
rm -f combined.dat.1
cp combined.dat.1.pz combined.dat.pz
echo "Corrupting file ..."
dd if=/dev/urandom conv=notrunc of=combined.dat.1.pz bs=4 seek=51 count=1
cmd="../../pcompress -d combined.dat.1.pz combined.dat.1"
eval $cmd
if [ $? -eq 0 ]
then
echo "${cmd} DID NOT ERROR where expected."
rm -f combined.dat.pz
rm -f combined.dat.1
rm -f combined.dat.1.pz
exit 1
fi
done
rm -f combined.dat.1.pz
rm -f combined.dat.pz
rm -f combined.dat.1
echo "#################################################"
echo ""