X-Git-Url: http://git.vrable.net/?a=blobdiff_plain;f=ref.cc;h=2f870a66c9b793572302ad09fb1bf88054add0f5;hb=c10290a5e5b066bedfec4ae23a799e5d5a1ff009;hp=80f4d1deb51ee95706cb41559183e8466726baa9;hpb=d3c10b747ecec0acc14863fc12db9661c3f88128;p=cumulus.git diff --git a/ref.cc b/ref.cc index 80f4d1d..2f870a6 100644 --- a/ref.cc +++ b/ref.cc @@ -1,7 +1,24 @@ -/* LBS: An LFS-inspired filesystem backup system - * Copyright (C) 2007 Michael Vrable +/* Cumulus: Smart Filesystem Backup to Dumb Servers * - * Backups are structured as a collection of objects, which may refer to other + * Copyright (C) 2007 The Regents of the University of California + * Written by Michael Vrable + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +/* 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. */ @@ -78,7 +95,11 @@ string ObjectReference::to_string() const if (range_valid) { char buf[64]; - sprintf(buf, "[%zu+%zu]", range_start, range_length); + if (range_start == 0) { + sprintf(buf, "[%zu]", range_length); + } else { + sprintf(buf, "[%zu+%zu]", range_start, range_length); + } result += buf; } @@ -143,21 +164,28 @@ ObjectReference ObjectReference::parse(const std::string& str) s = t; while (*t >= '0' && *t <= '9') t++; - if (*t != '+') - return ObjectReference(); - string val(s, t - s); - range1 = atoll(val.c_str()); + // Abbreviated-length only range? + if (*t == ']') { + string val(s, t - s); + range2 = atoll(val.c_str()); + } else { + if (*t != '+') + return ObjectReference(); - t++; - s = t; - while (*t >= '0' && *t <= '9') - t++; - if (*t != ']') - return ObjectReference(); + string val(s, t - s); + range1 = atoll(val.c_str()); - val = string(s, t - s); - range2 = atoll(val.c_str()); + t++; + s = t; + while (*t >= '0' && *t <= '9') + t++; + if (*t != ']') + return ObjectReference(); + + val = string(s, t - s); + range2 = atoll(val.c_str()); + } have_range = true; }