diff --git a/ChangeLog b/ChangeLog index e4a8695a1..e4dd73cf1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,4 @@ + * don't create all directories up front when adding torrents * support DHT scrape * added support for fadvise/F_RDADVISE for improved disk read performance * introduced pop_alerts() which pops the entire alert queue in a single call diff --git a/src/storage.cpp b/src/storage.cpp index e9bb7305f..5820618b3 100644 --- a/src/storage.cpp +++ b/src/storage.cpp @@ -453,17 +453,6 @@ namespace libtorrent for (file_storage::iterator file_iter = files().begin(), end_iter = files().end(); file_iter != end_iter; ++file_iter) { - std::string file_path = combine_path(m_save_path, files().file_path(*file_iter)); - std::string dir = parent_path(file_path); - - if (dir != last_path) - { - last_path = dir; - - if (!is_directory(last_path, ec)) - create_directories(last_path, ec); - } - int file_index = files().file_index(*file_iter); // ignore files that have priority 0 @@ -473,6 +462,8 @@ namespace libtorrent // ignore pad files if (file_iter->pad_file) continue; + std::string file_path = combine_path(m_save_path, files().file_path(*file_iter)); + file_status s; stat_file(file_path, &s, ec); if (ec && ec != boost::system::errc::no_such_file_or_directory @@ -489,7 +480,21 @@ namespace libtorrent // if the file is empty, just create it either way. if ((ec && allocate_files) || (!ec && s.file_size > file_iter->size) || file_iter->size == 0) { + std::string dir = parent_path(file_path); + + if (dir != last_path) + { + last_path = dir; + + create_directories(last_path, ec); + if (ec) + { + set_error(dir, ec); + break; + } + } ec.clear(); + boost::intrusive_ptr f = open_file(file_iter, file::read_write, ec); if (ec) set_error(file_path, ec); else if (f)