X-Git-Url: http://git.vrable.net/?a=blobdiff_plain;f=ref.cc;fp=ref.cc;h=e996c7dc7a7af6e022e90882d2da4f119c6a37c9;hb=3cfc1643082e60fea72539033b7adb094d236b0a;hp=0000000000000000000000000000000000000000;hpb=b1a0bfe834d45694851787317da2cd55add2d7bb;p=cumulus.git diff --git a/ref.cc b/ref.cc new file mode 100644 index 0000000..e996c7d --- /dev/null +++ b/ref.cc @@ -0,0 +1,57 @@ +/* LBS: An LFS-inspired filesystem backup system + * Copyright (C) 2007 Michael Vrable + * + * Backups are structured as a collection of objects, which may refer to other + * objects. Object references are used to name other objects or parts of them. + * This file defines the class for representing object references and the + * textual representation of these references. */ + +#include +#include +#include + +#include + +#include "ref.h" + +using std::string; + +/* Generate a new UUID, and return the text representation of it. This is + * suitable for generating the name for a new segment. */ +string generate_uuid() +{ + uint8_t uuid[16]; + char buf[40]; + + uuid_generate(uuid); + uuid_unparse_lower(uuid, buf); + return string(buf); +} + + +ObjectReference::ObjectReference(const std::string& segment, int sequence) + : segment(segment) +{ + char seq_buf[64]; + sprintf(seq_buf, "%08x", sequence); + object = seq_buf; + + clear_checksum(); + clear_range(); +} + +string ObjectReference::to_string() const +{ + string result = segment + "/" + object; + + if (checksum_valid) + result += "(" + checksum + ")"; + + if (range_valid) { + char buf[64]; + sprintf(buf, "[%zu+%zu]", range_start, range_length); + result += buf; + } + + return result; +}