Reinstate filesize and hash file extract output

This commit is contained in:
Jeremy Lakeman 2013-01-04 11:02:24 +10:30
parent fd96c5bd76
commit 2b480c1d1a
4 changed files with 24 additions and 6 deletions

View File

@ -1324,14 +1324,28 @@ int app_rhizome_extract_file(int argc, const char *const *argv, const struct com
ret = rhizome_extract_file(m, filepath, bskhex?&bsk:NULL);
}
if (ret==0){
cli_puts("filehash"); cli_delim(":");
cli_puts(m->fileHexHash); cli_delim("\n");
cli_puts("filesize"); cli_delim(":");
cli_printf("%lld", m->fileLength); cli_delim("\n");
}
if (m)
rhizome_manifest_free(m);
}else if(fileid){
if (!rhizome_exists(fileid))
return 1;
int64_t length;
ret = rhizome_dump_file(fileid, filepath, &length);
ret = rhizome_dump_file(fileid, filepath);
if (ret==0){
cli_puts("filehash"); cli_delim(":");
cli_puts(fileid); cli_delim("\n");
cli_puts("filesize"); cli_delim(":");
cli_printf("%lld", length); cli_delim("\n");
}
}
return ret;

View File

@ -650,6 +650,6 @@ int rhizome_crypt_xor_block(unsigned char *buffer, int buffer_size, int64_t stre
int rhizome_open_read(struct rhizome_read *read, const char *fileid, int hash);
int rhizome_read(struct rhizome_read *read, unsigned char *buffer, int buffer_length);
int rhizome_extract_file(rhizome_manifest *m, const char *filepath, rhizome_bk_t *bsk);
int rhizome_dump_file(const char *id, const char *filepath);
int rhizome_dump_file(const char *id, const char *filepath, int64_t *length);
#endif //__SERVALDNA__RHIZOME_H

View File

@ -523,12 +523,15 @@ int rhizome_extract_file(rhizome_manifest *m, const char *filepath, rhizome_bk_t
}
/* dump the raw contents of a file */
int rhizome_dump_file(const char *id, const char *filepath){
int rhizome_dump_file(const char *id, const char *filepath, int64_t *length){
struct rhizome_read read_state;
bzero(&read_state, sizeof read_state);
if (rhizome_open_read(&read_state, id, 1))
return -1;
if (length)
*length = read_state.length;
return write_file(&read_state, filepath);
}

7
tests/rhizomeops Executable file → Normal file
View File

@ -302,15 +302,16 @@ setup_ExtractFileAfterAdd() {
executeOk_servald rhizome list ''
assert_rhizome_list --fromhere=1 --author=$SIDB1 file1
extract_manifest_id BID file1.manifest
extract_manifest_filehash filehash file1.manifest
}
test_ExtractFileAfterAdd() {
executeOk_servald rhizome extract file $BID file1x
tfw_cat --stderr
assert cmp file1 file1x
local size=$(( $(cat file1 | wc -c) + 0 ))
assertStdoutLineCount '==' 0
# assertStdoutGrep --matches=1 "^filehash:$filehash$"
# assertStdoutGrep --matches=1 "^filesize:$size$"
assertStdoutLineCount '==' 2
assertStdoutGrep --matches=1 "^filehash:$filehash$"
assertStdoutGrep --matches=1 "^filesize:$size$"
}
doc_ExtractFileMissing="Extract non-existent file"