diff --git a/rhizome.c b/rhizome.c index 083cd581..6e48224e 100644 --- a/rhizome.c +++ b/rhizome.c @@ -109,6 +109,8 @@ int rhizome_fetch_delay_ms() * * - 'mout' must point to a manifest pointer which is updated to hold the constructed manifest. * + * - 'bid' must point to a supplied bundle id parameter, or NULL if none was supplied. + * * - 'bsk' must point to a supplied bundle secret parameter, or NULL if none was supplied. * * - 'author' must point to a supplied author parameter, or NULL if none was supplied. @@ -145,6 +147,7 @@ int rhizome_fetch_delay_ms() enum rhizome_add_file_result rhizome_manifest_add_file(int appending, rhizome_manifest *m, rhizome_manifest **mout, + const rhizome_bid_t *bid, const rhizome_bk_t *bsk, const sid_t *author, const char *file_path, @@ -161,14 +164,14 @@ enum rhizome_add_file_result rhizome_manifest_add_file(int appending, // Caller must not supply a malformed manifest (but an invalid one is okay because missing // fields will be filled in, so we don't check validity here). assert(!m->malformed); - if (m->has_id) { + if (bid) { if (config.debug.rhizome) - DEBUGF("Reading manifest from database: id=%s", alloca_tohex_rhizome_bid_t(m->cryptoSignPublic)); + DEBUGF("Reading manifest from database: id=%s", alloca_tohex_rhizome_bid_t(*bid)); if ((existing_manifest = rhizome_new_manifest()) == NULL) { WHY(cause = "Manifest struct could not be allocated"); goto error; } - enum rhizome_bundle_status status = rhizome_retrieve_manifest(&m->cryptoSignPublic, existing_manifest); + enum rhizome_bundle_status status = rhizome_retrieve_manifest(bid, existing_manifest); switch (status) { case RHIZOME_BUNDLE_STATUS_NEW: // No manifest with that bundle ID exists in the store, so we are building a bundle from diff --git a/rhizome.h b/rhizome.h index 28655940..00a8b799 100644 --- a/rhizome.h +++ b/rhizome.h @@ -463,6 +463,7 @@ enum rhizome_add_file_result { enum rhizome_add_file_result rhizome_manifest_add_file(int appending, rhizome_manifest *m, rhizome_manifest **mout, + const rhizome_bid_t *bid, const rhizome_bk_t *bsk, const sid_t *author, const char *file_path, diff --git a/rhizome_cli.c b/rhizome_cli.c index 1adc6f20..2e292a87 100644 --- a/rhizome_cli.c +++ b/rhizome_cli.c @@ -104,22 +104,22 @@ static int app_rhizome_hash_file(const struct cli_parsed *parsed, struct cli_con DEFINE_CMD(app_rhizome_add_file, 0, "Add a file to Rhizome and optionally write its manifest to the given path", - "rhizome","add","file" KEYRING_PIN_OPTIONS,"[--force-new]","","","[]","[]","..."); + "rhizome","add","file" KEYRING_PIN_OPTIONS,"[--bundle=]","[--force-new]","","","[]","[]","..."); DEFINE_CMD(app_rhizome_add_file, 0, "Append content to a journal bundle", - "rhizome", "journal", "append" KEYRING_PIN_OPTIONS, "", "", "", "[]"); + "rhizome", "journal", "append" KEYRING_PIN_OPTIONS, "", "", "", "[]"); static int app_rhizome_add_file(const struct cli_parsed *parsed, struct cli_context *context) { if (config.debug.verbose) DEBUG_cli_parsed(parsed); - const char *filepath, *manifestpath, *manifestIdHex, *authorSidHex, *bsktext; + const char *filepath, *manifestpath, *bundleIdHex, *authorSidHex, *bsktext; int force_new = 0 == cli_arg(parsed, "--force-new", NULL, NULL, NULL); cli_arg(parsed, "filepath", &filepath, NULL, ""); if (cli_arg(parsed, "author_sid", &authorSidHex, cli_optional_sid, "") == -1) return -1; cli_arg(parsed, "manifestpath", &manifestpath, NULL, ""); - cli_arg(parsed, "manifestid", &manifestIdHex, NULL, ""); + cli_arg(parsed, "--bundle", &bundleIdHex, cli_bid, "") == 0 || cli_arg(parsed, "bundleid", &bundleIdHex, cli_optional_bid, ""); if (cli_arg(parsed, "bsk", &bsktext, cli_optional_bundle_secret_key, NULL) == -1) return -1; @@ -130,10 +130,10 @@ static int app_rhizome_add_file(const struct cli_parsed *parsed, struct cli_cont return WHYF("invalid author_sid: %s", authorSidHex); rhizome_bid_t bid; - if (!manifestIdHex || !*manifestIdHex) - manifestIdHex = NULL; - else if (str_to_rhizome_bid_t(&bid, manifestIdHex) == -1) - return WHYF("Invalid bundle ID: %s", alloca_str_toprint(manifestIdHex)); + if (!bundleIdHex || !*bundleIdHex) + bundleIdHex = NULL; + else if (str_to_rhizome_bid_t(&bid, bundleIdHex) == -1) + return WHYF("Invalid bundle ID: %s", alloca_str_toprint(bundleIdHex)); rhizome_bk_t bsk; if (!bsktext || !*bsktext) @@ -184,7 +184,7 @@ static int app_rhizome_add_file(const struct cli_parsed *parsed, struct cli_cont if (rhizome_opendb() == -1) goto finish; - /* Create a manifest in memory that to accompany the added file. Initially the manifest is blank. + /* Create a manifest in memory that to describe the added file. Initially the manifest is blank. * If a manifest file is supplied, then read and parse it, barfing if it contains any duplicate * fields or invalid values. If it successfully parses, then overwrite it with any command-line * manifest field settings, overriding the values parsed from the file. Barf if any of these new @@ -204,23 +204,11 @@ static int app_rhizome_add_file(const struct cli_parsed *parsed, struct cli_cont } } - /* If a manifest ID (bundle ID) was supplied on the command line, first ensure it does not - * contradict any manifest ID present in the supplied manifest file, then insert it into the - * manifest. - */ - if (manifestIdHex) { - if (!m->has_id) - rhizome_manifest_set_id(m, &bid); - else if (cmp_rhizome_bid_t(&m->cryptoSignPublic, &bid) != 0) { - ret = WHYF("manifestid=%s does not match manifest id=%s", manifestIdHex, alloca_tohex_rhizome_bid_t(m->cryptoSignPublic)); - goto finish; - } - } - /* Create an in-memory manifest for the file being added. */ rhizome_manifest *mout = NULL; enum rhizome_add_file_result result = rhizome_manifest_add_file(appending, m, &mout, + bundleIdHex ? &bid : NULL, bsktext ? &bsk : NULL, authorSidHex ? &authorSid : NULL, filepath, diff --git a/rhizome_restful.c b/rhizome_restful.c index bb8a34e2..574d791f 100644 --- a/rhizome_restful.c +++ b/rhizome_restful.c @@ -403,6 +403,7 @@ static int insert_make_manifest(httpd_request *r) rhizome_manifest *mout = NULL; char message[150]; enum rhizome_add_file_result result = rhizome_manifest_add_file(r->u.insert.appending, r->manifest, &mout, + NULL, r->u.insert.received_secret ? &r->u.insert.bundle_secret : NULL, r->u.insert.received_author ? &r->u.insert.author: NULL, NULL, 0, NULL, strbuf_local(message, sizeof message)); diff --git a/tests/rhizomeops b/tests/rhizomeops index 600e0e9e..82b09d77 100755 --- a/tests/rhizomeops +++ b/tests/rhizomeops @@ -999,6 +999,26 @@ test_BroadcastNotEncrypted() { assert diff file1 file1y } +doc_AddReuseManifest="Add --bundle copies fields from existing manifest" +setup_AddReuseManifest() { + B_IDENTITY_COUNT=1 + setup_servald + setup_rhizome + echo "First content" >file1 + echo "Second content" >file1a + echo -e "service=wazoo\nunexpected=true\nrecipient=$SIDB1\nnothing=here" >file1.manifest + executeOk_servald rhizome add file $SIDA file1 file1.manifest + tfw_cat --stderr + extract_stdout_manifestid BID +} +test_AddReuseManifest() { + executeOk_servald rhizome add file --bundle=$BID $SIDA file1a file1a.manifest '' !nothing something=there + tfw_cat --stderr + assert_manifest_fields file1a.manifest service=wazoo unexpected=true recipient=$SIDB1 !nothing something=there + executeOk_servald rhizome export bundle $BID file1ax.manifest file1ax + assert diff file1a file1ax +} + doc_JournalAppend="Create and append to a journal" setup_JournalAppend() { setup_servald