]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Implement manifest_dump
authorJoel Rosdahl <joel@rosdahl.net>
Tue, 2 Nov 2010 17:41:07 +0000 (18:41 +0100)
committerJoel Rosdahl <joel@rosdahl.net>
Tue, 2 Nov 2010 17:41:07 +0000 (18:41 +0100)
manifest.c
manifest.h

index dc3c7da920d6f3400d2242b4256f3cef748aac0d..6a58841cd1765e685ea76a014deb427258284dd8 100644 (file)
@@ -679,3 +679,78 @@ out:
        }
        return ret;
 }
+
+bool
+manifest_dump(const char *manifest_path, FILE *stream)
+{
+       struct manifest *mf = NULL;
+       int fd;
+       gzFile *f = NULL;
+       bool ret = false;
+       unsigned i, j;
+
+       fd = open(manifest_path, O_RDONLY | O_BINARY);
+       if (fd == -1) {
+               fprintf(stderr, "No such manifest file: %s\n", manifest_path);
+               goto out;
+       }
+       f = gzdopen(fd, "rb");
+       if (!f) {
+               fprintf(stderr, "Failed to dzopen manifest file\n");
+               close(fd);
+               goto out;
+       }
+       mf = read_manifest(f);
+       if (!mf) {
+               fprintf(stderr, "Error reading manifest file\n");
+               goto out;
+       }
+
+       fprintf(stream, "Magic: %c%c%c%c\n",
+               (MAGIC >> 24) & 0xFF,
+               (MAGIC >> 16) & 0xFF,
+               (MAGIC >> 8) & 0xFF,
+               MAGIC & 0xFF);
+       fprintf(stream, "Version: %u\n", mf->version);
+       fprintf(stream, "Hash size: %u\n", (unsigned)mf->hash_size);
+       fprintf(stream, "Reserved field: %u\n", (unsigned)mf->reserved);
+       fprintf(stream, "File paths (%u):\n", (unsigned)mf->n_files);
+       for (i = 0; i < mf->n_files; ++i) {
+               fprintf(stream, "  %u: %s\n", i, mf->files[i]);
+       }
+       fprintf(stream, "File infos (%u):\n", (unsigned)mf->n_file_infos);
+       for (i = 0; i < mf->n_file_infos; ++i) {
+               char *hash;
+               fprintf(stream, "  %u:\n", i);
+               fprintf(stream, "    Path index: %u\n", mf->file_infos[i].index);
+               hash = format_hash_as_string(mf->file_infos[i].hash, -1);
+               fprintf(stream, "    Hash: %s\n", hash);
+               free(hash);
+               fprintf(stream, "    Size: %u\n", mf->file_infos[i].size);
+       }
+       fprintf(stream, "Results (%u):\n", (unsigned)mf->n_objects);
+       for (i = 0; i < mf->n_objects; ++i) {
+               char *hash;
+               fprintf(stream, "  %u:\n", i);
+               fprintf(stream, "    File hash indexes:");
+               for (j = 0; j < mf->objects[i].n_file_info_indexes; ++j) {
+                       fprintf(stream, " %u", mf->objects[i].file_info_indexes[j]);
+               }
+               fprintf(stream, "\n");
+               hash = format_hash_as_string(mf->objects[i].hash.hash, -1);
+               fprintf(stream, "    Hash: %s\n", hash);
+               free(hash);
+               fprintf(stream, "    Size: %u\n", (unsigned)mf->objects[i].hash.size);
+       }
+
+       ret = true;
+
+out:
+       if (mf) {
+               free_manifest(mf);
+       }
+       if (f) {
+               gzclose(f);
+       }
+       return ret;
+}
index 80333e7a2a8cbafedf72bbe6df834e05e2eba25c..708496077d2536cda4fa480217b149739979632f 100644 (file)
@@ -7,5 +7,6 @@
 struct file_hash *manifest_get(const char *manifest_path);
 bool manifest_put(const char *manifest_path, struct file_hash *object_hash,
                   struct hashtable *included_files);
+bool manifest_dump(const char *manifest_path, FILE *stream);
 
 #endif