return true;
}
-size_t common_header_size(const struct common_header *header, bool *is_compressed)
+size_t
+common_header_content_size(
+ const struct common_header *header, bool *is_compressed)
{
*is_compressed = header->compression_type != COMPR_TYPE_NONE;
return header->content_size;
XXH64_state_t *checksum,
char **errmsg);
-size_t common_header_size(const struct common_header *header, bool *is_compressed);
+size_t common_header_content_size(
+ const struct common_header *header, bool *is_compressed);
void common_header_dump(const struct common_header *header, FILE *f);
-// Copyright (C) 2002-2006 Andrew Tridgell
-// Copyright (C) 2009-2018 Joel Rosdahl
+// Copyright (C) 2019 Joel Rosdahl
//
// This program is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by the Free
#include "ccache.h"
+#include "common_header.h"
#include "manifest.h"
#include "result.h"
+static size_t
+content_size(
+ const char *path, const char *magic, uint8_t version, bool *is_compressed)
+{
+ char *errmsg;
+ size_t size = 0;
+ FILE *f = fopen(path, "rb");
+ if (!f) {
+ cc_log("Failed to open %s for reading: %s", path, strerror(errno));
+ goto error;
+ }
+ struct common_header header;
+ if (!common_header_initialize_for_reading(
+ &header,
+ f,
+ magic,
+ version,
+ NULL,
+ NULL,
+ NULL,
+ &errmsg)) {
+ cc_log("Error: %s", errmsg);
+ goto error;
+ }
+ size = common_header_content_size(&header, is_compressed);
+
+error:
+ if (f) {
+ fclose(f);
+ }
+ return size;
+}
+
static unsigned num_files;
static unsigned comp_files;
size_t uncompressed_size;
bool is_compressed;
- if (str_endswith(p, ".manifest")) {
- uncompressed_size = manifest_size(fname, &is_compressed);
- } else if (str_endswith(p, ".result")) {
- uncompressed_size = result_size(fname, &is_compressed);
+ const char *file_ext = get_extension(p);
+ if (str_eq(file_ext, ".manifest")) {
+ uncompressed_size =
+ content_size(fname, MANIFEST_MAGIC, MANIFEST_VERSION, &is_compressed);
+ } else if (str_eq(file_ext, ".result")) {
+ uncompressed_size =
+ content_size(fname, RESULT_MAGIC, RESULT_VERSION, &is_compressed);
} else {
uncompressed_size = 0;
is_compressed = false;
}
- // Ignore unknown files in the cache, including any files from older versions.
+ // Ignore unknown files in the cache, including any files from older
+ // versions.
if (uncompressed_size > 0) {
cache_size += st->st_size;
num_files++;
return ret;
}
-size_t
-manifest_size(const char *path, bool *is_compressed)
-{
- char *errmsg;
- size_t size = 0;
- FILE *f = fopen(path, "rb");
- if (!f) {
- cc_log("Failed to open %s for reading: %s", path, strerror(errno));
- goto error;
- }
- struct common_header header;
- if (!common_header_initialize_for_reading(
- &header,
- f,
- MANIFEST_MAGIC,
- MANIFEST_VERSION,
- NULL,
- NULL,
- NULL,
- &errmsg)) {
- cc_log("Error: %s", errmsg);
- goto error;
- }
- size = common_header_size(&header, is_compressed);
-error:
- if (f) {
- fclose(f);
- }
- return size;
-}
-
bool
manifest_dump(const char *manifest_path, FILE *stream)
{
struct digest *manifest_get(struct conf *conf, const char *manifest_path);
bool manifest_put(const char *manifest_path, struct digest *result_digest,
struct hashtable *included_files);
-size_t manifest_size(const char *manifest_path, bool *is_compressed);
bool manifest_dump(const char *manifest_path, FILE *stream);
#endif
return ret;
}
-
-size_t
-result_size(const char *path, bool *is_compressed)
-{
- size_t size = 0;
- char *errmsg;
- FILE *f = fopen(path, "rb");
- if (!f) {
- cc_log("Failed to open %s for reading: %s", path, strerror(errno));
- goto error;
- }
- struct common_header header;
- if (!common_header_initialize_for_reading(
- &header,
- f,
- RESULT_MAGIC,
- RESULT_VERSION,
- NULL,
- NULL,
- NULL,
- &errmsg)) {
- cc_log("Error: %s", errmsg);
- goto error;
- }
- size = common_header_size(&header, is_compressed);
-error:
- if (f) {
- fclose(f);
- }
- return size;
-}
-
bool
result_dump(const char *path, FILE *stream)
{
bool result_get(const char *path, struct result_files *list);
bool result_put(const char *path, struct result_files *list);
-size_t result_size(const char *path, bool *is_compressed);
bool result_dump(const char *path, FILE *stream);
#endif