From 5751569b5956dc6ac5fbefe78292a2abe8e92313 Mon Sep 17 00:00:00 2001 From: Andrew Bettison Date: Wed, 7 Nov 2012 20:29:12 +1030 Subject: [PATCH] Rhizome extract manifest to '-' writes to output Instead of specifying a file path, if the file is given as '-' then the content of the manifest is output in the 'manifest' key-value pair instead of written to a file. --- commandline.c | 11 ++++++++--- tests/rhizomeops | 33 ++++++++++++++++++++++++++++++++- 2 files changed, 40 insertions(+), 4 deletions(-) diff --git a/commandline.c b/commandline.c index 56924849..2b23e671 100644 --- a/commandline.c +++ b/commandline.c @@ -1260,11 +1260,16 @@ int app_rhizome_extract_manifest(int argc, const char *const *argv, struct comma switch (ret) { case 0: ret = 1; break; case 1: ret = 0; - if (manifestpath) { + if (manifestpath && strcmp(manifestpath, "-") == 0) { + cli_puts("manifest"); + cli_delim(":"); + cli_write(m->manifestdata, m->manifest_all_bytes); + cli_delim("\n"); + } else if (manifestpath) { /* If the manifest has been read in from database, the blob is there, and we can lie and say we are finalised and just want to write it - out. XXX really should have a dirty/clean flag, so that write - works is clean but not finalised. */ + out. TODO: really should have a dirty/clean flag, so that write + works if clean but not finalised. */ m->finalised=1; if (rhizome_write_manifest_file(m, manifestpath) == -1) ret = -1; diff --git a/tests/rhizomeops b/tests/rhizomeops index 5ed5af1e..741500d6 100755 --- a/tests/rhizomeops +++ b/tests/rhizomeops @@ -178,7 +178,6 @@ setup_ExtractManifestAfterAdd() { } test_ExtractManifestAfterAdd() { executeOk_servald rhizome extract manifest $manifestid file1x.manifest - assert cmp file1.manifest file1x.manifest assertStdoutLineCount '==' 8 local size=$(( $(cat file1 | wc -c) + 0 )) assertStdoutGrep --matches=1 "^service:file$" @@ -189,6 +188,38 @@ test_ExtractManifestAfterAdd() { assertStdoutGrep --matches=1 "^filesize:$size\$" assertStdoutGrep --matches=1 "^\.author:$SIDB1\$" assertStdoutGrep --matches=1 "^\.readonly:0\$" + assert cmp file1.manifest file1x.manifest +} + +doc_ExtractManifestToStdout="Extract manifest to output field" +setup_ExtractManifestToStdout() { + setup_servald + setup_rhizome + echo "A test file" >file1 + executeOk_servald rhizome add file $SIDB1 '' file1 file1.manifest + extract_manifest_id manifestid file1.manifest + extract_manifest_version version file1.manifest + extract_manifest_filehash filehash file1.manifest +} +test_ExtractManifestToStdout() { + executeOk_servald rhizome extract manifest $manifestid - + assertStdoutLineCount '>=' 9 + local size=$(( $(cat file1 | wc -c) + 0 )) + assertStdoutGrep --line=..8 --matches=1 "^service:file$" + assertStdoutGrep --line=..8 --matches=1 "^manifestid:$manifestid\$" + assertStdoutGrep --line=..8 --matches=1 "^version:$version\$" + assertStdoutGrep --line=..8 --matches=1 "^inserttime:$rexp_date\$" + assertStdoutGrep --line=..8 --matches=1 "^filehash:$filehash\$" + assertStdoutGrep --line=..8 --matches=1 "^filesize:$size\$" + assertStdoutGrep --line=..8 --matches=1 "^\.author:$SIDB1\$" + assertStdoutGrep --line=..8 --matches=1 "^\.readonly:0\$" + assertStdoutGrep --line=9 --matches=1 "^manifest:" + replayStdout | $SED -n '9s/^manifest://p' >file1x.manifest + replayStdout | $SED -n '10,$p' >>file1x.manifest + cat file1.manifest >file1n.manifest + echo >>file1n.manifest + tfw_cat file1n.manifest file1x.manifest + assert cmp file1n.manifest file1x.manifest } doc_ExtractManifestAfterAddNoAuthor="Extract manifest after one add with no author"