mirror of
https://github.com/servalproject/serval-dna.git
synced 2025-04-09 12:01:15 +00:00
Tidy up rhizome extract return code
This commit is contained in:
parent
26a4034688
commit
898cddfcd3
@ -1277,18 +1277,13 @@ int app_rhizome_extract_file(int argc, const char *const *argv, const struct com
|
||||
return -1;
|
||||
if (rhizome_opendb() == -1)
|
||||
return -1;
|
||||
/* Extract the file from the database.
|
||||
We don't provide a decryption key here, because we don't know it.
|
||||
(We probably should allow the user to provide one).
|
||||
*/
|
||||
int ret = rhizome_retrieve_file(fileid, filepath, keyhex[0] ? key : NULL);
|
||||
switch (ret) {
|
||||
case 0: ret = 1; break;
|
||||
case 1: ret = 0; break;
|
||||
case -1: break;
|
||||
default: ret = WHYF("Unsupported return value %d", ret); break;
|
||||
/* Extract the file from the database. */
|
||||
if (!rhizome_exists(fileid)){
|
||||
return 1;
|
||||
}
|
||||
return ret;
|
||||
if (rhizome_retrieve_file(fileid, filepath, keyhex[0] ? key : NULL))
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int app_rhizome_list(int argc, const char *const *argv, const struct command_line_option *o, void *context)
|
||||
|
@ -1365,13 +1365,12 @@ int rhizome_retrieve_manifest(const char *manifestid, rhizome_manifest **mp)
|
||||
|
||||
/* Retrieve a file from the database, given its file hash.
|
||||
*
|
||||
* Returns 1 if file is found (contents are written to filepath if given).
|
||||
* Returns 0 if file is not found.
|
||||
* Returns 0 if file is valid, contents are written to filepath if given.
|
||||
* Returns -1 on error.
|
||||
*/
|
||||
int rhizome_retrieve_file(const char *fileid, const char *filepath, const unsigned char *key)
|
||||
{
|
||||
int ret;
|
||||
int ret=0;
|
||||
|
||||
if (rhizome_update_file_priority(fileid) == -1)
|
||||
return WHY("Failed to update file priority");
|
||||
@ -1381,7 +1380,7 @@ int rhizome_retrieve_file(const char *fileid, const char *filepath, const unsign
|
||||
|
||||
// for now, always hash the file
|
||||
if (rhizome_open_read(&read_state, fileid, 1))
|
||||
return 0;
|
||||
return -1;
|
||||
|
||||
int fd=-1;
|
||||
|
||||
@ -1416,7 +1415,6 @@ int rhizome_retrieve_file(const char *fileid, const char *filepath, const unsign
|
||||
cli_puts(read_state.id); cli_delim("\n");
|
||||
cli_puts("filesize"); cli_delim(":");
|
||||
cli_printf("%lld", read_state.length); cli_delim("\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
@ -358,7 +358,7 @@ int rhizome_open_read(struct rhizome_read *read, const char *fileid, int hash){
|
||||
|
||||
sqlite3_stmt *statement = sqlite_prepare(&retry, "SELECT FILEBLOBS.rowid FROM FILEBLOBS, FILES WHERE FILEBLOBS.id = FILES.id AND FILES.id = ? AND FILES.datavalid != 0");
|
||||
if (!statement)
|
||||
return -1;
|
||||
return WHYF("Failed to prepare statement: %s", sqlite3_errmsg(rhizome_db));
|
||||
|
||||
sqlite3_bind_text(statement, 1, read->id, -1, SQLITE_STATIC);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user