static int enumerate_dir(Hashmap *top, Hashmap *bottom, const char *path) { _cleanup_closedir_ DIR *d; assert(top); assert(bottom); assert(path); d = opendir(path); if (!d) { if (errno == ENOENT) return 0; log_error("Failed to enumerate %s: %m", path); return -errno; } for (;;) { struct dirent *de; union dirent_storage buf; int k; char *p; k = readdir_r(d, &buf.de, &de); if (k != 0) return -k; if (!de) break; if (!dirent_is_file(de)) continue; p = strjoin(path, "/", de->d_name, NULL); if (!p) return -ENOMEM; path_kill_slashes(p); k = hashmap_put(top, path_get_file_name(p), p); if (k >= 0) { p = strdup(p); if (!p) return -ENOMEM; } else if (k != -EEXIST) { free(p); return k; } free(hashmap_remove(bottom, path_get_file_name(p))); k = hashmap_put(bottom, path_get_file_name(p), p); if (k < 0) { free(p); return k; } } return 0; }
HASHMAP_FOREACH(f, top, i) { char *o; o = hashmap_get(bottom, path_get_file_name(f)); assert(o); if (path_equal(o, f)) { notify_override_unchanged(f); continue; } k = found_override(f, o); if (k < 0) r = k; n_found ++; }
static int nftw_cb( const char *fpath, const struct stat *sb, int tflag, struct FTW *ftwbuf) { char *p, *e; int r; if (tflag != FTW_F) return 0; if (!endswith(fpath, ".map") && !endswith(fpath, ".map.gz")) return 0; p = strdup(path_get_file_name(fpath)); if (!p) return log_oom(); e = endswith(p, ".map"); if (e) *e = 0; e = endswith(p, ".map.gz"); if (e) *e = 0; r = set_put(keymaps, p); if (r == -EEXIST) free(p); else if (r < 0) { log_error("Can't add keymap: %s", strerror(-r)); free(p); return r; } return 0; }