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;
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;
/* Ensure the Rhizome database exists and is open */
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) {
case 0: ret = 1; break;
case 1: ret = 0;
if (manifestpath[0]) {
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. */
m->finalised=1;
if (rhizome_write_manifest_file(m, manifestpath) == -1)
ret = WHY("Could not overwrite manifest file.");
ret = -1;
}
break;
case -1: break;

View File

@ -1066,22 +1066,23 @@ int rhizome_retrieve_file(const char *fileid, const char *filepath)
if (fileblobsize != length)
ret = WHY("File length does not match blob size");
else {
int fd = open(filepath, O_WRONLY | O_CREAT | O_TRUNC, 0775);
if (fd == -1) {
ret = WHYF("Cannot open %s for write/create", filepath);
WHY_perror("open");
} else if (write(fd, fileblob, length) != length) {
ret = WHYF("Error writing %lld bytes to %s ", (long long) length, filepath);
WHY_perror("write");
} else if (close(fd) == -1) {
ret = WHYF("Error flushing to %s ", filepath);
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");
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);
if (fd == -1) {
ret = WHYF("Cannot open %s for write/create", filepath);
WHY_perror("open");
} else if (write(fd, fileblob, length) != length) {
ret = WHYF("Error writing %lld bytes to %s ", (long long) length, filepath);
WHY_perror("write");
} else if (close(fd) == -1) {
ret = WHYF("Error flushing to %s ", filepath);
WHY_perror("close");
}
}
}
break;