std::vector<std::string> SimpleFileStore::versions(const std::string& name, bool inprogress/*=false*/) const { std::vector<std::string> versions; FilePaths paths = filepath(name); if ( File::exists(paths.current()) ) versions.push_back( lookupVersion(paths.current()).toString() ); if ( File::exists(paths.deleted()) ) versions.push_back( lookupVersion(paths.deleted(), true).toString() ); if ( inprogress && File::exists(paths.inprogress()) ) versions.push_back( lookupVersion(paths.inprogress()).toString() ); return versions; }
bool SimpleFileStore::onDeleteComplete(const std::string& name, KeyMetadata& md) { FilePaths paths = filepath(name); if ( !testIfVersionGreater(md.version, paths.current()) ) { File::remove(paths.inprogress()); return false; } unsigned long long currentDigest = removeIfExists(paths.deleted(), true); if ( !File::set_modified_time(paths.inprogress(), timeFromVersion(md.version)) || !File::rename(paths.inprogress(), paths.deleted()) ) { File::remove(paths.inprogress()); return false; } md.digest ^= removeIfExists(paths.current()); md.digest ^= currentDigest; return true; }
bool SimpleFileStore::remove(const std::string& name) { FilePaths fps = filepath(name); bool success = File::remove(fps.inprogress()) | File::remove(fps.deleted()) | File::remove(fps.current()); boost::filesystem::path path = fps.current(); path = path.parent_path(); while (File::remove(path.string())) path = path.parent_path(); return success; }
readstream SimpleFileStore::read(const std::string& name, const std::string& version, bool inprogress/*=false*/) const { // can't read inprogress versions, because I don't want to think about it. FilePaths paths = filepath(name); KeyMetadata md; if (!version.empty()) { md.version.fromString(version); if (md.version.compare(mergedVersion(name)) != VectorClock::EQUAL) return readstream(); } else md.version = mergedVersion(name); string filename = md.version.isDeleted()? paths.deleted() : paths.current(); FileReader* reader = new FileReader(filename); if (name.find(MEMBERSHIP_FILE_PREFIX) == 0) md.totalCopies = 0; return readstream(reader, md); }