Beispiel #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;
}
Beispiel #2
0
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;
}
Beispiel #3
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;
}
Beispiel #4
0
writestream SimpleFileStore::write(const std::string& name, const std::string& version, unsigned short, unsigned long long offset)
{
	KeyMetadata md;
	md.version.fromString(version);
	if (md.version.empty())
		md.version.increment("sec");

	uint64_t current = timeFromVersion( mergedVersion(name, true) );
	uint64_t prospective = timeFromVersion(md.version);
	if ( prospective < current || (prospective == current && !md.version.isDeleted()) || md.version.isExpired(EXPIRY_TIMEOUT_SECONDS) )
		return writestream();
	// correct versions in the future back to now?

	FilePaths paths = filepath(name);
	string tempname(paths.inprogress());
	boost::filesystem::create_directories(boost::filesystem::path(tempname).parent_path());

	FileWriter* writer = new FileWriter(tempname);
	return writestream(writer, md, std::bind(&SimpleFileStore::onWriteComplete, this, name, _1));
}