#include "string-util.h"
#include "sysupdate-config.h"
#include "sysupdate-feature.h"
+#include "sysupdate-util.h"
static Feature *feature_free(Feature *f) {
if (!f)
Feature, feature_unref);
int feature_read_definition(Feature *f, const char *root, const char *path, const char *const *dirs) {
+ int r;
+
assert(f);
+ assert(path);
+ assert(dirs);
+
+ _cleanup_free_ char *filename = NULL;
+ r = path_extract_filename(path, &filename);
+ if (r < 0)
+ return log_error_errno(r, "Failed to extract filename from path '%s': %m", path);
+
+ char *e = endswith(filename, ".feature");
+ if (!e)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Feature file has bad suffix: %s", filename);
+
+ _cleanup_free_ char *id = strndup(filename, e - filename);
+ if (!id)
+ return log_oom();
+
+ if (!feature_name_valid(id))
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Malformed feature filename '%s': %m", filename);
ConfigTableItem table[] = {
{ "Feature", "Description", config_parse_string, 0, &f->description },
{}
};
- _cleanup_free_ char *filename = NULL;
- int r;
-
- assert(path);
- assert(dirs);
-
- r = path_extract_filename(path, &filename);
- if (r < 0)
- return log_error_errno(r, "Failed to extract filename from path '%s': %m", path);
-
r = config_parse_many_full(
STRV_MAKE_CONST(path),
dirs,
if (r < 0)
return r;
- *ASSERT_PTR(endswith(filename, ".feature")) = 0; /* Remove the file extension */
- f->id = TAKE_PTR(filename);
+ f->id = TAKE_PTR(id);
return 0;
}