commit 1af8800025bf22cf87cde038bbcfda0d2564eefc from: Stefan Sperling date: Sat Oct 22 20:01:46 2022 UTC refresh cached list of pack index paths while searching a packed object Previously, this list was only refreshed while trying to match an object ID prefix. Regular pack file access needs to refresh this list, too. In particular, future gotd(8) needs this to ensure that newly uploaded packfiles are picked up as expected. commit - 9316cc27bdc5db7db6927879f3c47b63f1c8ded2 commit + 1af8800025bf22cf87cde038bbcfda0d2564eefc blob - 4ce6727114c32c4380ae59715312588d87adc91b blob + c737a5e9ab0c0f7d5eaf7bd9936fd0f21b0edf45 --- lib/repository.c +++ lib/repository.c @@ -1032,6 +1032,46 @@ add_packidx_bloom_filter(struct got_repository *repo, RB_INSERT(got_packidx_bloom_filter_tree, &repo->packidx_bloom_filters, bf); return NULL; +} + +static void +purge_packidx_paths(struct got_pathlist_head *packidx_paths) +{ + struct got_pathlist_entry *pe; + + while (!TAILQ_EMPTY(packidx_paths)) { + pe = TAILQ_FIRST(packidx_paths); + TAILQ_REMOVE(packidx_paths, pe, entry); + free((char *)pe->path); + free(pe); + } +} + +static const struct got_error * +refresh_packidx_paths(struct got_repository *repo) +{ + const struct got_error *err = NULL; + char *objects_pack_dir = NULL; + struct stat sb; + + objects_pack_dir = got_repo_get_path_objects_pack(repo); + if (objects_pack_dir == NULL) + return got_error_from_errno("got_repo_get_path_objects_pack"); + + if (stat(objects_pack_dir, &sb) == -1) { + if (errno != ENOENT) { + err = got_error_from_errno2("stat", objects_pack_dir); + goto done; + } + } else if (sb.st_mtime != repo->pack_path_mtime) { + purge_packidx_paths(&repo->packidx_paths); + err = got_repo_list_packidx(&repo->packidx_paths, repo); + if (err) + goto done; + } +done: + free(objects_pack_dir); + return err; } const struct got_error * @@ -1071,6 +1111,10 @@ got_repo_search_packidx(struct got_packidx **packidx, } } /* No luck. Search the filesystem. */ + + err = refresh_packidx_paths(repo); + if (err) + return err; TAILQ_FOREACH(pe, &repo->packidx_paths, entry) { const char *path_packidx = pe->path; @@ -1465,46 +1509,19 @@ got_repo_init(const char *repo_path, const char *head_ return NULL; } -static void -purge_packidx_paths(struct got_pathlist_head *packidx_paths) -{ - struct got_pathlist_entry *pe; - - while (!TAILQ_EMPTY(packidx_paths)) { - pe = TAILQ_FIRST(packidx_paths); - TAILQ_REMOVE(packidx_paths, pe, entry); - free((char *)pe->path); - free(pe); - } -} - static const struct got_error * match_packed_object(struct got_object_id **unique_id, struct got_repository *repo, const char *id_str_prefix, int obj_type) { const struct got_error *err = NULL; - char *objects_pack_dir = NULL; struct got_object_id_queue matched_ids; struct got_pathlist_entry *pe; - struct stat sb; STAILQ_INIT(&matched_ids); - objects_pack_dir = got_repo_get_path_objects_pack(repo); - if (objects_pack_dir == NULL) - return got_error_from_errno("got_repo_get_path_objects_pack"); - - if (stat(objects_pack_dir, &sb) == -1) { - if (errno != ENOENT) { - err = got_error_from_errno2("stat", objects_pack_dir); - goto done; - } - } else if (sb.st_mtime != repo->pack_path_mtime) { - purge_packidx_paths(&repo->packidx_paths); - err = got_repo_list_packidx(&repo->packidx_paths, repo); - if (err) - goto done; - } + err = refresh_packidx_paths(repo); + if (err) + return err; TAILQ_FOREACH(pe, &repo->packidx_paths, entry) { const char *path_packidx = pe->path; @@ -1552,7 +1569,6 @@ match_packed_object(struct got_object_id **unique_id, } } done: - free(objects_pack_dir); got_object_id_queue_free(&matched_ids); if (err) { free(*unique_id);