예제 #1
0
	std::vector<pool_file_status> file_pool::get_status(storage_index_t const st) const
	{
		std::vector<pool_file_status> ret;
		{
			std::unique_lock<std::mutex> l(m_mutex);

			auto const start = m_files.lower_bound(std::make_pair(st, file_index_t(0)));
			auto const end = m_files.upper_bound(std::make_pair(st
				, std::numeric_limits<file_index_t>::max()));

			for (auto i = start; i != end; ++i)
				ret.push_back({i->first.second, i->second.mode, i->second.last_use});
		}
		return ret;
	}
예제 #2
0
	void posix_storage::rename_file(file_index_t const index, std::string const& new_filename, storage_error& ec)
	{
		if (index < file_index_t(0) || index >= files().end_file()) return;
		std::string const old_name = files().file_path(index, m_save_path);

		if (exists(old_name, ec.ec))
		{
			std::string new_path;
			if (is_complete(new_filename)) new_path = new_filename;
			else new_path = combine_path(m_save_path, new_filename);
			std::string new_dir = parent_path(new_path);

			// create any missing directories that the new filename
			// lands in
			create_directories(new_dir, ec.ec);
			if (ec.ec)
			{
				ec.file(index);
				ec.operation = operation_t::file_rename;
				return;
			}

			rename(old_name, new_path, ec.ec);

			if (ec.ec == boost::system::errc::no_such_file_or_directory)
				ec.ec.clear();

			if (ec)
			{
				ec.file(index);
				ec.operation = operation_t::file_rename;
				return;
			}
		}
		else if (ec.ec)
		{
			// if exists fails, report that error
			ec.file(index);
			ec.operation = operation_t::file_rename;
			return;
		}

		if (!m_mapped_files)
		{
			m_mapped_files.reset(new file_storage(files()));
		}
		m_mapped_files->rename_file(index, new_filename);
	}
예제 #3
0
	void file_view_pool::release(storage_index_t const st)
	{
		std::vector<std::shared_ptr<file_mapping>> defer_destruction;

		std::unique_lock<std::mutex> l(m_mutex);

		auto& key_view = m_files.get<0>();
		auto const begin = key_view.lower_bound(file_id{st, file_index_t(0)});
		auto const end = key_view.upper_bound(file_id{st, std::numeric_limits<file_index_t>::max()});

		for (auto it = begin; it != end; ++it)
			defer_destruction.emplace_back(std::move(it->mapping));

		if (begin != end) key_view.erase(begin, end);
		l.unlock();
		// the files are closed here while the lock is not held
	}
예제 #4
0
	void file_pool::release(storage_index_t const st)
	{
		std::unique_lock<std::mutex> l(m_mutex);

		auto begin = m_files.lower_bound(std::make_pair(st, file_index_t(0)));
		auto const end = m_files.upper_bound(std::make_pair(st
				, std::numeric_limits<file_index_t>::max()));

		std::vector<file_handle> to_close;
		while (begin != end)
		{
			to_close.push_back(std::move(begin->second.file_ptr));
			m_files.erase(begin++);
		}
		l.unlock();
		// the files are closed here while the lock is not held
	}
예제 #5
0
	std::vector<open_file_state> file_view_pool::get_status(storage_index_t const st) const
	{
		std::vector<open_file_state> ret;
		{
			std::unique_lock<std::mutex> l(m_mutex);

			auto& key_view = m_files.get<0>();
			auto const start = key_view.lower_bound(file_id{st, file_index_t(0)});
			auto const end = key_view.upper_bound(file_id{st, std::numeric_limits<file_index_t>::max()});

			for (auto i = start; i != end; ++i)
			{
				ret.push_back({i->key.second
					, to_file_open_mode(i->mode)
					, i->last_use});
			}
		}
		return ret;
	}