lt 2879-storage cleanup and truncating files that are larger than they should be

This commit is contained in:
Marcos Pinto 2008-10-30 06:38:25 +00:00
parent da6594d138
commit c1be1f3072

View File

@ -505,44 +505,36 @@ namespace libtorrent
if (dir != last_path)
{
last_path = dir;
#if defined(_WIN32) && defined(UNICODE) && BOOST_VERSION < 103400
last_path = dir;
if (!exists_win(last_path))
create_directories_win(last_path);
#elif TORRENT_USE_WPATH
last_path = dir;
fs::wpath wp = safe_convert(last_path.string());
if (!exists(wp))
create_directories(wp);
#else
last_path = dir;
if (!exists(last_path))
create_directories(last_path);
#endif
}
// if the file is empty, just create it. But also make sure
// the directory exists.
if (file_iter->size == 0)
{
boost::shared_ptr<file> f = m_pool.open_file(this
, m_save_path / file_iter->path, file::in | file::out, ec);
if (ec)
{
set_error(m_save_path / file_iter->path, ec);
return true;
}
continue;
}
#ifndef BOOST_NO_EXCEPTIONS
try {
#endif
// don't allocate files with priority 0
int file_index = file_iter - files().begin();
if (allocate_files && (int(m_file_priority.size()) <= file_index
|| m_file_priority[file_index] > 0))
#if TORRENT_USE_WPATH
fs::wpath file_path = safe_convert(m_save_path / file_iter->path);
#else
fs::path file_path = m_save_path / file_iter->path;
#endif
// if the file is empty, just create it either way.
// if the file already exists, but is larger than what
// it's supposed to be, also truncate it
if (allocate_files
|| file_iter->size == 0
|| (exists(file_path) && file_size(file_path) > file_iter->size))
{
error_code ec;
boost::shared_ptr<file> f = m_pool.open_file(this
@ -2280,10 +2272,7 @@ namespace libtorrent
#else
&& m_storage->error() != error_code(ENOENT, get_posix_category()))
#endif
{
std::cerr << m_storage->error().message() << std::endl;
return -1;
}
return 1;
}