storage cleanup
This commit is contained in:
@@ -161,6 +161,7 @@ namespace libtorrent
|
|||||||
virtual bool delete_files() = 0;
|
virtual bool delete_files() = 0;
|
||||||
|
|
||||||
virtual std::string const& error() const = 0;
|
virtual std::string const& error() const = 0;
|
||||||
|
virtual std::string const& error_file() const = 0;
|
||||||
virtual void clear_error() = 0;
|
virtual void clear_error() = 0;
|
||||||
|
|
||||||
virtual ~storage_interface() {}
|
virtual ~storage_interface() {}
|
||||||
@@ -201,9 +202,6 @@ namespace libtorrent
|
|||||||
|
|
||||||
torrent_info const* info() const { return m_info.get(); }
|
torrent_info const* info() const { return m_info.get(); }
|
||||||
|
|
||||||
// frees a buffer that was returned from a read operation
|
|
||||||
void free_buffer(char* buf);
|
|
||||||
|
|
||||||
void write_resume_data(entry& rd, std::vector<bool> const& have) const;
|
void write_resume_data(entry& rd, std::vector<bool> const& have) const;
|
||||||
|
|
||||||
void async_check_fastresume(entry const* resume_data
|
void async_check_fastresume(entry const* resume_data
|
||||||
|
@@ -297,9 +297,8 @@ namespace libtorrent
|
|||||||
|
|
||||||
if (!view.valid())
|
if (!view.valid())
|
||||||
{
|
{
|
||||||
m_error = "failed to open file '";
|
m_error = "failed to open file for reading";
|
||||||
m_error += (m_save_path / file_iter->path).string();
|
m_error_file = (m_save_path / file_iter->path).string();
|
||||||
m_error += "'for reading";
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
TORRENT_ASSERT(view.const_addr() != 0);
|
TORRENT_ASSERT(view.const_addr() != 0);
|
||||||
@@ -418,9 +417,8 @@ namespace libtorrent
|
|||||||
|
|
||||||
if (!view.valid())
|
if (!view.valid())
|
||||||
{
|
{
|
||||||
m_error = "failed to open file '";
|
m_error = "failed to open file for writing";
|
||||||
m_error += (m_save_path / file_iter->path).string();
|
m_error_file = (m_save_path / file_iter->path).string();
|
||||||
m_error += "'for writing";
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
TORRENT_ASSERT(view.addr() != 0);
|
TORRENT_ASSERT(view.addr() != 0);
|
||||||
@@ -477,9 +475,8 @@ namespace libtorrent
|
|||||||
|
|
||||||
if (!view.valid())
|
if (!view.valid())
|
||||||
{
|
{
|
||||||
m_error = "failed to open file '";
|
m_error = "failed to open file for reading";
|
||||||
m_error += (m_save_path / file_iter->path).string();
|
m_error_file = (m_save_path / file_iter->path).string();
|
||||||
m_error += "'for reading";
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
TORRENT_ASSERT(view.addr() != 0);
|
TORRENT_ASSERT(view.addr() != 0);
|
||||||
@@ -489,6 +486,7 @@ namespace libtorrent
|
|||||||
catch (std::exception& e)
|
catch (std::exception& e)
|
||||||
{
|
{
|
||||||
m_error = e.what();
|
m_error = e.what();
|
||||||
|
m_error_file = (m_save_path / file_iter->path).string();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
return size;
|
return size;
|
||||||
@@ -647,6 +645,7 @@ namespace libtorrent
|
|||||||
if (rd.type() != entry::dictionary_t)
|
if (rd.type() != entry::dictionary_t)
|
||||||
{
|
{
|
||||||
m_error = "invalid fastresume file";
|
m_error = "invalid fastresume file";
|
||||||
|
m_error_file.clear();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
std::vector<std::pair<size_type, std::time_t> > file_sizes
|
std::vector<std::pair<size_type, std::time_t> > file_sizes
|
||||||
@@ -754,6 +753,7 @@ namespace libtorrent
|
|||||||
|
|
||||||
int result = 0;
|
int result = 0;
|
||||||
std::string error;
|
std::string error;
|
||||||
|
std::string error_file;
|
||||||
|
|
||||||
// delete the files from disk
|
// delete the files from disk
|
||||||
std::set<std::string> directories;
|
std::set<std::string> directories;
|
||||||
@@ -773,6 +773,7 @@ namespace libtorrent
|
|||||||
if (std::remove(p.c_str()) != 0 && errno != ENOENT)
|
if (std::remove(p.c_str()) != 0 && errno != ENOENT)
|
||||||
{
|
{
|
||||||
error = std::strerror(errno);
|
error = std::strerror(errno);
|
||||||
|
error_file = p;
|
||||||
result = errno;
|
result = errno;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -786,16 +787,22 @@ namespace libtorrent
|
|||||||
if (std::remove(i->c_str()) != 0 && errno != ENOENT)
|
if (std::remove(i->c_str()) != 0 && errno != ENOENT)
|
||||||
{
|
{
|
||||||
error = std::strerror(errno);
|
error = std::strerror(errno);
|
||||||
|
error_file = *i;
|
||||||
result = errno;
|
result = errno;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!error.empty()) m_error.swap(error);
|
if (!error.empty())
|
||||||
|
{
|
||||||
|
m_error.swap(error);
|
||||||
|
m_error_file.swap(error_file);
|
||||||
|
}
|
||||||
return result != 0;
|
return result != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string const& error() const { return m_error; }
|
std::string const& error() const { return m_error; }
|
||||||
void clear_error() { m_error.clear(); }
|
std::string const& error_file() const { return m_error_file; }
|
||||||
|
void clear_error() { m_error.clear(); m_error_file.clear(); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
@@ -808,6 +815,7 @@ namespace libtorrent
|
|||||||
static mapped_file_pool m_pool;
|
static mapped_file_pool m_pool;
|
||||||
|
|
||||||
mutable std::string m_error;
|
mutable std::string m_error;
|
||||||
|
mutable std::string m_error_file;
|
||||||
};
|
};
|
||||||
|
|
||||||
storage_interface* mapped_storage_constructor(boost::intrusive_ptr<torrent_info const> ti
|
storage_interface* mapped_storage_constructor(boost::intrusive_ptr<torrent_info const> ti
|
||||||
|
108
src/storage.cpp
108
src/storage.cpp
@@ -376,7 +376,8 @@ namespace libtorrent
|
|||||||
sha1_hash hash_for_slot(int slot, partial_hash& ph, int piece_size);
|
sha1_hash hash_for_slot(int slot, partial_hash& ph, int piece_size);
|
||||||
|
|
||||||
std::string const& error() const { return m_error; }
|
std::string const& error() const { return m_error; }
|
||||||
void clear_error() { m_error.clear(); }
|
std::string const& error_file() const { return m_error_file; }
|
||||||
|
void clear_error() { m_error.clear(); m_error_file.clear(); }
|
||||||
|
|
||||||
int read_impl(char* buf, int slot, int offset, int size, bool fill_zero);
|
int read_impl(char* buf, int slot, int offset, int size, bool fill_zero);
|
||||||
|
|
||||||
@@ -394,6 +395,7 @@ namespace libtorrent
|
|||||||
buffer m_scratch_buffer;
|
buffer m_scratch_buffer;
|
||||||
|
|
||||||
mutable std::string m_error;
|
mutable std::string m_error;
|
||||||
|
mutable std::string m_error_file;
|
||||||
};
|
};
|
||||||
|
|
||||||
sha1_hash storage::hash_for_slot(int slot, partial_hash& ph, int piece_size)
|
sha1_hash storage::hash_for_slot(int slot, partial_hash& ph, int piece_size)
|
||||||
@@ -466,6 +468,7 @@ namespace libtorrent
|
|||||||
}
|
}
|
||||||
catch (std::exception& e)
|
catch (std::exception& e)
|
||||||
{
|
{
|
||||||
|
m_error_file = (m_save_path / file_iter->path).string();
|
||||||
m_error = e.what();
|
m_error = e.what();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -489,6 +492,7 @@ namespace libtorrent
|
|||||||
}
|
}
|
||||||
catch (std::exception& e)
|
catch (std::exception& e)
|
||||||
{
|
{
|
||||||
|
m_error_file = (m_save_path / file_iter->path).string();
|
||||||
m_error = e.what();
|
m_error = e.what();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -514,6 +518,7 @@ namespace libtorrent
|
|||||||
|
|
||||||
int result = 0;
|
int result = 0;
|
||||||
std::string error;
|
std::string error;
|
||||||
|
std::string error_file;
|
||||||
|
|
||||||
// delete the files from disk
|
// delete the files from disk
|
||||||
std::set<std::string> directories;
|
std::set<std::string> directories;
|
||||||
@@ -533,6 +538,7 @@ namespace libtorrent
|
|||||||
if (std::remove(p.c_str()) != 0 && errno != ENOENT)
|
if (std::remove(p.c_str()) != 0 && errno != ENOENT)
|
||||||
{
|
{
|
||||||
error = std::strerror(errno);
|
error = std::strerror(errno);
|
||||||
|
error_file = p;
|
||||||
result = errno;
|
result = errno;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -546,11 +552,16 @@ namespace libtorrent
|
|||||||
if (std::remove(i->c_str()) != 0 && errno != ENOENT)
|
if (std::remove(i->c_str()) != 0 && errno != ENOENT)
|
||||||
{
|
{
|
||||||
error = std::strerror(errno);
|
error = std::strerror(errno);
|
||||||
|
error_file = *i;
|
||||||
result = errno;
|
result = errno;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!error.empty()) m_error.swap(error);
|
if (!error.empty())
|
||||||
|
{
|
||||||
|
m_error.swap(error);
|
||||||
|
m_error_file.swap(error_file);
|
||||||
|
}
|
||||||
return result != 0;
|
return result != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -558,6 +569,7 @@ namespace libtorrent
|
|||||||
{
|
{
|
||||||
if (rd.type() != entry::dictionary_t)
|
if (rd.type() != entry::dictionary_t)
|
||||||
{
|
{
|
||||||
|
m_error_file.clear();
|
||||||
m_error = "invalid fastresume file";
|
m_error = "invalid fastresume file";
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -847,13 +859,16 @@ namespace libtorrent
|
|||||||
, error));
|
, error));
|
||||||
if (!in)
|
if (!in)
|
||||||
{
|
{
|
||||||
m_error = "failed to open file ";
|
m_error_file = (m_save_path / file_iter->path).string();
|
||||||
m_error += (m_save_path / file_iter->path).string();
|
m_error = error;
|
||||||
m_error += ": ";
|
return -1;
|
||||||
m_error += error;
|
}
|
||||||
|
if (!in->error().empty())
|
||||||
|
{
|
||||||
|
m_error_file = (m_save_path / file_iter->path).string();
|
||||||
|
m_error = in->error();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
TORRENT_ASSERT(in->error().empty());
|
|
||||||
TORRENT_ASSERT(file_offset < file_iter->size);
|
TORRENT_ASSERT(file_offset < file_iter->size);
|
||||||
TORRENT_ASSERT(slices[0].offset == file_offset + file_iter->file_base);
|
TORRENT_ASSERT(slices[0].offset == file_offset + file_iter->file_base);
|
||||||
|
|
||||||
@@ -863,7 +878,8 @@ namespace libtorrent
|
|||||||
// the file was not big enough
|
// the file was not big enough
|
||||||
if (!fill_zero)
|
if (!fill_zero)
|
||||||
{
|
{
|
||||||
m_error = "slot has no storage";
|
m_error_file = (m_save_path / file_iter->path).string();
|
||||||
|
m_error = "seek failed";
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
std::memset(buf + buf_pos, 0, size - buf_pos);
|
std::memset(buf + buf_pos, 0, size - buf_pos);
|
||||||
@@ -913,8 +929,8 @@ namespace libtorrent
|
|||||||
if (actual_read > 0) buf_pos += actual_read;
|
if (actual_read > 0) buf_pos += actual_read;
|
||||||
if (!fill_zero)
|
if (!fill_zero)
|
||||||
{
|
{
|
||||||
m_error = "failed to read file: "
|
m_error_file = (m_save_path / file_iter->path).string();
|
||||||
+ (m_save_path / file_iter->path).string();
|
m_error = "read failed";
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
std::memset(buf + buf_pos, 0, size - buf_pos);
|
std::memset(buf + buf_pos, 0, size - buf_pos);
|
||||||
@@ -943,14 +959,28 @@ namespace libtorrent
|
|||||||
this, path, file::in, error);
|
this, path, file::in, error);
|
||||||
if (!in)
|
if (!in)
|
||||||
{
|
{
|
||||||
m_error = "failed to open file ";
|
m_error_file = path.string();
|
||||||
m_error += path.string();
|
m_error = error;
|
||||||
m_error += ": ";
|
|
||||||
m_error += error;
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
TORRENT_ASSERT(in->error().empty());
|
if (!in->error().empty())
|
||||||
in->seek(file_iter->file_base);
|
{
|
||||||
|
m_error_file = (m_save_path / file_iter->path).string();
|
||||||
|
m_error = in->error();
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
size_type pos = in->seek(file_iter->file_base);
|
||||||
|
if (pos != file_iter->file_base)
|
||||||
|
{
|
||||||
|
if (!fill_zero)
|
||||||
|
{
|
||||||
|
m_error_file = (m_save_path / file_iter->path).string();
|
||||||
|
m_error = "seek failed";
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
std::memset(buf + buf_pos, 0, size - buf_pos);
|
||||||
|
return size;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
@@ -998,13 +1028,16 @@ namespace libtorrent
|
|||||||
|
|
||||||
if (!out)
|
if (!out)
|
||||||
{
|
{
|
||||||
m_error = "failed to open file ";
|
m_error_file += p.string();
|
||||||
m_error += p.string();
|
m_error = error;
|
||||||
m_error += ": ";
|
return -1;
|
||||||
m_error += error;
|
}
|
||||||
|
if (!out->error().empty())
|
||||||
|
{
|
||||||
|
m_error_file += p.string();
|
||||||
|
m_error = out->error();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
TORRENT_ASSERT(out->error().empty());
|
|
||||||
TORRENT_ASSERT(file_offset < file_iter->size);
|
TORRENT_ASSERT(file_offset < file_iter->size);
|
||||||
TORRENT_ASSERT(slices[0].offset == file_offset + file_iter->file_base);
|
TORRENT_ASSERT(slices[0].offset == file_offset + file_iter->file_base);
|
||||||
|
|
||||||
@@ -1012,7 +1045,8 @@ namespace libtorrent
|
|||||||
|
|
||||||
if (pos != file_offset + file_iter->file_base)
|
if (pos != file_offset + file_iter->file_base)
|
||||||
{
|
{
|
||||||
m_error = "failed to seek " + (m_save_path / file_iter->path).string();
|
m_error_file = (m_save_path / file_iter->path).string();
|
||||||
|
m_error = "seek failed";
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1050,7 +1084,8 @@ namespace libtorrent
|
|||||||
|
|
||||||
if (written != write_bytes)
|
if (written != write_bytes)
|
||||||
{
|
{
|
||||||
m_error = "failed to write " + (m_save_path / file_iter->path).string();
|
m_error_file = (m_save_path / file_iter->path).string();
|
||||||
|
m_error = "write failed";
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1077,15 +1112,25 @@ namespace libtorrent
|
|||||||
|
|
||||||
if (!out)
|
if (!out)
|
||||||
{
|
{
|
||||||
m_error = "failed to open file ";
|
m_error_file = p.string();
|
||||||
m_error += p.string();
|
m_error = error;
|
||||||
m_error += ": ";
|
return -1;
|
||||||
m_error += error;
|
}
|
||||||
|
if (!out->error().empty())
|
||||||
|
{
|
||||||
|
m_error_file += p.string();
|
||||||
|
m_error = out->error();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
TORRENT_ASSERT(out->error().empty());
|
|
||||||
|
|
||||||
out->seek(file_iter->file_base);
|
size_type pos = out->seek(file_iter->file_base);
|
||||||
|
|
||||||
|
if (pos != file_iter->file_base)
|
||||||
|
{
|
||||||
|
m_error_file = (m_save_path / file_iter->path).string();
|
||||||
|
m_error = "seek failed";
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return size;
|
return size;
|
||||||
@@ -1125,11 +1170,6 @@ namespace libtorrent
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void piece_manager::free_buffer(char* buf)
|
|
||||||
{
|
|
||||||
m_io_thread.free_buffer(buf);
|
|
||||||
}
|
|
||||||
|
|
||||||
void piece_manager::async_release_files(
|
void piece_manager::async_release_files(
|
||||||
boost::function<void(int, disk_io_job const&)> const& handler)
|
boost::function<void(int, disk_io_job const&)> const& handler)
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user