Exemplo n.º 1
0
	void create_directories(std::string const& f, error_code& ec)
	{
		ec.clear();
		if (is_directory(f, ec)) return;
		if (ec != boost::system::errc::no_such_file_or_directory)
			return;
		ec.clear();
		if (is_root_path(f)) return;
		if (has_parent_path(f))
		{
			create_directories(parent_path(f), ec);
			if (ec) return;
		}
		create_directory(f, ec);
	}
Exemplo n.º 2
0
    void
    CoreFS::resetCachedFile(::boost::filesystem::path const &thePath)
    {
        if(m_cachedFileAndPath) {

            auto cachedPath = boost::filesystem::path(m_cachedFileAndPath->first);
            auto boostFolderPath = thePath;
            do {
                cachedPath = cachedPath.parent_path();
                if(cachedPath == boostFolderPath) {
                    m_cachedFileAndPath.reset();
                    m_cachedFileAndPath = nullptr;
                    break;
                }

            } while (cachedPath.has_parent_path());
        }
    }
Exemplo n.º 3
0
	void file_storage::add_file(std::string const& file, size_type size, int flags
		, std::time_t mtime, std::string const& symlink_path)
	{
		TORRENT_ASSERT(size >= 0);
		if (size < 0) size = 0;
		if (!has_parent_path(file))
		{
			// you have already added at least one file with a
			// path to the file (branch_path), which means that
			// all the other files need to be in the same top
			// directory as the first file.
			TORRENT_ASSERT(m_files.empty());
			m_name = file;
		}
		else
		{
			if (m_files.empty())
				m_name = split_path(file).c_str();
		}
		TORRENT_ASSERT(m_name == split_path(file).c_str());
		m_files.push_back(internal_file_entry());
		internal_file_entry& e = m_files.back();
		e.set_name(file.c_str());
		e.size = size;
		e.offset = m_total_size;
		e.pad_file = (flags & pad_file) != 0;
		e.hidden_attribute = (flags & attribute_hidden) != 0;
		e.executable_attribute = (flags & attribute_executable) != 0;
		e.symlink_attribute = (flags & attribute_symlink) != 0;
		if (e.symlink_attribute)
		{
			e.symlink_index = m_symlinks.size();
			m_symlinks.push_back(symlink_path);
		}
		if (mtime)
		{
			if (m_mtime.size() < m_files.size()) m_mtime.resize(m_files.size());
			m_mtime[m_files.size() - 1] = mtime;
		}
		
		update_path_index(e);
		m_total_size += size;
	}
Exemplo n.º 4
0
	void file_storage::add_file(file_entry const& ent, char const* filehash)
	{
		TORRENT_ASSERT(ent.size >= 0);
		if (!has_parent_path(ent.path))
		{
			// you have already added at least one file with a
			// path to the file (branch_path), which means that
			// all the other files need to be in the same top
			// directory as the first file.
			TORRENT_ASSERT(m_files.empty());
			m_name = ent.path;
		}
		else
		{
			if (m_files.empty())
				m_name = split_path(ent.path).c_str();
		}
		internal_file_entry ife(ent);
		m_files.push_back(ife);
		internal_file_entry& e = m_files.back();
		if (e.size < 0) e.size = 0;
		e.offset = m_total_size;
		m_total_size += e.size;
		if (filehash)
		{
			if (m_file_hashes.size() < m_files.size()) m_file_hashes.resize(m_files.size());
			m_file_hashes[m_files.size() - 1] = filehash;
		}
		if (!ent.symlink_path.empty())
		{
			e.symlink_index = m_symlinks.size();
			m_symlinks.push_back(ent.symlink_path);
		}
		if (ent.mtime)
		{
			if (m_mtime.size() < m_files.size()) m_mtime.resize(m_files.size());
			m_mtime[m_files.size() - 1] = ent.mtime;
		}
		if (ent.file_base) set_file_base(e, ent.file_base);
		update_path_index(e);
	}