make the file_storage interface a bit more sane, and fixed typos in make_torrent documentation

This commit is contained in:
Arvid Norberg 2012-03-26 16:07:55 +00:00
parent 289921e276
commit a2cb2c9bca
3 changed files with 108 additions and 50 deletions

View File

@ -59,15 +59,15 @@ add_files
::
template <class Pred>
void add_files(file_storage& fs, boost::filesystem::path const& path, Pred p
void add_files(file_storage& fs, std::string const& path, Pred p
, boost::uint32_t flags = 0);
template <class Pred>
void add_files(file_storage& fs, boost::filesystem::wpath const& path, Pred p
void add_files(file_storage& fs, std::wstring const& path, Pred p
, boost::uint32_t flags = 0);
void add_files(file_storage& fs, boost::filesystem::path const& path
void add_files(file_storage& fs, std::string const& path
, boost::uint32_t flags = 0);
void add_files(file_storage& fs, boost::filesystem::wpath const& path
void add_files(file_storage& fs, std::wstring const& path
, boost::uint32_t flags = 0);
Adds the file specified by ``path`` to the ``file_storage`` object. In case ``path``
@ -77,11 +77,11 @@ If specified, the predicate ``p`` is called once for every file and directory th
is encountered. files for which ``p`` returns true are added, and directories for
which ``p`` returns true are traversed. ``p`` must have the following signature::
bool Pred(boost::filesystem::path const& p);
bool Pred(std::string const& p);
and for the wpath version::
and for the wide string version::
bool Pred(boost::filesystem::wpath const& p);
bool Pred(std::wstring const& p);
The path that is passed in to the predicate is the full path of the file or
directory. If no predicate is specified, all files are added, and all directories
@ -98,21 +98,21 @@ set_piece_hashes()
::
template <class Fun>
void set_piece_hashes(create_torrent& t, boost::filesystem::path const& p, Fun f);
void set_piece_hashes(create_torrent& t, std::string const& p, Fun f);
template <class Fun>
void set_piece_hashes(create_torrent& t, boost::filesystem::wpath const& p, Fun f);
void set_piece_hashes(create_torrent& t, std::wstring const& p, Fun f);
template <class Fun>
void set_piece_hashes(create_torrent& t, boost::filesystem::path const& p, Fun f
void set_piece_hashes(create_torrent& t, std::string const& p, Fun f
, error_code& ec);
template <class Fun>
void set_piece_hashes(create_torrent& t, boost::filesystem::wpath const& p, Fun f
void set_piece_hashes(create_torrent& t, std::wstring const& p, Fun f
, error_code& ec);
void set_piece_hashes(create_torrent& t, boost::filesystem::path const& p);
void set_piece_hashes(create_torrent& t, boost::filesystem::wpath const& p);
void set_piece_hashes(create_torrent& t, boost::filesystem::path const& p
void set_piece_hashes(create_torrent& t, std::string const& p);
void set_piece_hashes(create_torrent& t, std::wstring const& p);
void set_piece_hashes(create_torrent& t, std::string const& p
, error_code& ec);
void set_piece_hashes(create_torrent& t, boost::filesystem::wpath const& p
void set_piece_hashes(create_torrent& t, std::wstring const& p
, error_code& ec);
This function will assume that the files added to the torrent file exists at path
@ -146,8 +146,8 @@ file structure. Its synopsis::
};
void add_file(file_entry const& e);
void add_file(fs::path const& p, size_type size, int flags = 0);
void add_file(fs::wpath const& p, size_type size, int flags = 0);
void add_file(std::string const& p, size_type size, int flags = 0);
void add_file(std::wstring const& p, size_type size, int flags = 0);
void rename_file(int index, std::string const& new_filename);
void rename_file(int index, std::wstring const& new_filename);
@ -155,8 +155,8 @@ file structure. Its synopsis::
, int size) const;
peer_request map_file(int file, size_type offset, int size) const;
typedef std::vector<file_entry>::const_iterator iterator;
typedef std::vector<file_entry>::const_reverse_iterator reverse_iterator;
typedef std::vector<internal_file_entry>::const_iterator iterator;
typedef std::vector<internal_file_entry>::const_reverse_iterator reverse_iterator;
iterator begin() const;
iterator end() const;
@ -164,7 +164,7 @@ file structure. Its synopsis::
reverse_iterator rend() const;
int num_files() const;
file_entry const& at(int index) const;
file_entry at(int index) const;
size_type total_size() const;
void set_num_pieces(int n);
@ -173,12 +173,12 @@ file structure. Its synopsis::
int piece_length() const;
int piece_size(int index) const;
sha1_hash const& hash(internal_file_entry const& fe) const;
std::string const& symlink(internal_file_entry const& fe) const;
time_t mtime(internal_file_entry const& fe) const;
int file_index(internal_file_entry const& fe) const;
size_type file_base(internal_file_entry const& fe) const;
void set_file_base(internal_file_entry const& fe, size_type off);
sha1_hash const& hash(int index) const;
std::string const& symlink(int index) const;
time_t mtime(int index) const;
int file_index(int index) const;
size_type file_base(int index) const;
void set_file_base(int index, size_type off);
void set_name(std::string const& n);
void set_name(std::wstring const& n);
@ -219,18 +219,13 @@ hash() symlink() mtime() file_index()
::
sha1_hash hash(internal_file_entry const& fe) const;
std::string const& symlink(internal_file_entry const& fe) const;
time_t mtime(internal_file_entry const& fe) const;
int file_index(internal_file_entry const& fe) const;
sha1_hash hash(int index) const;
std::string const& symlink(int index) const;
time_t mtime(int index) const;
int file_index(int index) const;
These functions are used to query the symlink, file hash,
modification time and the file-index from a ``internal_file_entry``,
which typically would be acquired from an iterator.
For these functions to function, the file entry must be an
actual object from this same ``file_storage`` object. It may
not be a copy.
modification time and the file-index from a file index.
The file hash is a sha-1 hash of the file, or 0 if none was
provided in the torrent file. This can potentially be used to
@ -247,8 +242,8 @@ file_base() set_file_base()
::
size_type file_base(internal_file_entry const& fe) const;
void set_file_base(internal_file_entry const& fe, size_type off);
size_type file_base(int index) const;
void set_file_base(int index, size_type off);
The file base of a file is the offset within the file on the filsystem
where it starts to write. For the most part, this is always 0. It's

View File

@ -246,6 +246,15 @@ namespace libtorrent
// not add any padding
void optimize(int pad_file_limit = -1);
sha1_hash hash(int index) const;
std::string const& symlink(int index) const;
time_t mtime(int index) const;
int file_index(int index) const;
size_type file_base(int index) const;
void set_file_base(int index, size_type off);
std::string file_path(int index) const;
size_type file_size(int index) const;
sha1_hash hash(internal_file_entry const& fe) const;
std::string const& symlink(internal_file_entry const& fe) const;
time_t mtime(internal_file_entry const& fe) const;

View File

@ -277,18 +277,6 @@ namespace libtorrent
return ret;
}
std::string file_storage::file_path(internal_file_entry const& fe) const
{
TORRENT_ASSERT(fe.path_index >= -1 && fe.path_index < int(m_paths.size()));
if (fe.path_index == -1) return fe.filename();
return combine_path(m_paths[fe.path_index], fe.filename());
}
size_type file_storage::file_size(internal_file_entry const& fe) const
{
return fe.size;
}
peer_request file_storage::map_file(int file_index, size_type file_offset
, int size) const
{
@ -389,6 +377,60 @@ namespace libtorrent
update_path_index(e);
}
sha1_hash file_storage::hash(int index) const
{
if (index >= int(m_file_hashes.size())) return sha1_hash(0);
return sha1_hash(m_file_hashes[index]);
}
std::string const& file_storage::symlink(int index) const
{
TORRENT_ASSERT(index >= 0 && index < int(m_files.size()));
internal_file_entry const& fe = m_files[index];
TORRENT_ASSERT(fe.symlink_index < int(m_symlinks.size()));
return m_symlinks[fe.symlink_index];
}
time_t file_storage::mtime(int index) const
{
if (index >= int(m_mtime.size())) return 0;
return m_mtime[index];
}
int file_storage::file_index(int index) const
{
TORRENT_ASSERT(index >= 0 && index < int(m_files.size()));
return index;
}
void file_storage::set_file_base(int index, size_type off)
{
TORRENT_ASSERT(index >= 0 && index < int(m_files.size()));
if (int(m_file_base.size()) <= index) m_file_base.resize(index);
m_file_base[index] = off;
}
size_type file_storage::file_base(int index) const
{
if (index >= int(m_file_base.size())) return 0;
return m_file_base[index];
}
std::string file_storage::file_path(int index) const
{
TORRENT_ASSERT(index >= 0 && index < int(m_files.size()));
internal_file_entry const& fe = m_files[index];
TORRENT_ASSERT(fe.path_index >= -1 && fe.path_index < int(m_paths.size()));
if (fe.path_index == -1) return fe.filename();
return combine_path(m_paths[fe.path_index], fe.filename());
}
size_type file_storage::file_size(int index) const
{
TORRENT_ASSERT(index >= 0 && index < int(m_files.size()));
return m_files[index].size;
}
sha1_hash file_storage::hash(internal_file_entry const& fe) const
{
int index = &fe - &m_files[0];
@ -431,6 +473,18 @@ namespace libtorrent
return m_file_base[index];
}
std::string file_storage::file_path(internal_file_entry const& fe) const
{
TORRENT_ASSERT(fe.path_index >= -1 && fe.path_index < int(m_paths.size()));
if (fe.path_index == -1) return fe.filename();
return combine_path(m_paths[fe.path_index], fe.filename());
}
size_type file_storage::file_size(internal_file_entry const& fe) const
{
return fe.size;
}
bool compare_file_entry_size(internal_file_entry const& fe1, internal_file_entry const& fe2)
{ return fe1.size < fe2.size; }