Exemple #1
0
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;
}
Exemple #2
0
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;
}
Exemple #3
0
bool SimpleFileStore::onWriteComplete(const std::string& name, KeyMetadata& md)
{
	if (md.version.isDeleted())
		return onDeleteComplete(name, md);

	FilePaths paths = filepath(name);
	if ( !testIfVersionGreater(md.version, paths.deleted()) )
	{
		File::remove(paths.inprogress());
		return false;
	}

	File::rename(paths.current(), paths.reserve());
	if ( !File::set_modified_time(paths.inprogress(), timeFromVersion(md.version)) || !File::rename(paths.inprogress(), paths.current()) )
	{
		File::rename(paths.reserve(), paths.current());
		File::remove(paths.inprogress());
		return false;
	}

	md.digest ^= removeIfExists(paths.reserve());
	md.digest ^= removeIfExists(paths.deleted(), true);
	return true;
}
Exemple #4
0
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);
}