1 /* LBS: An LFS-inspired filesystem backup system
2 * Copyright (C) 2007 Michael Vrable
4 * Handling of metadata written to backup snapshots. This manages the writing
5 * of file metadata into new backup snapshots, including breaking the metadata
6 * log apart across separate objects. Eventually this should include unified
7 * handling of the statcache, and re-use of metadata between snapshots.
15 #include "statcache.h"
21 static const size_t LBS_METADATA_BLOCK_SIZE = 65536;
23 /* TODO: Move to header file */
24 void add_segment(const string& segment);
26 MetadataWriter::MetadataWriter(TarSegmentStore *store)
31 /* Ensure contents of metadata are flushed to an object. */
32 void MetadataWriter::metadata_flush()
34 string m = metadata.str();
38 /* Write current metadata information to a new object. */
39 LbsObject *meta = new LbsObject;
40 meta->set_group("metadata");
41 meta->set_data(m.data(), m.size());
45 /* Write a reference to this block in the root. */
46 ObjectReference ref = meta->get_ref();
47 metadata_root << "@" << ref.to_string() << "\n";
48 add_segment(ref.get_segment());
55 void MetadataWriter::add(const string& path, dictionary info)
57 metadata << "path: " << uri_encode(path) << "\n";
58 metadata << encode_dict(info);
61 if (metadata.str().size() > LBS_METADATA_BLOCK_SIZE)
65 ObjectReference MetadataWriter::close()
68 const string root_data = metadata_root.str();
70 LbsObject *root = new LbsObject;
71 root->set_group("metadata");
72 root->set_data(root_data.data(), root_data.size());
75 add_segment(root->get_ref().get_segment());
77 ObjectReference ref = root->get_ref();