mirror of https://github.com/aria2/aria2
mingw32: Re-open files with read-only mode enabled on seeding
On Mingw32 build, if aria2 opens file with GENERIC_WRITE access right, some programs cannot open the file aria2 is seeding. To avoid this situation, re-open files with read-only enabled when seeding is about to begin.pull/43/head
parent
43cee0c264
commit
c09a5a95f4
|
@ -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>& 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__
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -480,6 +480,17 @@ void DefaultPieceStorage::completePiece(const SharedHandle<Piece>& piece)
|
|||
SharedHandle<TorrentAttribute> 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<Notifier>::instance()->
|
||||
|
|
Loading…
Reference in New Issue