diff --git a/src/BtFileAllocationEntry.cc b/src/BtFileAllocationEntry.cc index 95d383ec..debeacdc 100644 --- a/src/BtFileAllocationEntry.cc +++ b/src/BtFileAllocationEntry.cc @@ -46,6 +46,7 @@ #include "DiskAdaptor.h" #include "Option.h" #include "prefs.h" +#include "LogFactory.h" namespace aria2 { @@ -72,6 +73,22 @@ void BtFileAllocationEntry::prepareForNextAction (fileEntries.begin(), fileEntries.end())) { getRequestGroup()->createNextCommandWithAdj(commands, e, 0); } + } else { +#ifdef __MINGW32__ + const SharedHandle& diskAdaptor = + getRequestGroup()->getPieceStorage()->getDiskAdaptor(); + if(!diskAdaptor->isReadOnlyEnabled()) { + // On Windows, if aria2 opens files with GENERIC_WRITE access + // right, some programs cannot open them aria2 is seeding. To + // avoid this situation, re-open the files with read-only + // enabled. + A2_LOG_INFO("Closing files and re-open them with read-only mode" + " enabled."); + diskAdaptor->closeFile(); + diskAdaptor->enableReadOnly(); + diskAdaptor->openFile(); + } +#endif // __MINGW32__ } } diff --git a/src/DefaultPieceStorage.cc b/src/DefaultPieceStorage.cc index 63fba262..954765ef 100644 --- a/src/DefaultPieceStorage.cc +++ b/src/DefaultPieceStorage.cc @@ -480,6 +480,17 @@ void DefaultPieceStorage::completePiece(const SharedHandle& piece) SharedHandle torrentAttrs = bittorrent::getTorrentAttrs(downloadContext_); if(!torrentAttrs->metadata.empty()) { +#ifdef __MINGW32__ + // On Windows, if aria2 opens files with GENERIC_WRITE access + // right, some programs cannot open them aria2 is seeding. To + // avoid this situation, re-open the files with read-only + // enabled. + A2_LOG_INFO("Closing files and re-open them with read-only mode" + " enabled."); + diskAdaptor_->closeFile(); + diskAdaptor_->enableReadOnly(); + diskAdaptor_->openFile(); +#endif // __MINGW32__ util::executeHookByOptName(downloadContext_->getOwnerRequestGroup(), option_, PREF_ON_BT_DOWNLOAD_COMPLETE); SingletonHolder::instance()->