#include <unistd.h>
#include <fcntl.h>
#include <time.h>
-#include <uuid/uuid.h>
#include <list>
#include <set>
#include <iostream>
#include "store.h"
+#include "ref.h"
using std::list;
using std::set;
using std::string;
-list<string> TarSegmentStore::norefs;
-
Tarfile::Tarfile(const string &path, const string &segment)
: size(0),
segment_name(segment)
Tarfile::~Tarfile()
{
- string checksum_list = checksums.str();
- internal_write_object(segment_name + "/checksums",
- checksum_list.data(), checksum_list.size());
tar_append_eof(t);
if (tar_close(t) != 0)
string path = segment_name + "/" + buf;
internal_write_object(path, data, len);
-
- // Compute a checksum for the data block, which will be stored at the end
- // of the TAR file.
- SHA1Checksum hash;
- hash.process(data, len);
- sprintf(buf, "%08x", id);
- checksums << buf << " " << hash.checksum_str() << "\n";
}
void Tarfile::internal_write_object(const string &path,
static const size_t SEGMENT_SIZE = 4 * 1024 * 1024;
string TarSegmentStore::write_object(const char *data, size_t len, const
- std::string &group,
- const std::list<std::string> &refs)
+ std::string &group)
{
struct segment_info *segment;
if (segments.find(group) == segments.end()) {
segment = new segment_info;
- uint8_t uuid[16];
- char uuid_buf[40];
- uuid_generate(uuid);
- uuid_unparse_lower(uuid, uuid_buf);
- segment->name = uuid_buf;
+ segment->name = generate_uuid();
string filename = path + "/" + segment->name + ".tar";
segment->file = new Tarfile(filename, segment->name);
string full_name = segment->name + "/" + id_buf;
- // Store any dependencies this object has on other segments, so they can be
- // written when the segment is closed.
- for (list<string>::const_iterator i = refs.begin(); i != refs.end(); ++i) {
- segment->refs.insert(*i);
- }
-
// If this segment meets or exceeds the size target, close it so that
// future objects will go into a new segment.
if (segment->file->size_estimate() >= SEGMENT_SIZE)
fprintf(stderr, "Closing segment group %s (%s)\n",
group.c_str(), segment->name.c_str());
- string reflist;
- for (set<string>::iterator i = segment->refs.begin();
- i != segment->refs.end(); ++i) {
- reflist += *i + "\n";
- }
- segment->file->internal_write_object(segment->name + "/references",
- reflist.data(), reflist.size());
-
delete segment->file;
segments.erase(segments.find(group));
delete segment;
{
}
-void LbsObject::add_reference(const LbsObject *o)
-{
- // TODO: Implement
-}
-
void LbsObject::write(TarSegmentStore *store)
{
assert(data != NULL);