commit 9b2510924916cdc1e66d879b43f4dc953aac3c83 from: Stefan Sperling via: Thomas Adam date: Tue Nov 08 20:14:11 2022 UTC use sub-second precision when checking for objects/pack/ modification Convert from st.m_time (second-precision time_t) to st.m_tim (struct timespec). To compensate for the potential case where a filesystem provides resolution in seconds only, always read the directory if no pack files are known to exist. Otherwise, there is a race condition when gotd repo_write creates a new pack and a request arrives for repo_read shortly after. Caught by a regression test for gotd on empty repositories. Test failure pointed out by Mikhail. ok op@ commit - c22ed3f5d5d97db3f1d8fc8c649537c9033136f9 commit + 9b2510924916cdc1e66d879b43f4dc953aac3c83 blob - cd9aa4370a65e5d58169777bb0760f75b984b0b1 blob + e78dd4fb4cada73349067798a377d8d17194da2e --- gotd/privsep_stub.c +++ gotd/privsep_stub.c @@ -15,6 +15,7 @@ */ #include +#include #include #include #include blob - ced490e96ad476ac78d59ed49d235863982116c3 blob + b8032ffd3ffe9dab29beaf3cc57c39a6ef957859 --- lib/got_lib_repository.h +++ lib/got_lib_repository.h @@ -65,7 +65,7 @@ struct got_repository { int gitdir_fd; struct got_pathlist_head packidx_paths; - time_t pack_path_mtime; + struct timespec pack_path_mtime; /* The pack index cache speeds up search for packed objects. */ struct got_packidx *packidx_cache[GOT_PACK_CACHE_SIZE]; blob - 3c735047768978e048588c45a499263ce4d16e37 blob + 5522108b0b638af2088f27d7658bd2a3671def42 --- lib/read_gitconfig_privsep.c +++ lib/read_gitconfig_privsep.c @@ -14,6 +14,7 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#include #include #include #include blob - 59e3126a13e7972046e19f9dbdc2a29da4c031dd blob + b7acde6c731648b5e05261665578a19822deafd3 --- lib/repository.c +++ lib/repository.c @@ -1145,7 +1145,9 @@ refresh_packidx_paths(struct got_repository *repo) err = got_error_from_errno2("stat", objects_pack_dir); goto done; } - } else if (sb.st_mtime != repo->pack_path_mtime) { + } else if (TAILQ_EMPTY(&repo->packidx_paths) || + sb.st_mtim.tv_sec != repo->pack_path_mtime.tv_sec || + sb.st_mtim.tv_nsec != repo->pack_path_mtime.tv_nsec) { purge_packidx_paths(&repo->packidx_paths); err = got_repo_list_packidx(&repo->packidx_paths, repo); if (err) @@ -1272,7 +1274,8 @@ got_repo_list_packidx(struct got_pathlist_head *packid err = got_error_from_errno("fstat"); goto done; } - repo->pack_path_mtime = sb.st_mtime; + repo->pack_path_mtime.tv_sec = sb.st_mtim.tv_sec; + repo->pack_path_mtime.tv_nsec = sb.st_mtim.tv_nsec; while ((dent = readdir(packdir)) != NULL) { if (!got_repo_is_packidx_filename(dent->d_name,