diff --git a/rhizome.h b/rhizome.h index a60ce8e9..d74efcfd 100644 --- a/rhizome.h +++ b/rhizome.h @@ -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 *); diff --git a/rhizome_bundle.c b/rhizome_bundle.c index f7ea4a64..6bc67145 100644 --- a/rhizome_bundle.c +++ b/rhizome_bundle.c @@ -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 @@ -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'"); }