Esempio n. 1
0
int catalog_update(const char* database, const char* root, const char* const* dirs) {
        _cleanup_strv_free_ char **files = NULL;
        char **f;
        struct strbuf *sb = NULL;
        _cleanup_hashmap_free_free_ Hashmap *h = NULL;
        _cleanup_free_ CatalogItem *items = NULL;
        CatalogItem *i;
        Iterator j;
        unsigned n;
        long r;

        h = hashmap_new(catalog_hash_func, catalog_compare_func);
        sb = strbuf_new();

        if (!h || !sb) {
                r = log_oom();
                goto finish;
        }

        r = conf_files_list_strv(&files, ".catalog", root, dirs);
        if (r < 0) {
                log_error("Failed to get catalog files: %s", strerror(-r));
                goto finish;
        }

        STRV_FOREACH(f, files) {
                log_debug("Reading file '%s'", *f);
                r = catalog_import_file(h, sb, *f);
                if (r < 0) {
                        log_error("Failed to import file '%s': %s.",
                                  *f, strerror(-r));
                        goto finish;
                }
        }
Esempio n. 2
0
static void test_import(Hashmap *h, struct strbuf *sb,
                        const char* contents, ssize_t size, int code) {
        int r;
        char name[] = "/tmp/test-catalog.XXXXXX";
        _cleanup_close_ int fd = mkstemp(name);
        assert(fd >= 0);
        assert_se(write(fd, contents, size) == size);

        r = catalog_import_file(h, sb, name);
        assert(r == code);

        unlink(name);
}
Esempio n. 3
0
static Hashmap * test_import(const char* contents, ssize_t size, int code) {
        int r;
        char name[] = "/tmp/test-catalog.XXXXXX";
        _cleanup_close_ int fd;
        Hashmap *h;

        if (size < 0)
                size = strlen(contents);

        assert_se(h = hashmap_new(&catalog_hash_ops));

        fd = mkostemp_safe(name, O_RDWR|O_CLOEXEC);
        assert_se(fd >= 0);
        assert_se(write(fd, contents, size) == size);

        r = catalog_import_file(h, name);
        assert_se(r == code);

        unlink(name);

        return h;
}