summaryrefslogtreecommitdiff
path: root/src/BtFileAllocationEntry.cc
diff options
context:
space:
mode:
authorTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2012-12-24 22:59:29 +0900
committerTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2012-12-24 23:03:19 +0900
commitc09a5a95f4963cd67c5f3c92250ac3c1876bc430 (patch)
treea6dfab983518c380675d623d97a94729027b4961 /src/BtFileAllocationEntry.cc
parent43cee0c2641b9867a7e2506264eaedf583727034 (diff)
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.
Diffstat (limited to 'src/BtFileAllocationEntry.cc')
-rw-r--r--src/BtFileAllocationEntry.cc17
1 files changed, 17 insertions, 0 deletions
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>& 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__
}
}