Clean up the file hashing interface and segment metadata hashes.
authorMichael Vrable <vrable@cs.hmc.edu>
Fri, 10 May 2013 04:53:07 +0000 (21:53 -0700)
committerMichael Vrable <vrable@cs.hmc.edu>
Sun, 26 Jan 2014 20:42:11 +0000 (12:42 -0800)
Switch the segment file hashes to the generic hashing code, and ensure that
the metadata checkpoint file also has a hash computed and stored.

hash.cc
hash.h
main.cc
store.cc

diff --git a/hash.cc b/hash.cc
index 7e2087a..2875814 100644 (file)
--- a/hash.cc
+++ b/hash.cc
@@ -50,6 +50,17 @@ Hash *Hash::New(const std::string& name)
         return constructor();
 }
 
+std::string Hash::hash_file(const char *filename)
+{
+    string result;
+    Hash *hash = Hash::New();
+    if (hash->update_from_file(filename))
+        result = hash->digest_str();
+
+    delete hash;
+    return result;
+}
+
 bool Hash::update_from_file(const char *filename)
 {
     FILE *f = fopen(filename, "rb");
diff --git a/hash.h b/hash.h
index 12d5b47..5f14dab 100644 (file)
--- a/hash.h
+++ b/hash.h
@@ -53,6 +53,9 @@ public:
     static Hash *New();
     static Hash *New(const std::string& name);
 
+    // Computes and returns the hash of a file on disk.
+    static std::string hash_file(const char *filename);
+
 protected:
     virtual const uint8_t *finalize() = 0;
 
diff --git a/main.cc b/main.cc
index ede33c6..91d1cef 100644 (file)
--- a/main.cc
+++ b/main.cc
@@ -917,6 +917,9 @@ int main(int argc, char *argv[])
         }
     }
     fclose(dbmeta);
+
+    string dbmeta_csum
+        = Hash::hash_file(dbmeta_file->get_local_path().c_str());
     dbmeta_file->send();
 
     db->Close();
@@ -961,6 +964,10 @@ int main(int argc, char *argv[])
         fprintf(descriptor, "Scheme: %s\n", backup_scheme.c_str());
     fprintf(descriptor, "Root: %s\n", backup_root.c_str());
 
+    if (dbmeta_csum.size() > 0) {
+        fprintf(descriptor, "Database-state: %s\n", dbmeta_csum.c_str());
+    }
+
     if (csum.size() > 0) {
         fprintf(descriptor, "Checksums: %s\n", csum.c_str());
     }
index ccd055d..31ff40f 100644 (file)
--- a/store.cc
+++ b/store.cc
@@ -309,11 +309,8 @@ void TarSegmentStore::close_segment(const string &group)
             group_sizes[segment->group].second += disk_size;
         }
 
-        SHA1Checksum segment_checksum;
-        string checksum;
-        if (segment_checksum.process_file(segment->rf->get_local_path().c_str())) {
-            checksum = segment_checksum.checksum_str();
-        }
+        string checksum
+            = Hash::hash_file(segment->rf->get_local_path().c_str());
 
         db->SetSegmentMetadata(segment->name, segment->rf->get_remote_path(),
                                checksum, group, segment->data_size, disk_size);