X-Git-Url: http://git.vrable.net/?a=blobdiff_plain;f=tarstore.h;h=6acee7fb4b0fce8707eb3aa02a095a0cfabe9ead;hb=13431fb44e1be1bdb3397685970011404fa49be8;hp=009dd90fbf34ca546b8c7e454bb629241d0e6ecd;hpb=5eeb3286b0a8a892195462c37815a064311ce1f6;p=cumulus.git diff --git a/tarstore.h b/tarstore.h index 009dd90..6acee7f 100644 --- a/tarstore.h +++ b/tarstore.h @@ -12,11 +12,31 @@ #include #include +#include +#include +#include #include #include #include -#include "store.h" +#include "sha1.h" + +/* In memory datatype to represent key/value pairs of information, such as file + * metadata. Currently implemented as map. */ +typedef std::map dictionary; + +/* IOException will be thrown if an error occurs while reading or writing in + * one of the I/O wrappers. Depending upon the context; this may be fatal or + * not--typically, errors reading/writing the store will be serious, but errors + * reading an individual file are less so. */ +class IOException : public std::exception { +private: + std::string error; +public: + explicit IOException(const std::string &err) { error = err; } + virtual ~IOException() throw () { } + std::string getError() const { return error; } +}; /* A simple wrapper around a single TAR file to represent a segment. Objects * may only be written out all at once, since the tar header must be written @@ -28,10 +48,14 @@ public: void write_object(int id, const char *data, size_t len); -private: + // Return an estimate of the size of the file. + size_t size_estimate() { return size; } + void internal_write_object(const std::string &path, const char *data, size_t len); +private: + size_t size; std::string segment_name; std::ostringstream checksums; TAR *t; @@ -48,7 +72,8 @@ public: // used to control object placement; objects with different group // parameters are kept in separate segments. std::string write_object(const char *data, size_t len, - const std::string &group = ""); + const std::string &group = "", + const std::list &refs = norefs); // Ensure all segments have been fully written. void sync(); @@ -56,12 +81,24 @@ public: private: struct segment_info { Tarfile *file; - std::string name; // UUID - int count; // Objects written to this segment + std::string name; // UUID + std::set refs; // Other segments this one refers to + int count; // Objects written to this segment }; std::string path; std::map segments; + + // An empty list which can be used as an argument to write_object to + // indicate that this object depends on no others. + static std::list norefs; + + // Ensure that all segments in the given group have been fully written. + void close_segment(const std::string &group); + + // Parse an object reference string and return just the segment name + // portion. + std::string object_reference_to_segment(const std::string &object); }; #endif // _LBS_TARSTORE_H