replace got_pack_get_packfile_size() with simple fstat()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
diff --git a/lib/got_lib_pack.h b/lib/got_lib_pack.h
index 18d2e6e..34beeb2 100644
--- a/lib/got_lib_pack.h
+++ b/lib/got_lib_pack.h
@@ -170,5 +170,4 @@ const struct got_error *got_packfile_extract_object(struct got_pack *,
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 *);
diff --git a/lib/pack.c b/lib/pack.c
index 6779323..9f38ab3 100644
--- a/lib/pack.c
+++ b/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;
diff --git a/lib/repository.c b/lib/repository.c
index 4a2efe8..bff89f5 100644
--- a/lib/repository.c
+++ b/lib/repository.c
@@ -722,6 +722,7 @@ got_repo_cache_pack(struct got_pack **packp, struct got_repository *repo,
{
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 got_repository *repo,
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;