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");
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;
}
}
fclose(dbmeta);
+
+ string dbmeta_csum
+ = Hash::hash_file(dbmeta_file->get_local_path().c_str());
dbmeta_file->send();
db->Close();
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());
}
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);