commit ff563a3de3ff9931c2702516c74c8aea8d5cf142 from: Stefan Sperling date: Thu May 23 19:04:23 2019 UTC replace got_pack_get_packfile_size() with simple fstat() commit - fa6e0e48ed35f3686bde7eed64adbe53a3df7384 commit + ff563a3de3ff9931c2702516c74c8aea8d5cf142 blob - 18d2e6e9a1b19b345fcc5feaabcd5e2c5dc6ca5e blob + 34beeb2b7345dac2a513a297aab77a4a94811563 --- lib/got_lib_pack.h +++ lib/got_lib_pack.h @@ -170,5 +170,4 @@ const struct got_error *got_packfile_extract_object(st struct got_object *, FILE *, FILE *, FILE *); const struct got_error *got_packfile_extract_object_to_mem(uint8_t **, size_t *, struct got_object *, struct got_pack *); -const struct got_error *got_pack_get_packfile_size(size_t *, const char *); struct got_pack *got_repo_get_cached_pack(struct got_repository *, const char *); blob - 6779323106d7b5ee0bbd2c4fa38b3102384c0def blob + 9f38ab305851d89c4ee68b2ae45ad8935d7a6d87 --- lib/pack.c +++ lib/pack.c @@ -66,49 +66,6 @@ verify_fanout_table(uint32_t *fanout_table) } const struct got_error * -got_pack_get_packfile_size(size_t *size, const char *path) -{ - struct stat sb; - char *dot; - - *size = 0; - - dot = strrchr(path, '.'); - if (dot == NULL) - return got_error(GOT_ERR_BAD_PATH); - - /* Path must point to a pack index or to a pack file. */ - if (strcmp(dot, GOT_PACKIDX_SUFFIX) == 0) { - const struct got_error *err = NULL; - char *path_pack; - char base_path[PATH_MAX]; - - /* Convert pack index path to pack file path. */ - if (strlcpy(base_path, path, PATH_MAX) > PATH_MAX) - return got_error(GOT_ERR_NO_SPACE); - dot = strrchr(base_path, '.'); - if (dot == NULL) - return got_error(GOT_ERR_BAD_PATH); - *dot = '\0'; - if (asprintf(&path_pack, "%s.pack", base_path) == -1) - return got_error_from_errno("asprintf"); - - if (stat(path_pack, &sb) != 0) - err = got_error_from_errno("asprintf"); - free(path_pack); - if (err) - return err; - } else if (strcmp(dot, GOT_PACKFILE_SUFFIX) == 0) { - if (stat(path, &sb) != 0) - return got_error_from_errno2("stat", path); - } else - return got_error(GOT_ERR_BAD_PATH); - - *size = sb.st_size; - return 0; -} - -const struct got_error * got_packidx_init_hdr(struct got_packidx *p, int verify) { const struct got_error *err = NULL; blob - 4a2efe86fcf1cf4a1e8a7b1cac198509adfa3a8c blob + bff89f510415a95da98401388298562dac05a804 --- lib/repository.c +++ lib/repository.c @@ -722,6 +722,7 @@ got_repo_cache_pack(struct got_pack **packp, struct go { const struct got_error *err = NULL; struct got_pack *pack = NULL; + struct stat sb; int i; if (packp) @@ -756,9 +757,11 @@ got_repo_cache_pack(struct got_pack **packp, struct go if (err) goto done; - err = got_pack_get_packfile_size(&pack->filesize, path_packfile); - if (err) + if (fstat(pack->fd, &sb) != 0) { + err = got_error_from_errno("fstat"); goto done; + } + pack->filesize = sb.st_size; pack->privsep_child = NULL;