Rhizome extract commands handle missing pathnames properly

This commit is contained in:
Andrew Bettison 2012-05-25 11:52:49 +09:30
parent 26f3966002
commit 1af238a4f9
2 changed files with 20 additions and 19 deletions

View File

@ -1236,7 +1236,7 @@ int app_rhizome_extract_manifest(int argc, const char *const *argv, struct comma
{ {
const char *manifestid, *manifestpath; const char *manifestid, *manifestpath;
if (cli_arg(argc, argv, o, "manifestid", &manifestid, cli_manifestid, NULL) if (cli_arg(argc, argv, o, "manifestid", &manifestid, cli_manifestid, NULL)
|| cli_arg(argc, argv, o, "manifestpath", &manifestpath, NULL, "") == -1) || cli_arg(argc, argv, o, "manifestpath", &manifestpath, NULL, NULL) == -1)
return -1; return -1;
/* Ensure the Rhizome database exists and is open */ /* Ensure the Rhizome database exists and is open */
if (create_serval_instance_dir() == -1) if (create_serval_instance_dir() == -1)
@ -1249,14 +1249,14 @@ int app_rhizome_extract_manifest(int argc, const char *const *argv, struct comma
switch (ret) { switch (ret) {
case 0: ret = 1; break; case 0: ret = 1; break;
case 1: ret = 0; case 1: ret = 0;
if (manifestpath[0]) { if (manifestpath) {
/* If the manifest has been read in from database, the blob is there, /* 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 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 out. XXX really should have a dirty/clean flag, so that write
works is clean but not finalised. */ works is clean but not finalised. */
m->finalised=1; m->finalised=1;
if (rhizome_write_manifest_file(m, manifestpath) == -1) if (rhizome_write_manifest_file(m, manifestpath) == -1)
ret = WHY("Could not overwrite manifest file."); ret = -1;
} }
break; break;
case -1: break; case -1: break;

View File

@ -1066,6 +1066,12 @@ int rhizome_retrieve_file(const char *fileid, const char *filepath)
if (fileblobsize != length) if (fileblobsize != length)
ret = WHY("File length does not match blob size"); ret = WHY("File length does not match blob size");
else { else {
cli_puts("filehash"); cli_delim(":");
cli_puts((const char *)sqlite3_column_text(statement, 0)); cli_delim("\n");
cli_puts("filesize"); cli_delim(":");
cli_printf("%lld", length); cli_delim("\n");
ret = 1;
if (filepath) {
int fd = open(filepath, O_WRONLY | O_CREAT | O_TRUNC, 0775); int fd = open(filepath, O_WRONLY | O_CREAT | O_TRUNC, 0775);
if (fd == -1) { if (fd == -1) {
ret = WHYF("Cannot open %s for write/create", filepath); ret = WHYF("Cannot open %s for write/create", filepath);
@ -1076,12 +1082,7 @@ int rhizome_retrieve_file(const char *fileid, const char *filepath)
} else if (close(fd) == -1) { } else if (close(fd) == -1) {
ret = WHYF("Error flushing to %s ", filepath); ret = WHYF("Error flushing to %s ", filepath);
WHY_perror("close"); WHY_perror("close");
} else { }
ret = 1;
cli_puts("filehash"); cli_delim(":");
cli_puts((const char *)sqlite3_column_text(statement, 0)); cli_delim("\n");
cli_puts("filesize"); cli_delim(":");
cli_printf("%lld", length); cli_delim("\n");
} }
} }
break; break;