Skip to content

Commit

Permalink
fix directory creation on windows shared folders
Browse files Browse the repository at this point in the history
commit on behalf of FletcherD
  • Loading branch information
arvidn committed Feb 14, 2022
1 parent 902f5b4 commit 9218903
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
1 change: 1 addition & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
* fix directory creation on windows shared folders
* add flag to make add_files() not record file attributes
* deprecate (unused) allow_partial_disk_writes settings
* fix disk-full error reporting in mmap_disk_io
Expand Down
9 changes: 8 additions & 1 deletion src/mmap_storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -816,7 +816,14 @@ error_code translate_error(std::system_error const& err, bool const write)

boost::optional<aux::file_view> h = open_file_impl(sett, file, mode, ec);
if ((mode & aux::open_mode::write)
&& ec.ec == boost::system::errc::no_such_file_or_directory)
&& (ec.ec == boost::system::errc::no_such_file_or_directory
#ifdef TORRENT_WINDOWS
// this is a workaround for improper handling of files on windows shared drives.
// if the directory on a shared drive does not exist,
// windows returns ERROR_IO_DEVICE instead of ERROR_FILE_NOT_FOUND
|| ec.ec == error_code(ERROR_IO_DEVICE, system_category())
#endif
))
{
// this means the directory the file is in doesn't exist.
// so create it
Expand Down
11 changes: 9 additions & 2 deletions src/posix_storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -462,8 +462,15 @@ namespace aux {
// if we fail to open a file for writing, and the error is ENOENT,
// it is likely because the directory we're creating the file in
// does not exist. Create the directory and try again.
if ((mode & open_mode::write)
&& ec.ec == boost::system::errc::no_such_file_or_directory)
if ((mode & aux::open_mode::write)
&& (ec.ec == boost::system::errc::no_such_file_or_directory
#ifdef TORRENT_WINDOWS
// this is a workaround for improper handling of files on windows shared drives.
// if the directory on a shared drive does not exist,
// windows returns ERROR_IO_DEVICE instead of ERROR_FILE_NOT_FOUND
|| ec.ec == error_code(ERROR_IO_DEVICE, system_category())
#endif
))
{
// this means the directory the file is in doesn't exist.
// so create it
Expand Down

0 comments on commit 9218903

Please sign in to comment.