Fix bug in output from "rhizome add file"

When a duplicate is detected, the 'manifestid' field must contain the public
key of the existing manifest.
This commit is contained in:
Andrew Bettison 2012-05-04 15:59:58 +09:30
parent f31c326871
commit 97884ba069
3 changed files with 10 additions and 4 deletions

View File

@ -1014,17 +1014,19 @@ int app_rhizome_add_file(int argc, const char *const *argv, struct command_line_
); );
if (ret == -1) if (ret == -1)
return WHY("Manifest not added to Rhizome database"); return WHY("Manifest not added to Rhizome database");
if (!(ret == 0 || ret == 2))
return WHYF("Unexpected return value ret=%d", ret);
/* If successfully added, overwrite the manifest file so that the Java component that is /* If successfully added, overwrite the manifest file so that the Java component that is
invoking this command can read it to obtain feedback on the result. */ invoking this command can read it to obtain feedback on the result. */
if (manifestpath[0] && rhizome_write_manifest_file(mout, manifestpath) == -1) if (manifestpath[0] && rhizome_write_manifest_file(mout, manifestpath) == -1)
ret = WHY("Could not overwrite manifest file."); ret = WHY("Could not overwrite manifest file.");
cli_puts("manifestid"); cli_delim(":"); cli_puts("manifestid"); cli_delim(":");
cli_puts(rhizome_bytes_to_hex(m->cryptoSignPublic, crypto_sign_edwards25519sha512batch_PUBLICKEYBYTES)); cli_delim("\n"); cli_puts(rhizome_bytes_to_hex(mout->cryptoSignPublic, crypto_sign_edwards25519sha512batch_PUBLICKEYBYTES)); cli_delim("\n");
cli_puts("filehash"); cli_delim(":"); cli_puts("filehash"); cli_delim(":");
cli_puts(m->fileHexHash); cli_delim("\n"); cli_puts(mout->fileHexHash); cli_delim("\n");
cli_puts("filesize"); cli_delim(":"); cli_puts("filesize"); cli_delim(":");
cli_printf("%lld", m->fileLength); cli_delim("\n"); cli_printf("%lld", mout->fileLength); cli_delim("\n");
const char *name = rhizome_manifest_get(m, "name", NULL, 0); const char *name = rhizome_manifest_get(mout, "name", NULL, 0);
if (name) { if (name) {
cli_puts("name"); cli_delim(":"); cli_puts("name"); cli_delim(":");
cli_puts(name); cli_delim("\n"); cli_puts(name); cli_delim("\n");

View File

@ -824,6 +824,7 @@ int rhizome_find_duplicate(const rhizome_manifest *m, rhizome_manifest **found)
&& (lengthq == -1 || lengthq == m->fileLength) && (lengthq == -1 || lengthq == m->fileLength)
&& (!filehashq || strncmp(filehashq, m->fileHexHash, SHA512_DIGEST_STRING_LENGTH) == 0) && (!filehashq || strncmp(filehashq, m->fileHexHash, SHA512_DIGEST_STRING_LENGTH) == 0)
) { ) {
rhizome_hex_to_bytes(manifestid, mq->cryptoSignPublic, crypto_sign_edwards25519sha512batch_PUBLICKEYBYTES*2);
memcpy(mq->fileHexHash, m->fileHexHash, SHA512_DIGEST_STRING_LENGTH); memcpy(mq->fileHexHash, m->fileHexHash, SHA512_DIGEST_STRING_LENGTH);
mq->fileHashedP = 1; mq->fileHashedP = 1;
mq->fileLength = m->fileLength; mq->fileLength = m->fileLength;

View File

@ -302,12 +302,14 @@ test_AddDuplicate() {
# on stderr). # on stderr).
execute --exit-status=2 $dna rhizome add file file1 file1.manifestA execute --exit-status=2 $dna rhizome add file file1 file1.manifestA
assert [ -s file1.manifestA ] assert [ -s file1.manifestA ]
assert_stdout_add_file file1
assert_rhizome_list file1 file2 assert_rhizome_list file1 file2
strip_signatures file1.manifest file1.manifestA strip_signatures file1.manifest file1.manifestA
assert diff file1.manifest file1.manifestA assert diff file1.manifest file1.manifestA
# Repeat for second file. # Repeat for second file.
execute --exit-status=2 $dna rhizome add file file2 file2.manifestA execute --exit-status=2 $dna rhizome add file file2 file2.manifestA
assert [ -s file2.manifestA ] assert [ -s file2.manifestA ]
assert_stdout_add_file file2
assert_rhizome_list file1 file2 assert_rhizome_list file1 file2
strip_signatures file2.manifest file2.manifestA strip_signatures file2.manifest file2.manifestA
assert diff file2.manifest file2.manifestA assert diff file2.manifest file2.manifestA
@ -361,6 +363,7 @@ setup_AddUpdateNewVersion() {
test_AddUpdateNewVersion() { test_AddUpdateNewVersion() {
tfw_cat -v file1_2.manifest tfw_cat -v file1_2.manifest
executeOk $dna rhizome add file file1_2 file1_2.manifest executeOk $dna rhizome add file file1_2 file1_2.manifest
assert_stdout_add_file file1_2 file1
assert_manifest_newer file1.manifest file1_2.manifest assert_manifest_newer file1.manifest file1_2.manifest
# Rhizome store contents reflect new payload. # Rhizome store contents reflect new payload.
mv -f file1_2.manifest file1.manifest mv -f file1_2.manifest file1.manifest