Skip to content

Commit

Permalink
rhizome_manifest_set_name_from_path()
Browse files Browse the repository at this point in the history
Refactor rhizome_fill_manifest() to use it
  • Loading branch information
quixotique committed Dec 30, 2013
1 parent 464f085 commit dd5048b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
1 change: 1 addition & 0 deletions rhizome.h
Expand Up @@ -494,6 +494,7 @@ int rhizome_remove_file_datainvalid(sqlite_retry_state *retry, const rhizome_fil
int rhizome_store_file(rhizome_manifest *m,const unsigned char *key);
int rhizome_bundle_import_files(rhizome_manifest *m, rhizome_manifest **m_out, const char *manifest_path, const char *filepath);

int rhizome_manifest_set_name_from_path(rhizome_manifest *m, const char *filepath);
int rhizome_fill_manifest(rhizome_manifest *m, const char *filepath, const sid_t *authorSidp);

int rhizome_apply_bundle_secret(rhizome_manifest *, const rhizome_bk_t *);
Expand Down
26 changes: 17 additions & 9 deletions rhizome_bundle.c
Expand Up @@ -1138,6 +1138,21 @@ enum rhizome_bundle_status rhizome_manifest_finalise(rhizome_manifest *m, rhizom
OUT();
}

/* Returns 1 if the name was successfully set, 0 if not.
*/
int rhizome_manifest_set_name_from_path(rhizome_manifest *m, const char *filepath)
{
const char *name = strrchr(filepath, '/');
if (!name)
name = filepath;
if (!rhizome_str_is_manifest_name(name)) {
WARNF("invalid rhizome name %s -- not used", alloca_str_toprint(name));
return 0;
}
rhizome_manifest_set_name(m, name);
return 1;
}

/* Fill in a few missing manifest fields, to make it easier to use when adding new files:
* - use the current time for "date" and "version"
* - use the given author SID, or the 'sender' if present, as the author
Expand Down Expand Up @@ -1190,15 +1205,8 @@ int rhizome_fill_manifest(rhizome_manifest *m, const char *filepath, const sid_t
if (m->name) {
if (config.debug.rhizome)
DEBUGF("manifest already contains name=%s", alloca_str_toprint(m->name));
} else if (filepath) {
const char *name = strrchr(filepath, '/');
if (!name)
name = filepath;
if (rhizome_str_is_manifest_name(name))
rhizome_manifest_set_name(m, name);
else if (config.debug.rhizome)
DEBUGF("invalid rhizome name %s -- not used", alloca_str_toprint(name));
}
} else if (filepath)
rhizome_manifest_set_name_from_path(m, filepath);
else if (config.debug.rhizome)
DEBUGF("manifest missing 'name'");
}
Expand Down

0 comments on commit dd5048b

Please sign in to comment.