summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2007-07-01 10:40:30 +0000
committerTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2007-07-01 10:40:30 +0000
commit055c9e0b210d7b2e800cb4b5de72c5f2d5b24b8e (patch)
tree68569b5a2b0c9d199c9083e1496f1b6d65f01535 /src
parent7e99d4d2a1b0b0b3db2768ac0090faded5bc2455 (diff)
2007-07-01 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Create directory structure specified in metalink file. * src/RequestGroup.h, src/RequestGroup.cc (initAndOpenFile): Create a directory to store files if it does not exist. (getDir): New function.
Diffstat (limited to 'src')
-rw-r--r--src/RequestGroup.cc17
-rw-r--r--src/RequestGroup.h2
2 files changed, 19 insertions, 0 deletions
diff --git a/src/RequestGroup.cc b/src/RequestGroup.cc
index be1af6d7..b1f6eaf7 100644
--- a/src/RequestGroup.cc
+++ b/src/RequestGroup.cc
@@ -48,6 +48,7 @@
#include "FatalException.h"
#include "CheckIntegrityEntry.h"
#include "DownloadCommand.h"
+#include <cerrno>
SegmentManHandle RequestGroup::initSegmentMan()
{
@@ -123,6 +124,13 @@ void RequestGroup::shouldCancelDownloadForSafety()
void RequestGroup::initAndOpenFile()
{
+ File d(getDir());
+ if(d.isDir()) {
+ } else if(d.exists()) {
+ throw new FatalException(EX_MAKE_DIR, getDir().c_str(), "not a directory");
+ } else if(!d.mkdirs()) {
+ throw new FatalException(EX_MAKE_DIR, getDir().c_str(), strerror(errno));
+ }
_segmentMan->diskWriter->initAndOpenFile(_segmentMan->getFilePath());
}
@@ -151,6 +159,15 @@ string RequestGroup::getFilePath() const
}
}
+string RequestGroup::getDir() const
+{
+ if(_segmentMan.isNull()) {
+ return "";
+ } else {
+ return _segmentMan->dir;
+ }
+}
+
void RequestGroup::loadAndOpenFile()
{
bool segFileExists = segmentFileExists();
diff --git a/src/RequestGroup.h b/src/RequestGroup.h
index edde7cf7..006fb318 100644
--- a/src/RequestGroup.h
+++ b/src/RequestGroup.h
@@ -187,6 +187,8 @@ public:
string getFilePath() const;
+ string getDir() const;
+
int64_t getExistingFileLength() const;
int64_t getTotalLength() const