throw IOException("Error opening statcache");
}
- found_match = false;
old_metadata_eof = false;
this->store = store;
while (!old_metadata_eof) {
string old_path = uri_decode(old_metadata["name"]);
int cmp = pathcmp(old_path.c_str(), path_str);
- if (cmp == 0) {
- found_match = true;
+ if (cmp == 0)
return true;
- } else if (cmp > 0) {
- found_match = false;
+ else if (cmp > 0)
return false;
- } else {
+ else
read_statcache();
- }
}
- found_match = false;
return false;
}
s++;
}
- ObjectReference *r = ObjectReference::parse(ref);
- if (r != NULL) {
- blocks.push_back(*r);
- delete r;
- }
+ ObjectReference r = ObjectReference::parse(ref);
+ if (!r.is_null())
+ blocks.push_back(r);
}
return blocks;
item.text += encode_dict(info) + "\n";
if (info == old_metadata) {
- ObjectReference *ref = ObjectReference::parse(old_metadata_loc);
- if (ref != NULL) {
+ ObjectReference ref = ObjectReference::parse(old_metadata_loc);
+ if (!ref.is_null()) {
item.reused = true;
- item.ref = *ref;
- delete ref;
+ item.ref = ref;
}
}
ObjectReference close();
bool find(const std::string& path);
- ObjectReference *old_ref() const {
+ ObjectReference old_ref() const {
return ObjectReference::parse(old_metadata_loc);
}
- bool matched() const { return found_match; }
bool is_unchanged(const struct stat *stat_buf);
dictionary get_old_metadata() const { return old_metadata; }
std::ostringstream metadata_root;
// Statcache information read back in from a previous run
- bool found_match; // Result of last call to find
bool old_metadata_eof;
dictionary old_metadata;
std::string old_metadata_loc; // Reference to where the metadata is found
string ObjectReference::to_string() const
{
+ if (is_null())
+ return "/";
+
string result = segment + "/" + object;
if (checksum_valid)
/* Parse a string object reference and return a pointer to a new
* ObjectReference. The caller is responsible for freeing the object. NULL is
* returned if there is an error in the syntax. */
-ObjectReference *ObjectReference::parse(const std::string& str)
+ObjectReference ObjectReference::parse(const std::string& str)
{
const char *s = str.c_str();
const char *t;
while ((*t >= '0' && *t <= '9') || (*t >= 'a' && *t <= 'f') || (*t == '-'))
t++;
if (*t != '/')
- return NULL;
+ return ObjectReference();
string segment(s, t - s);
// Object sequence number
while ((*t >= '0' && *t <= '9') || (*t >= 'a' && *t <= 'f'))
t++;
if (*t != '\0' && *t != '(' && *t != '[')
- return NULL;
+ return ObjectReference();
string object(s, t - s);
// Checksum
while (*t != ')' && *t != '\0')
t++;
if (*t != ')')
- return NULL;
+ return ObjectReference();
checksum = string(s, t - s);
t++;
}
while (*t >= '0' && *t <= '9')
t++;
if (*t != '+')
- return NULL;
+ return ObjectReference();
string val(s, t - s);
range1 = atoll(val.c_str());
while (*t >= '0' && *t <= '9')
t++;
if (*t != ']')
- return NULL;
+ return ObjectReference();
val = string(s, t - s);
range2 = atoll(val.c_str());
have_range = true;
}
- ObjectReference *ref = new ObjectReference(segment, object);
+ ObjectReference ref(segment, object);
if (checksum.size() > 0)
- ref->set_checksum(checksum);
+ ref.set_checksum(checksum);
if (have_range)
- ref->set_range(range1, range2);
+ ref.set_range(range1, range2);
return ref;
}
ObjectReference(const std::string& segment, int sequence);
ObjectReference(const std::string& segment, const std::string& sequence);
- bool is_null() { return segment.size() == 0; }
+ bool is_null() const { return segment.size() == 0; }
std::string to_string() const;
- static ObjectReference *parse(const std::string& s);
+ static ObjectReference parse(const std::string& s);
std::string get_segment() const { return segment; }
std::string get_sequence() const { return object; }
* re-reading the entire contents. */
bool cached = false;
- if (metawriter->matched() && metawriter->is_unchanged(&stat_buf)) {
+ if (metawriter->find(path) && metawriter->is_unchanged(&stat_buf)) {
cached = true;
list<ObjectReference> blocks = metawriter->get_blocks();
printf("%s\n", path.c_str());
- metawriter->find(path);
-
file_info["name"] = uri_encode(path);
file_info["mode"] = encode_int(stat_buf.st_mode & 07777, 8);
file_info["ctime"] = encode_int(stat_buf.st_ctime);