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.
This commit is contained in:
Andrew Bettison 2012-11-07 20:29:12 +10:30
parent b8de07679d
commit 5751569b59
2 changed files with 40 additions and 4 deletions

View File

@ -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;

View File

@ -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"