浏览代码

2009-03-10 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>

	FileEntry::getPath() contains store(top level) directory to
	simplify path handling operation.  In the previous
	implementation, store directory is concatenated to
	FileEntry::getPath() in DownloadContext.
	* src/BtDependency.cc
	* src/BtPostDownloadHandler.cc
	* src/CopyDiskAdaptor.cc
	* src/DefaultBtContext.cc
	* src/DirectDiskAdaptor.cc
	* src/FileEntry.cc
	* src/FileEntry.h
	* src/FtpNegotiationCommand.cc
	* src/HttpResponse.cc
	* src/HttpResponseCommand.cc
	* src/Metalink2RequestGroup.cc
	* src/MultiDiskAdaptor.cc
	* src/MultiDiskAdaptor.h
	* src/MultiFileAllocationIterator.cc
	* src/RequestGroup.cc
	* src/SingleFileDownloadContext.cc
	* src/SingleFileDownloadContext.h
	* src/download_helper.cc
	* test/BtDependencyTest.cc
	* test/CopyDiskAdaptorTest.cc
	* test/DefaultBtContextTest.cc
	* test/DefaultBtProgressInfoFileTest.cc
	* test/DirectDiskAdaptorTest.cc
	* test/DownloadHelperTest.cc
	* test/FileEntryTest.cc
	* test/MultiDiskAdaptorTest.cc
	* test/MultiFileAllocationIteratorTest.cc
	* test/RequestGroupTest.cc
	* test/SingleFileDownloadContextTest.cc
Tatsuhiro Tsujikawa 16 年之前
父节点
当前提交
e2704bd823

+ 36 - 0
ChangeLog

@@ -1,3 +1,39 @@
+2009-03-10  Tatsuhiro Tsujikawa  <t-tujikawa@users.sourceforge.net>
+
+	FileEntry::getPath() contains store(top level) directory to
+	simplify path handling operation.  In the previous implementation,
+	store directory is concatenated to FileEntry::getPath() in
+	DownloadContext.
+	* src/BtDependency.cc
+	* src/BtPostDownloadHandler.cc
+	* src/CopyDiskAdaptor.cc
+	* src/DefaultBtContext.cc
+	* src/DirectDiskAdaptor.cc
+	* src/FileEntry.cc
+	* src/FileEntry.h
+	* src/FtpNegotiationCommand.cc
+	* src/HttpResponse.cc
+	* src/HttpResponseCommand.cc
+	* src/Metalink2RequestGroup.cc
+	* src/MultiDiskAdaptor.cc
+	* src/MultiDiskAdaptor.h
+	* src/MultiFileAllocationIterator.cc
+	* src/RequestGroup.cc
+	* src/SingleFileDownloadContext.cc
+	* src/SingleFileDownloadContext.h
+	* src/download_helper.cc
+	* test/BtDependencyTest.cc
+	* test/CopyDiskAdaptorTest.cc
+	* test/DefaultBtContextTest.cc
+	* test/DefaultBtProgressInfoFileTest.cc
+	* test/DirectDiskAdaptorTest.cc
+	* test/DownloadHelperTest.cc
+	* test/FileEntryTest.cc
+	* test/MultiDiskAdaptorTest.cc
+	* test/MultiFileAllocationIteratorTest.cc
+	* test/RequestGroupTest.cc
+	* test/SingleFileDownloadContextTest.cc
+	
 2009-03-09  Tatsuhiro Tsujikawa  <t-tujikawa@users.sourceforge.net>
 
 	Fixed compiler warning

+ 13 - 2
src/BtDependency.cc

@@ -65,17 +65,28 @@ bool BtDependency::resolve()
     // cut reference here
     _dependee.reset();
     DefaultBtContextHandle btContext(new DefaultBtContext());
+    btContext->setDir(_dependant->getDownloadContext()->getDir());
     try {
       DiskAdaptorHandle diskAdaptor = dependee->getPieceStorage()->getDiskAdaptor();
       diskAdaptor->openExistingFile();
       std::string content = Util::toString(diskAdaptor);
+
+      std::string overrideName;
+      if(Util::startsWith(_dependant->getDownloadContext()->getActualBasePath(),
+			  _dependant->getDownloadContext()->getDir())) {
+	overrideName =
+	  _dependant->getDownloadContext()->getActualBasePath().substr
+	  (_dependant->getDownloadContext()->getDir().size());
+	if(Util::startsWith(overrideName, "/")) {
+	  overrideName = overrideName.substr(1);
+	}
+      }
       btContext->loadFromMemory(content,
 				File(dependee->getFilePath()).getBasename(),
-				_dependant->getDownloadContext()->getName());
+				overrideName);
       if(_option->defined(PREF_PEER_ID_PREFIX)) {
 	btContext->setPeerIdPrefix(_option->get(PREF_PEER_ID_PREFIX));
       }
-      btContext->setDir(_dependant->getDownloadContext()->getDir());
     } catch(RecoverableException& e) {
       _logger->error(EX_EXCEPTION_CAUGHT, e);
       _logger->debug("BtDependency for GID#%d failed. Go without Bt.",

+ 1 - 1
src/BtPostDownloadHandler.cc

@@ -77,11 +77,11 @@ void BtPostDownloadHandler::getNextRequestGroups
     throw;
   }
   DefaultBtContextHandle btContext(new DefaultBtContext());
+  btContext->setDir(requestGroup->getDownloadContext()->getDir());
   btContext->loadFromMemory(content, File(requestGroup->getFilePath()).getBasename());
   if(op->defined(PREF_PEER_ID_PREFIX)) {
     btContext->setPeerIdPrefix(op->get(PREF_PEER_ID_PREFIX));
   }
-  btContext->setDir(requestGroup->getDownloadContext()->getDir());
   rg->setDownloadContext(btContext);
   btContext->setOwnerRequestGroup(rg.get());
   

+ 3 - 5
src/CopyDiskAdaptor.cc

@@ -54,9 +54,8 @@ void CopyDiskAdaptor::fixFilename()
   for(FileEntries::iterator itr = fileEntries.begin();
       itr != fileEntries.end(); itr++) {
     if(!(*itr)->isExtracted() && (*itr)->isRequested()) {
-      std::string topDirPath = storeDir+"/"+topDir;
-      (*itr)->setupDir(topDirPath);
-      std::string destFilePath = topDirPath+"/"+(*itr)->getPath();
+      (*itr)->setupDir();
+      std::string destFilePath = (*itr)->getPath();
       logger->info(MSG_WRITING_FILE, destFilePath.c_str());
       Util::rangedFileCopy(destFilePath, getFilePath(),
 			   offset, (*itr)->getLength());
@@ -74,11 +73,10 @@ std::string CopyDiskAdaptor::getFilePath()
 size_t CopyDiskAdaptor::utime(const Time& actime, const Time& modtime)
 {
   size_t numOK = 0;
-  std::string topDirPath = storeDir+"/"+topDir;
   for(std::deque<SharedHandle<FileEntry> >::const_iterator i =
 	fileEntries.begin(); i != fileEntries.end(); ++i) {
     if((*i)->isExtracted() && (*i)->isRequested()) {
-      File f(topDirPath+"/"+(*i)->getPath());
+      File f((*i)->getPath());
       if(f.isFile() && f.utime(actime, modtime)) {
 	++numOK;
       }

+ 3 - 1
src/DefaultBtContext.cc

@@ -160,6 +160,7 @@ void DefaultBtContext::extractFileEntries(const bencode::BDE& infoDict,
       std::deque<std::string> elements;
       Util::slice(elements, path, '/');
       elements.push_front(name);
+      elements.push_front(_dir);
       path = Util::joinPath(elements.begin(), elements.end());
 
       std::deque<std::string> uris;
@@ -180,7 +181,8 @@ void DefaultBtContext::extractFileEntries(const bencode::BDE& infoDict,
 				     BtContext::C_LENGTH.c_str()).str());      
     }
     totalLength = lengthData.i();
-    FileEntryHandle fileEntry(new FileEntry(name, totalLength, 0, urlList));
+    // TODO slice name and apply Util::joinPath()
+    FileEntryHandle fileEntry(new FileEntry(_dir+"/"+name, totalLength, 0, urlList));
     fileEntries.push_back(fileEntry);
   }
 }

+ 1 - 1
src/DirectDiskAdaptor.cc

@@ -40,7 +40,7 @@ namespace aria2 {
 
 std::string DirectDiskAdaptor::getFilePath()
 {
-  return storeDir+"/"+fileEntries.front()->getPath();
+  return fileEntries.front()->getPath();
 }
 
 void DirectDiskAdaptor::onDownloadComplete()

+ 2 - 2
src/FileEntry.cc

@@ -47,9 +47,9 @@ FileEntry::FileEntry(const std::string& path,
 
 FileEntry::~FileEntry() {}
 
-void FileEntry::setupDir(const std::string& parentDir)
+void FileEntry::setupDir()
 {
-  Util::mkdirs(File(parentDir+"/"+path).getDirname());
+  Util::mkdirs(File(path).getDirname());
 }
 
 FileEntry& FileEntry::operator=(const FileEntry& entry)

+ 1 - 1
src/FileEntry.h

@@ -91,7 +91,7 @@ public:
 
   void setRequested(bool flag) { this->requested = flag; }
 
-  void setupDir(const std::string& parentDir);
+  void setupDir();
 
   const std::deque<std::string>& getAssociatedUris() const
   {

+ 1 - 1
src/FtpNegotiationCommand.cc

@@ -327,7 +327,7 @@ bool FtpNegotiationCommand::onFileSizeDetermined(uint64_t totalLength)
   SingleFileDownloadContextHandle dctx =
     dynamic_pointer_cast<SingleFileDownloadContext>(_requestGroup->getDownloadContext());
   dctx->setTotalLength(totalLength);
-  dctx->setFilename(Util::urldecode(req->getFile()));
+  dctx->setFilename(dctx->getDir()+"/"+Util::urldecode(req->getFile()));
   _requestGroup->preDownloadProcessing();
   if(e->_requestGroupMan->isSameFileBeingDownloaded(_requestGroup)) {
     throw DownloadFailureException

+ 6 - 1
src/HttpResponse.cc

@@ -101,7 +101,12 @@ std::string HttpResponse::determinFilename() const
     Util::getContentDispositionFilename
     (httpHeader->getFirst(HttpHeader::CONTENT_DISPOSITION));
   if(contentDisposition.empty()) {
-    return Util::urldecode(httpRequest->getFile());
+    std::string file = Util::urldecode(httpRequest->getFile());
+    if(file.empty()) {
+      return "index.html";
+    } else {
+      return file;
+    }
   } else {
     logger->info(MSG_CONTENT_DISPOSITION_DETECTED,
 		 cuid, contentDisposition.c_str());

+ 1 - 1
src/HttpResponseCommand.cc

@@ -129,7 +129,7 @@ bool HttpResponseCommand::executeInternal()
     SingleFileDownloadContextHandle dctx =
       dynamic_pointer_cast<SingleFileDownloadContext>(_requestGroup->getDownloadContext());
     dctx->setTotalLength(totalLength);
-    dctx->setFilename(httpResponse->determinFilename());
+    dctx->setFilename(dctx->getDir()+"/"+httpResponse->determinFilename());
     dctx->setContentType(httpResponse->getContentType());
     _requestGroup->preDownloadProcessing();
     if(e->_requestGroupMan->isSameFileBeingDownloaded(_requestGroup)) {

+ 1 - 0
src/Metalink2RequestGroup.cc

@@ -212,6 +212,7 @@ Metalink2RequestGroup::createRequestGroup
       (new SingleFileDownloadContext(pieceLength,
 				     entry->getLength(),
 				     A2STR::NIL,
+				     requestOption.get(PREF_DIR)+"/"+
 				     entry->file->getPath()));
     dctx->setDir(requestOption.get(PREF_DIR));
 #ifdef ENABLE_MESSAGE_DIGEST

+ 31 - 39
src/MultiDiskAdaptor.cc

@@ -58,15 +58,15 @@ DiskWriterEntry::DiskWriterEntry(const SharedHandle<FileEntry>& fileEntry):
 
 DiskWriterEntry::~DiskWriterEntry() {}
 
-std::string DiskWriterEntry::getFilePath(const std::string& storeDir) const
+const std::string& DiskWriterEntry::getFilePath() const
 {
-  return storeDir+"/"+fileEntry->getPath();
+  return fileEntry->getPath();
 }
 
-void DiskWriterEntry::initAndOpenFile(const std::string& storeDir)
+void DiskWriterEntry::initAndOpenFile()
 {
   if(!diskWriter.isNull()) {
-    diskWriter->initAndOpenFile(getFilePath(storeDir), fileEntry->getLength());
+    diskWriter->initAndOpenFile(getFilePath(), fileEntry->getLength());
     if(_directIO) {
       diskWriter->enableDirectIO();
     }
@@ -74,10 +74,10 @@ void DiskWriterEntry::initAndOpenFile(const std::string& storeDir)
   }
 }
 
-void DiskWriterEntry::openFile(const std::string& storeDir)
+void DiskWriterEntry::openFile()
 {
   if(!diskWriter.isNull()) {
-    diskWriter->openFile(getFilePath(storeDir), fileEntry->getLength());
+    diskWriter->openFile(getFilePath(), fileEntry->getLength());
     if(_directIO) {
       diskWriter->enableDirectIO();
     }
@@ -85,10 +85,10 @@ void DiskWriterEntry::openFile(const std::string& storeDir)
   }
 }
 
-void DiskWriterEntry::openExistingFile(const std::string& storeDir)
+void DiskWriterEntry::openExistingFile()
 {
   if(!diskWriter.isNull()) {
-    diskWriter->openExistingFile(getFilePath(storeDir), fileEntry->getLength());
+    diskWriter->openExistingFile(getFilePath(), fileEntry->getLength());
     if(_directIO) {
       diskWriter->enableDirectIO();
     }
@@ -109,9 +109,9 @@ void DiskWriterEntry::closeFile()
   }
 }
 
-bool DiskWriterEntry::fileExists(const std::string& storeDir)
+bool DiskWriterEntry::fileExists()
 {
-  return File(getFilePath(storeDir)).exists();
+  return File(getFilePath()).exists();
 }
 
 uint64_t DiskWriterEntry::size() const
@@ -270,9 +270,9 @@ void MultiDiskAdaptor::resetDiskWriterEntries()
 	diskWriterEntries.begin(); i != diskWriterEntries.end(); ++i) {
     if((*i)->needsFileAllocation() ||
        dwreq.find((*i)->getFileEntry()->getPath()) != dwreq.end() ||
-       (*i)->fileExists(storeDir)) {
+       (*i)->fileExists()) {
       logger->debug("Creating DiskWriter for filename=%s",
-		    (*i)->getFilePath(storeDir).c_str());
+		    (*i)->getFilePath().c_str());
       (*i)->setDiskWriter(dwFactory.newDiskWriter());
       (*i)->getDiskWriter()->setDirectIOAllowed(_directIOAllowed);
       if(_readOnly) {
@@ -287,25 +287,23 @@ std::string MultiDiskAdaptor::getTopDirPath() const
   return storeDir+"/"+topDir;
 }
 
-void MultiDiskAdaptor::mkdir(const std::string& storeDir) const
+void MultiDiskAdaptor::mkdir() const
 {
   for(std::deque<SharedHandle<DiskWriterEntry> >::const_iterator i =
 	diskWriterEntries.begin(); i != diskWriterEntries.end(); ++i) {
-    (*i)->getFileEntry()->setupDir(storeDir);
+    (*i)->getFileEntry()->setupDir();
   }
 }
 
 void MultiDiskAdaptor::openIfNot
-(const SharedHandle<DiskWriterEntry>& entry,
- void (DiskWriterEntry::*open)(const std::string&),
- const std::string& storeDir)
+(const SharedHandle<DiskWriterEntry>& entry, void (DiskWriterEntry::*open)())
 {
   if(!entry->isOpen()) {
 //     logger->debug("DiskWriterEntry: Cache MISS. offset=%s",
 // 		  Util::itos(entry->getFileEntry()->getOffset()).c_str());
  
     size_t numOpened = _openedDiskWriterEntries.size();
-    (entry.get()->*open)(storeDir);
+    (entry.get()->*open)();
     if(numOpened >= _maxOpenFiles) {
       // Cache is full. 
       // Choose one DiskWriterEntry randomly and close it.
@@ -327,23 +325,23 @@ void MultiDiskAdaptor::openIfNot
 void MultiDiskAdaptor::openFile()
 {
   resetDiskWriterEntries();
-  mkdir(storeDir);
+  mkdir();
   // Call DiskWriterEntry::openFile to make sure that zero-length files are
   // created.
   for(DiskWriterEntries::iterator itr = diskWriterEntries.begin();
       itr != diskWriterEntries.end(); ++itr) {
-    openIfNot(*itr, &DiskWriterEntry::openFile, storeDir);
+    openIfNot(*itr, &DiskWriterEntry::openFile);
   }
 }
 
 void MultiDiskAdaptor::initAndOpenFile()
 {
   resetDiskWriterEntries();
-  mkdir(storeDir);
+  mkdir();
   // Call DiskWriterEntry::initAndOpenFile to make files truncated.
   for(DiskWriterEntries::iterator itr = diskWriterEntries.begin();
       itr != diskWriterEntries.end(); ++itr) {
-    openIfNot(*itr, &DiskWriterEntry::initAndOpenFile, storeDir);
+    openIfNot(*itr, &DiskWriterEntry::initAndOpenFile);
   }
 }
 
@@ -412,13 +410,12 @@ findFirstDiskWriterEntry(const DiskWriterEntries& diskWriterEntries, off_t offse
 }
 
 static void throwOnDiskWriterNotOpened(const SharedHandle<DiskWriterEntry>& e,
-				       off_t offset,
-				       const std::string& storeDir)
+				       off_t offset)
 {
   throw DlAbortEx
     (StringFormat("DiskWriter for offset=%s, filename=%s is not opened.",
 		  Util::itos(offset).c_str(),
-		  e->getFilePath(storeDir).c_str()).str());  
+		  e->getFilePath().c_str()).str());  
 }
 
 void MultiDiskAdaptor::writeData(const unsigned char* data, size_t len,
@@ -431,10 +428,10 @@ void MultiDiskAdaptor::writeData(const unsigned char* data, size_t len,
   for(DiskWriterEntries::const_iterator i = first; i != diskWriterEntries.end(); ++i) {
     size_t writeLength = calculateLength(*i, fileOffset, rem);
 
-    openIfNot(*i, &DiskWriterEntry::openFile, storeDir);
+    openIfNot(*i, &DiskWriterEntry::openFile);
 
     if(!(*i)->isOpen()) {
-      throwOnDiskWriterNotOpened(*i, offset+(len-rem), storeDir);
+      throwOnDiskWriterNotOpened(*i, offset+(len-rem));
     }
 
     (*i)->getDiskWriter()->writeData(data+(len-rem), writeLength, fileOffset);
@@ -456,10 +453,10 @@ ssize_t MultiDiskAdaptor::readData(unsigned char* data, size_t len, off_t offset
   for(DiskWriterEntries::const_iterator i = first; i != diskWriterEntries.end(); ++i) {
     size_t readLength = calculateLength(*i, fileOffset, rem);
 
-    openIfNot(*i, &DiskWriterEntry::openFile, storeDir);
+    openIfNot(*i, &DiskWriterEntry::openFile);
 
     if(!(*i)->isOpen()) {
-      throwOnDiskWriterNotOpened(*i, offset+(len-rem), storeDir);
+      throwOnDiskWriterNotOpened(*i, offset+(len-rem));
     }
 
     totalReadLength +=
@@ -481,7 +478,7 @@ bool MultiDiskAdaptor::fileExists()
   // This method could be called before opening files.
   for(std::deque<SharedHandle<FileEntry> >::iterator i =
 	fileEntries.begin(); i != fileEntries.end(); ++i) {
-    if(File(storeDir+"/"+(*i)->getPath()).exists()) {
+    if(File((*i)->getPath()).exists()) {
       return true;
     }
   }
@@ -494,7 +491,7 @@ uint64_t MultiDiskAdaptor::size()
   uint64_t size = 0;
   for(DiskWriterEntries::const_iterator itr = diskWriterEntries.begin();
       itr != diskWriterEntries.end(); ++itr) {
-    openIfNot(*itr, &DiskWriterEntry::openFile, storeDir);
+    openIfNot(*itr, &DiskWriterEntry::openFile);
     size += (*itr)->size();
   }
   return size;
@@ -536,9 +533,9 @@ void MultiDiskAdaptor::cutTrailingGarbage()
   for(std::deque<SharedHandle<DiskWriterEntry> >::const_iterator i =
 	diskWriterEntries.begin(); i != diskWriterEntries.end(); ++i) {
     uint64_t length = (*i)->getFileEntry()->getLength();
-    if(File((*i)->getFilePath(storeDir)).size() > length) {
+    if(File((*i)->getFilePath()).size() > length) {
       // We need open file before calling DiskWriter::truncate(uint64_t)
-      openIfNot(*i, &DiskWriterEntry::openFile, storeDir);
+      openIfNot(*i, &DiskWriterEntry::openFile);
       (*i)->getDiskWriter()->truncate(length);
     }
   }
@@ -555,7 +552,7 @@ size_t MultiDiskAdaptor::utime(const Time& actime, const Time& modtime)
   for(std::deque<SharedHandle<FileEntry> >::const_iterator i =
 	fileEntries.begin(); i != fileEntries.end(); ++i) {
     if((*i)->isRequested()) {
-      File f(storeDir+"/"+(*i)->getPath());
+      File f((*i)->getPath());
       if(f.isFile() && f.utime(actime, modtime)) {
 	++numOK;
       }
@@ -570,9 +567,4 @@ MultiDiskAdaptor::getDiskWriterEntries() const
   return diskWriterEntries;
 }
 
-const std::string& MultiDiskAdaptor::getStoreDir() const
-{
-  return storeDir;
-}
-
 } // namespace aria2

+ 7 - 10
src/MultiDiskAdaptor.h

@@ -55,19 +55,19 @@ public:
 
   ~DiskWriterEntry();
 
-  std::string getFilePath(const std::string& storeDir) const;
+  const std::string& getFilePath() const;
 
-  void initAndOpenFile(const std::string& storeDir);
+  void initAndOpenFile();
 
-  void openFile(const std::string& storeDir);
+  void openFile();
 
-  void openExistingFile(const std::string& storeDir);
+  void openExistingFile();
 
   void closeFile();
 
   bool isOpen() const;
 
-  bool fileExists(const std::string& storeDir);
+  bool fileExists();
 
   uint64_t size() const;
 
@@ -115,13 +115,12 @@ private:
 
   void resetDiskWriterEntries();
 
-  void mkdir(const std::string& storeDir) const;
+  void mkdir() const;
 
   std::string getTopDirPath() const;
 
   void openIfNot(const SharedHandle<DiskWriterEntry>& entry,
-		 void (DiskWriterEntry::*f)(const std::string&),
-		 const std::string& storeDir);
+		 void (DiskWriterEntry::*f)());
  
   static const size_t DEFAULT_MAX_OPEN_FILES = 100;
 
@@ -198,8 +197,6 @@ public:
 
   const std::deque<SharedHandle<DiskWriterEntry> >&
   getDiskWriterEntries() const;
-
-  const std::string& getStoreDir() const;
 };
 
 typedef SharedHandle<MultiDiskAdaptor> MultiDiskAdaptorHandle;

+ 1 - 2
src/MultiFileAllocationIterator.cc

@@ -58,8 +58,7 @@ void MultiFileAllocationIterator::allocateChunk()
     _entries.pop_front();
     FileEntryHandle fileEntry = entry->getFileEntry();
     // Open file before calling DiskWriterEntry::size()
-    _diskAdaptor->openIfNot(entry, &DiskWriterEntry::openFile,
-			    _diskAdaptor->getStoreDir());
+    _diskAdaptor->openIfNot(entry, &DiskWriterEntry::openFile);
     entry->enableDirectIO();
     if(entry->needsFileAllocation() && entry->size() < fileEntry->getLength()) {
       // Calling private function of MultiDiskAdaptor.

+ 2 - 3
src/RequestGroup.cc

@@ -525,11 +525,10 @@ bool RequestGroup::tryAutoFileRenaming()
 
   for(unsigned int i = 1; i < 10000; ++i) {
     File newfile(filepath+"."+Util::uitos(i));
-    std::string newFilename = newfile.getBasename();
-    tempCtx->setUFilename(newFilename);
+    tempCtx->setUFilename(newfile.getPath());
     tempInfoFile.updateFilename();
     if(!newfile.exists() || (newfile.exists() && tempInfoFile.exists())) {
-      ctx->setUFilename(newFilename);
+      ctx->setUFilename(newfile.getPath());
       return true;
     }
   }

+ 2 - 2
src/SingleFileDownloadContext.cc

@@ -59,7 +59,7 @@ void SingleFileDownloadContext::updateFileEntry()
   } else if(!_filename.empty()) {
     _fileEntry->setPath(_filename);
   } else {
-    _fileEntry->setPath(DEFAULT_FILENAME);
+    _fileEntry->setPath("");
   }
 }
 
@@ -94,7 +94,7 @@ size_t SingleFileDownloadContext::getNumPieces() const
 
 std::string SingleFileDownloadContext::getActualBasePath() const
 {
-  return _dir+"/"+_fileEntry->getPath();
+  return _fileEntry->getPath();
 }
 
 void SingleFileDownloadContext::setTotalLength(uint64_t totalLength)

+ 3 - 6
src/SingleFileDownloadContext.h

@@ -46,14 +46,11 @@ class SingleFileDownloadContext:public DownloadContext
 {
 private:
   size_t _pieceLength;
-  /**
-   * Actual file path is _dir + _filename.
-   * If _ufilename is not zero-length string, then _dir + _ufilename.
-   */
   SharedHandle<FileEntry> _fileEntry;
   /**
-   * _filename and _ufilename may contains directory path name.
-   * So usr/local/aria2c is acceptable here.
+   * _filename and _ufilename may contains directory path name.  So
+   * /usr/local/aria2c is acceptable here.  These should be complete
+   * file path.
    */
   std::string _filename;
   std::string _ufilename;

+ 4 - 3
src/download_helper.cc

@@ -101,8 +101,9 @@ static SharedHandle<RequestGroup> createRequestGroup
     (new SingleFileDownloadContext(op->getAsInt(PREF_SEGMENT_SIZE),
 				   0,
 				   A2STR::NIL,
-				   useOutOption?
-				   requestOption.get(PREF_OUT):A2STR::NIL));
+				   useOutOption&&!requestOption.blank(PREF_OUT)?
+				   requestOption.get(PREF_DIR)+"/"+requestOption.get(PREF_OUT):A2STR::NIL));
+
   dctx->setDir(requestOption.get(PREF_DIR));
   rg->setDownloadContext(dctx);
   return rg;
@@ -119,11 +120,11 @@ createBtRequestGroup(const std::string& torrentFilePath,
 {
   SharedHandle<RequestGroup> rg(new RequestGroup(op, auxUris));
   SharedHandle<DefaultBtContext> btContext(new DefaultBtContext());
+  btContext->setDir(requestOption.get(PREF_DIR));
   btContext->load(torrentFilePath);// may throw exception
   if(op->defined(PREF_PEER_ID_PREFIX)) {
     btContext->setPeerIdPrefix(op->get(PREF_PEER_ID_PREFIX));
   }
-  btContext->setDir(requestOption.get(PREF_DIR));
   btContext->setFileFilter
     (Util::parseIntRange(requestOption.get(PREF_SELECT_FILE)));
   std::istringstream indexOutIn(requestOption.get(PREF_INDEX_OUT));

+ 1 - 1
test/BtDependencyTest.cc

@@ -29,7 +29,7 @@ class BtDependencyTest:public CppUnit::TestFixture {
   {
     SharedHandle<RequestGroup> dependant(new RequestGroup(option, std::deque<std::string>()));
     SharedHandle<SingleFileDownloadContext> dctx
-      (new SingleFileDownloadContext(0, 0, "outfile.path"));
+      (new SingleFileDownloadContext(0, 0, "/tmp/outfile.path"));
     dctx->setDir("/tmp");
     dependant->setDownloadContext(dctx);
     return dependant;

+ 20 - 25
test/CopyDiskAdaptorTest.cc

@@ -28,22 +28,19 @@ CPPUNIT_TEST_SUITE_REGISTRATION( CopyDiskAdaptorTest );
 
 void CopyDiskAdaptorTest::testUtime()
 {
-  std::string storeDir = "/tmp";
-  std::string topDir = "aria2_CopyDiskAdaptorTest_testUtime";
-  std::string prefix = storeDir+"/"+topDir;
+  std::string storeDir = "/tmp/aria2_CopyDiskAdaptorTest_testUtime";
   SharedHandle<FileEntry> entries[] = {
-    SharedHandle<FileEntry>(new FileEntry("requested", 10, 0)),
-    SharedHandle<FileEntry>(new FileEntry("notFound", 10, 10)),
-    SharedHandle<FileEntry>(new FileEntry("notRequested", 10, 20)),
-    SharedHandle<FileEntry>(new FileEntry("notExtracted", 10, 30)),
-    SharedHandle<FileEntry>(new FileEntry("anotherRequested", 10, 40)),
+    SharedHandle<FileEntry>(new FileEntry(storeDir+"/requested", 10, 0)),
+    SharedHandle<FileEntry>(new FileEntry(storeDir+"/notFound", 10, 10)),
+    SharedHandle<FileEntry>(new FileEntry(storeDir+"/notRequested", 10, 20)),
+    SharedHandle<FileEntry>(new FileEntry(storeDir+"/notExtracted", 10, 30)),
+    SharedHandle<FileEntry>(new FileEntry(storeDir+"/anotherRequested", 10, 40)),
   };
 
   std::deque<SharedHandle<FileEntry> > fileEntries
     (&entries[0], &entries[arrayLength(entries)]);
   CopyDiskAdaptor adaptor;
   adaptor.setStoreDir(storeDir);
-  adaptor.setTopDir(topDir);
   adaptor.setFileEntries(fileEntries);
 
   entries[0]->setExtracted(true);
@@ -53,11 +50,11 @@ void CopyDiskAdaptorTest::testUtime()
   
   entries[2]->setRequested(false);
 
-  createFile(prefix+"/"+entries[0]->getPath(), entries[0]->getLength());
-  File(prefix+"/"+entries[1]->getPath()).remove();
-  createFile(prefix+"/"+entries[2]->getPath(), entries[2]->getLength());
-  createFile(prefix+"/"+entries[3]->getPath(), entries[3]->getLength());
-  createFile(prefix+"/"+entries[4]->getPath(), entries[4]->getLength());
+  createFile(entries[0]->getPath(), entries[0]->getLength());
+  File(entries[1]->getPath()).remove();
+  createFile(entries[2]->getPath(), entries[2]->getLength());
+  createFile(entries[3]->getPath(), entries[3]->getLength());
+  createFile(entries[4]->getPath(), entries[4]->getLength());
 
   time_t atime = (time_t) 100000;
   time_t mtime = (time_t) 200000;
@@ -65,19 +62,17 @@ void CopyDiskAdaptorTest::testUtime()
   CPPUNIT_ASSERT_EQUAL((size_t)2, adaptor.utime(Time(atime), Time(mtime)));
   
   CPPUNIT_ASSERT_EQUAL((time_t)mtime,
-		       File(prefix+"/"+entries[0]->getPath())
-		       .getModifiedTime().getTime());
+		       File(entries[0]->getPath()).getModifiedTime().getTime());
 
   CPPUNIT_ASSERT_EQUAL((time_t)mtime,
-		       File(prefix+"/"+entries[4]->getPath())
-		       .getModifiedTime().getTime());
-
-  CPPUNIT_ASSERT((time_t)mtime != File(prefix+"/"+entries[1]->getPath())
-		 .getModifiedTime().getTime());
-  CPPUNIT_ASSERT((time_t)mtime != File(prefix+"/"+entries[2]->getPath())
-		 .getModifiedTime().getTime());
-  CPPUNIT_ASSERT((time_t)mtime != File(prefix+"/"+entries[3]->getPath())
-		 .getModifiedTime().getTime());
+		       File(entries[4]->getPath()).getModifiedTime().getTime());
+
+  CPPUNIT_ASSERT((time_t)mtime !=
+		 File(entries[1]->getPath()).getModifiedTime().getTime());
+  CPPUNIT_ASSERT((time_t)mtime !=
+		 File(entries[2]->getPath()).getModifiedTime().getTime());
+  CPPUNIT_ASSERT((time_t)mtime !=
+		 File(entries[3]->getPath()).getModifiedTime().getTime());
 
 }
 

+ 2 - 2
test/DefaultBtContextTest.cc

@@ -126,7 +126,7 @@ void DefaultBtContextTest::testGetFileEntriesSingle() {
   std::deque<SharedHandle<FileEntry> >::iterator itr = fileEntries.begin();
 
   SharedHandle<FileEntry> fileEntry1 = *itr;
-  CPPUNIT_ASSERT_EQUAL(std::string("aria2-0.8.2.tar.bz2"),
+  CPPUNIT_ASSERT_EQUAL(std::string("./aria2-0.8.2.tar.bz2"),
 		       fileEntry1->getPath());
 }
 
@@ -319,7 +319,7 @@ void DefaultBtContextTest::testGetFileEntries_singleFileUrlList() {
   CPPUNIT_ASSERT_EQUAL((size_t)1, fileEntries.size());
 
   SharedHandle<FileEntry> fileEntry1 = fileEntries.front();
-  CPPUNIT_ASSERT_EQUAL(std::string("aria2.tar.bz2"),
+  CPPUNIT_ASSERT_EQUAL(std::string("./aria2.tar.bz2"),
 		       fileEntry1->getPath());
   std::deque<std::string> uris1 = fileEntry1->getAssociatedUris();
   CPPUNIT_ASSERT_EQUAL((size_t)1, uris1.size());

+ 7 - 6
test/DefaultBtProgressInfoFileTest.cc

@@ -70,6 +70,7 @@ public:
   
     _btContext.reset(new MockBtContext());
     _btContext->setInfoHash(infoHash);
+    _btContext->setDir(_option->get(PREF_DIR));
     _peerStorage.reset(new MockPeerStorage());
     _btRuntime.reset(new BtRuntime());
 #endif // ENABLE_BITTORRENT
@@ -332,7 +333,7 @@ void DefaultBtProgressInfoFileTest::testLoad_nonBt_compat()
   initializeMembers(1024, 81920);
 
   SharedHandle<SingleFileDownloadContext> dctx
-    (new SingleFileDownloadContext(1024, 81920, "load-nonBt"));
+    (new SingleFileDownloadContext(1024, 81920, "./load-nonBt"));
   
   DefaultBtProgressInfoFile infoFile(dctx, _pieceStorage, _option.get());
 
@@ -377,7 +378,7 @@ void DefaultBtProgressInfoFileTest::testLoad_nonBt()
   initializeMembers(1024, 81920);
 
   SharedHandle<SingleFileDownloadContext> dctx
-    (new SingleFileDownloadContext(1024, 81920, "load-nonBt-v0001"));
+    (new SingleFileDownloadContext(1024, 81920, "./load-nonBt-v0001"));
   
   DefaultBtProgressInfoFile infoFile(dctx, _pieceStorage, _option.get());
 
@@ -422,7 +423,7 @@ void DefaultBtProgressInfoFileTest::testLoad_nonBt_pieceLengthShorter()
   _option->put(PREF_ALLOW_PIECE_LENGTH_CHANGE, V_TRUE);
 
   SharedHandle<SingleFileDownloadContext> dctx
-    (new SingleFileDownloadContext(512, 81920, "load-nonBt-v0001"));
+    (new SingleFileDownloadContext(512, 81920, "./load-nonBt-v0001"));
 
   DefaultBtProgressInfoFile infoFile(dctx, _pieceStorage, _option.get());
 
@@ -447,7 +448,7 @@ void DefaultBtProgressInfoFileTest::testSave_nonBt()
   initializeMembers(1024, 81920);
 
   SharedHandle<SingleFileDownloadContext> dctx
-    (new SingleFileDownloadContext(1024, 81920, "save-temp"));
+    (new SingleFileDownloadContext(1024, 81920, "./save-temp"));
 
   _bitfield->setAllBit();
   _bitfield->unsetBit(79);
@@ -554,7 +555,7 @@ void DefaultBtProgressInfoFileTest::testSave_nonBt()
 void DefaultBtProgressInfoFileTest::testUpdateFilename()
 {
   SharedHandle<SingleFileDownloadContext> dctx
-    (new SingleFileDownloadContext(1024, 81920, "file1"));
+    (new SingleFileDownloadContext(1024, 81920, "./file1"));
 
   DefaultBtProgressInfoFile infoFile(dctx, SharedHandle<MockPieceStorage>(), 0);
 #ifdef ENABLE_BITTORRENT
@@ -564,7 +565,7 @@ void DefaultBtProgressInfoFileTest::testUpdateFilename()
 
   CPPUNIT_ASSERT_EQUAL(std::string("./file1.aria2"), infoFile.getFilename());
 
-  dctx->setUFilename("file1.1");
+  dctx->setUFilename("./file1.1");
 
   CPPUNIT_ASSERT_EQUAL(std::string("./file1.aria2"), infoFile.getFilename());
 

+ 3 - 3
test/DirectDiskAdaptorTest.cc

@@ -29,9 +29,9 @@ void DirectDiskAdaptorTest::testCutTrailingGarbage()
 {
   std::string dir = "/tmp";
   SharedHandle<FileEntry> entry
-    (new FileEntry("aria2_DirectDiskAdaptorTest_testCutTrailingGarbage",
+    (new FileEntry(dir+"/aria2_DirectDiskAdaptorTest_testCutTrailingGarbage",
 		   256, 0));
-  createFile(dir+"/"+entry->getPath(), entry->getLength()+100);
+  createFile(entry->getPath(), entry->getLength()+100);
 
   std::deque<SharedHandle<FileEntry> > fileEntries;
   fileEntries.push_back(entry);
@@ -46,7 +46,7 @@ void DirectDiskAdaptorTest::testCutTrailingGarbage()
   adaptor.cutTrailingGarbage();
 
   CPPUNIT_ASSERT_EQUAL((uint64_t)entry->getLength(),
-		       File(dir+"/"+entry->getPath()).size());
+		       File(entry->getPath()).size());
 }
 
 } // namespace aria2

+ 2 - 5
test/DownloadHelperTest.cc

@@ -144,11 +144,8 @@ void DownloadHelperTest::testCreateRequestGroupForUri()
 			 alphaGroup->getNumConcurrentCommand());
     SharedHandle<DownloadContext> alphaCtx = alphaGroup->getDownloadContext();
     CPPUNIT_ASSERT_EQUAL(std::string("/tmp"), alphaCtx->getDir());
-    // See the value of PREF_OUT is not used as a file name.
-    CPPUNIT_ASSERT_EQUAL(std::string("/tmp/index.html"),
-			 alphaCtx->getActualBasePath());
-
-
+    // See filename is not assigned yet
+    CPPUNIT_ASSERT_EQUAL(std::string(""), alphaCtx->getActualBasePath());
   }
 }
 

+ 5 - 6
test/FileEntryTest.cc

@@ -19,17 +19,16 @@ CPPUNIT_TEST_SUITE_REGISTRATION( FileEntryTest );
 
 void FileEntryTest::testSetupDir()
 {
-  std::string topDir = "/tmp";
-  std::string dir = "aria2-FileEntryTest-testSetupDir";
+  std::string dir = "/tmp/aria2-FileEntryTest-testSetupDir";
   std::string filename = "filename";
-  std::string path = topDir+"/"+dir+"/"+filename;
-  File d(topDir+"/"+dir);
+  std::string path = dir+"/"+filename;
+  File d(dir);
   if(d.exists()) {
     CPPUNIT_ASSERT(d.remove());
   }
   CPPUNIT_ASSERT(!d.exists());
-  FileEntry fileEntry(dir+"/"+filename, 0, 0);
-  fileEntry.setupDir(topDir);
+  FileEntry fileEntry(path, 0, 0);
+  fileEntry.setupDir();
   CPPUNIT_ASSERT(d.isDir());
   File f(path);
   CPPUNIT_ASSERT(!f.exists());

+ 20 - 29
test/MultiDiskAdaptorTest.cc

@@ -373,23 +373,19 @@ void MultiDiskAdaptorTest::testReadData() {
 void MultiDiskAdaptorTest::testCutTrailingGarbage()
 {
   std::string dir = "/tmp";
-  std::string topDir = ".";
-  std::string topDirPath = dir+"/"+topDir;
   std::string prefix = "aria2_MultiDiskAdaptorTest_testCutTrailingGarbage_";
   SharedHandle<FileEntry> entries[] = {
-    SharedHandle<FileEntry>(new FileEntry(prefix+"1", 256, 0)),
-    SharedHandle<FileEntry>(new FileEntry(prefix+"2", 512, 256))
+    SharedHandle<FileEntry>(new FileEntry(dir+"/"+prefix+"1", 256, 0)),
+    SharedHandle<FileEntry>(new FileEntry(dir+"/"+prefix+"2", 512, 256))
   };
   for(size_t i = 0; i < arrayLength(entries); ++i) {
-    createFile(topDirPath+"/"+entries[i]->getPath(),
-	       entries[i]->getLength()+100);
+    createFile(entries[i]->getPath(), entries[i]->getLength()+100);
   }
   std::deque<SharedHandle<FileEntry> > fileEntries
     (&entries[0], &entries[arrayLength(entries)]);
   
   MultiDiskAdaptor adaptor;
   adaptor.setStoreDir(dir);
-  adaptor.setTopDir(topDir);
   adaptor.setFileEntries(fileEntries);
   adaptor.setMaxOpenFiles(1);
   adaptor.setPieceLength(1);
@@ -399,30 +395,27 @@ void MultiDiskAdaptorTest::testCutTrailingGarbage()
   adaptor.cutTrailingGarbage();
 
   CPPUNIT_ASSERT_EQUAL((uint64_t)256,
-		       File(topDirPath+"/"+entries[0]->getPath()).size());
+		       File(entries[0]->getPath()).size());
   CPPUNIT_ASSERT_EQUAL((uint64_t)512,
-		       File(topDirPath+"/"+entries[1]->getPath()).size());
+		       File(entries[1]->getPath()).size());
 }
 
 void MultiDiskAdaptorTest::testSize()
 {
   std::string dir = "/tmp";
-  std::string topDir = ".";
-  std::string topDirPath = dir+"/"+topDir;
   std::string prefix = "aria2_MultiDiskAdaptorTest_testSize_";
   SharedHandle<FileEntry> entries[] = {
-    SharedHandle<FileEntry>(new FileEntry(prefix+"1", 1, 0)),
-    SharedHandle<FileEntry>(new FileEntry(prefix+"2", 1, 1))
+    SharedHandle<FileEntry>(new FileEntry(dir+"/"+prefix+"1", 1, 0)),
+    SharedHandle<FileEntry>(new FileEntry(dir+"/"+prefix+"2", 1, 1))
   };
   for(size_t i = 0; i < arrayLength(entries); ++i) {
-    createFile(topDirPath+"/"+entries[i]->getPath(), entries[i]->getLength());
+    createFile(entries[i]->getPath(), entries[i]->getLength());
   }
   std::deque<SharedHandle<FileEntry> > fileEntries
     (&entries[0], &entries[arrayLength(entries)]);
   
   MultiDiskAdaptor adaptor;
   adaptor.setStoreDir(dir);
-  adaptor.setTopDir(topDir);
   adaptor.setFileEntries(fileEntries);
   adaptor.setMaxOpenFiles(1);
   adaptor.setPieceLength(1);
@@ -436,16 +429,16 @@ void MultiDiskAdaptorTest::testUtime()
 {
   std::string storeDir = "/tmp/aria2_MultiDiskAdaptorTest_testUtime";
   SharedHandle<FileEntry> entries[] = {
-    SharedHandle<FileEntry>(new FileEntry("requested", 0, 0)),
-    SharedHandle<FileEntry>(new FileEntry("notFound", 0, 0)),
-    SharedHandle<FileEntry>(new FileEntry("notRequested", 0, 0)),
-    SharedHandle<FileEntry>(new FileEntry("anotherRequested", 0, 0)),
+    SharedHandle<FileEntry>(new FileEntry(storeDir+"/requested", 0, 0)),
+    SharedHandle<FileEntry>(new FileEntry(storeDir+"/notFound", 0, 0)),
+    SharedHandle<FileEntry>(new FileEntry(storeDir+"/notRequested", 0, 0)),
+    SharedHandle<FileEntry>(new FileEntry(storeDir+"/anotherRequested", 0, 0)),
   };
 
-  createFile(storeDir+"/"+entries[0]->getPath(), entries[0]->getLength());
-  File(storeDir+"/"+entries[1]->getPath()).remove();
-  createFile(storeDir+"/"+entries[2]->getPath(), entries[2]->getLength());
-  createFile(storeDir+"/"+entries[3]->getPath(), entries[3]->getLength());
+  createFile(entries[0]->getPath(), entries[0]->getLength());
+  File(entries[1]->getPath()).remove();
+  createFile(entries[2]->getPath(), entries[2]->getLength());
+  createFile(entries[3]->getPath(), entries[3]->getLength());
 
   entries[2]->setRequested(false);
 
@@ -461,15 +454,13 @@ void MultiDiskAdaptorTest::testUtime()
   CPPUNIT_ASSERT_EQUAL((size_t)2, adaptor.utime(Time(atime), Time(mtime)));
   
   CPPUNIT_ASSERT_EQUAL((time_t)mtime,
-		       File(storeDir+"/"+entries[0]->getPath())
-		       .getModifiedTime().getTime());
+		       File(entries[0]->getPath()).getModifiedTime().getTime());
 
   CPPUNIT_ASSERT_EQUAL((time_t)mtime,
-		       File(storeDir+"/"+entries[3]->getPath())
-		       .getModifiedTime().getTime());
+		       File(entries[3]->getPath()).getModifiedTime().getTime());
 
-  CPPUNIT_ASSERT((time_t)mtime != File(storeDir+"/"+entries[2]->getPath())
-		 .getModifiedTime().getTime());
+  CPPUNIT_ASSERT((time_t)mtime !=
+		 File(entries[2]->getPath()).getModifiedTime().getTime());
 }
 
 } // namespace aria2

+ 41 - 45
test/MultiFileAllocationIteratorTest.cc

@@ -35,18 +35,21 @@ CPPUNIT_TEST_SUITE_REGISTRATION( MultiFileAllocationIteratorTest );
 
 void MultiFileAllocationIteratorTest::testMakeDiskWriterEntries()
 {
+  std::string storeDir = "/tmp/aria2_MultiFileAllocationIteratorTest"
+    "_testMakeDiskWriterEntries";
+
   SharedHandle<FileEntry> fs[] = {
-    SharedHandle<FileEntry>(new FileEntry("file1", 1536, 0)),
-    SharedHandle<FileEntry>(new FileEntry("file2", 2048, 1536)),// req no
-    SharedHandle<FileEntry>(new FileEntry("file3", 1024, 3584)),
-    SharedHandle<FileEntry>(new FileEntry("file4", 1024, 4608)),// req no
-    SharedHandle<FileEntry>(new FileEntry("file5", 1024, 5632)),// req no
-    SharedHandle<FileEntry>(new FileEntry("file6", 1024, 6656)),// req no
-    SharedHandle<FileEntry>(new FileEntry("file7",  256, 7680)),// req no
-    SharedHandle<FileEntry>(new FileEntry("file8",  255, 7936)),
-    SharedHandle<FileEntry>(new FileEntry("file9", 1025, 8191)),// req no
-    SharedHandle<FileEntry>(new FileEntry("fileA", 1024, 9216)),// req no
-    SharedHandle<FileEntry>(new FileEntry("fileB", 1024, 10240)),
+    SharedHandle<FileEntry>(new FileEntry(storeDir+"/file1", 1536, 0)),
+    SharedHandle<FileEntry>(new FileEntry(storeDir+"/file2", 2048, 1536)),// req no
+    SharedHandle<FileEntry>(new FileEntry(storeDir+"/file3", 1024, 3584)),
+    SharedHandle<FileEntry>(new FileEntry(storeDir+"/file4", 1024, 4608)),// req no
+    SharedHandle<FileEntry>(new FileEntry(storeDir+"/file5", 1024, 5632)),// req no
+    SharedHandle<FileEntry>(new FileEntry(storeDir+"/file6", 1024, 6656)),// req no
+    SharedHandle<FileEntry>(new FileEntry(storeDir+"/file7",  256, 7680)),// req no
+    SharedHandle<FileEntry>(new FileEntry(storeDir+"/file8",  255, 7936)),
+    SharedHandle<FileEntry>(new FileEntry(storeDir+"/file9", 1025, 8191)),// req no
+    SharedHandle<FileEntry>(new FileEntry(storeDir+"/fileA", 1024, 9216)),// req no
+    SharedHandle<FileEntry>(new FileEntry(storeDir+"/fileB", 1024, 10240)),
   };
   fs[1]->setRequested(false); // file2
   fs[3]->setRequested(false); // file4
@@ -56,8 +59,6 @@ void MultiFileAllocationIteratorTest::testMakeDiskWriterEntries()
   fs[8]->setRequested(false); // file9
   fs[9]->setRequested(false); // fileA
 
-  std::string storeDir = "/tmp/aria2_MultiFileAllocationIteratorTest"
-    "_testMakeDiskWriterEntries";
 
   // create empty file4
   createFile(storeDir+std::string("/file4"), 0);
@@ -79,57 +80,57 @@ void MultiFileAllocationIteratorTest::testMakeDiskWriterEntries()
 
   // file1
   CPPUNIT_ASSERT_EQUAL(storeDir+std::string("/file1"),
-		       entries[0]->getFilePath(storeDir));
+		       entries[0]->getFilePath());
   CPPUNIT_ASSERT(entries[0]->needsFileAllocation());
   CPPUNIT_ASSERT(!entries[0]->getDiskWriter().isNull());
   // file2
   CPPUNIT_ASSERT_EQUAL(storeDir+std::string("/file2"),
-		       entries[1]->getFilePath(storeDir));
+		       entries[1]->getFilePath());
   CPPUNIT_ASSERT(entries[1]->needsFileAllocation());
   CPPUNIT_ASSERT(!entries[1]->getDiskWriter().isNull());
   // file3
   CPPUNIT_ASSERT_EQUAL(storeDir+std::string("/file3"),
-		       entries[2]->getFilePath(storeDir));
+		       entries[2]->getFilePath());
   CPPUNIT_ASSERT(entries[2]->needsFileAllocation());
   CPPUNIT_ASSERT(!entries[2]->getDiskWriter().isNull());
   // file4, diskWriter is not null, because file exists.
   CPPUNIT_ASSERT_EQUAL(storeDir+std::string("/file4"),
-		       entries[3]->getFilePath(storeDir));
+		       entries[3]->getFilePath());
   CPPUNIT_ASSERT(!entries[3]->needsFileAllocation());
   CPPUNIT_ASSERT(!entries[3]->getDiskWriter().isNull());
   // file5
   CPPUNIT_ASSERT_EQUAL(storeDir+std::string("/file5"),
-		       entries[4]->getFilePath(storeDir));
+		       entries[4]->getFilePath());
   CPPUNIT_ASSERT(!entries[4]->needsFileAllocation());
   CPPUNIT_ASSERT(entries[4]->getDiskWriter().isNull());
   // file6
   CPPUNIT_ASSERT_EQUAL(storeDir+std::string("/file6"),
-		       entries[5]->getFilePath(storeDir));
+		       entries[5]->getFilePath());
   CPPUNIT_ASSERT(entries[5]->needsFileAllocation());
   CPPUNIT_ASSERT(!entries[5]->getDiskWriter().isNull());
   // file7
   CPPUNIT_ASSERT_EQUAL(storeDir+std::string("/file7"),
-		       entries[6]->getFilePath(storeDir));
+		       entries[6]->getFilePath());
   CPPUNIT_ASSERT(entries[6]->needsFileAllocation());
   CPPUNIT_ASSERT(!entries[6]->getDiskWriter().isNull());
   // file8
   CPPUNIT_ASSERT_EQUAL(storeDir+std::string("/file8"),
-		       entries[7]->getFilePath(storeDir));
+		       entries[7]->getFilePath());
   CPPUNIT_ASSERT(entries[7]->needsFileAllocation());
   CPPUNIT_ASSERT(!entries[7]->getDiskWriter().isNull());
   // file9
   CPPUNIT_ASSERT_EQUAL(storeDir+std::string("/file9"),
-		       entries[8]->getFilePath(storeDir));
+		       entries[8]->getFilePath());
   CPPUNIT_ASSERT(!entries[8]->needsFileAllocation());
   CPPUNIT_ASSERT(!entries[8]->getDiskWriter().isNull());
   // fileA
   CPPUNIT_ASSERT_EQUAL(storeDir+std::string("/fileA"),
-		       entries[9]->getFilePath(storeDir));
+		       entries[9]->getFilePath());
   CPPUNIT_ASSERT(!entries[9]->needsFileAllocation());
   CPPUNIT_ASSERT(entries[9]->getDiskWriter().isNull());
   // fileB
   CPPUNIT_ASSERT_EQUAL(storeDir+std::string("/fileB"),
-		       entries[10]->getFilePath(storeDir));
+		       entries[10]->getFilePath());
   CPPUNIT_ASSERT(entries[10]->needsFileAllocation());
   CPPUNIT_ASSERT(!entries[10]->getDiskWriter().isNull());
 }
@@ -158,32 +159,32 @@ void MultiFileAllocationIteratorTest::testAllocate()
     diskAdaptor->setPieceLength(1);
 
     int64_t offset = 0;
-    SharedHandle<FileEntry> fileEntry1(new FileEntry(fname1,
+    SharedHandle<FileEntry> fileEntry1(new FileEntry(storeDir+"/"+fname1,
 						     length1,
 						     offset));
     offset += length1;
-    SharedHandle<FileEntry> fileEntry2(new FileEntry(fname2,
+    SharedHandle<FileEntry> fileEntry2(new FileEntry(storeDir+"/"+fname2,
 						     length2,
 						     offset));
 
     offset += length2;
-    SharedHandle<FileEntry> fileEntry3(new FileEntry(fname3,
+    SharedHandle<FileEntry> fileEntry3(new FileEntry(storeDir+"/"+fname3,
 						     length3,
 						     offset));
 
     offset += length3;
-    SharedHandle<FileEntry> fileEntry4(new FileEntry(fname4,
+    SharedHandle<FileEntry> fileEntry4(new FileEntry(storeDir+"/"+fname4,
 						     length4,
 						     offset));
     fileEntry4->setRequested(false);
 
     offset += length4;
-    SharedHandle<FileEntry> fileEntry5(new FileEntry(fname5,
+    SharedHandle<FileEntry> fileEntry5(new FileEntry(storeDir+"/"+fname5,
 						     length5,
 						     offset));
 
     offset += length5;
-    SharedHandle<FileEntry> fileEntry6(new FileEntry(fname6,
+    SharedHandle<FileEntry> fileEntry6(new FileEntry(storeDir+"/"+fname6,
 						     length6,
 						     offset));
     fileEntry6->setRequested(false);
@@ -197,13 +198,10 @@ void MultiFileAllocationIteratorTest::testAllocate()
     fs.push_back(fileEntry6);
     diskAdaptor->setFileEntries(fs);
 
-    
-    File(storeDir+"/"+fname1).remove();
-    File(storeDir+"/"+fname2).remove();
-    File(storeDir+"/"+fname3).remove();
-    File(storeDir+"/"+fname4).remove();
-    File(storeDir+"/"+fname5).remove();
-    File(storeDir+"/"+fname6).remove();
+    for(std::deque<SharedHandle<FileEntry> >::const_iterator i = fs.begin();
+	i != fs.end(); ++i) {
+      File((*i)->getPath()).remove();
+    }
 
     // we have to open file first.
     diskAdaptor->initAndOpenFile();
@@ -213,14 +211,12 @@ void MultiFileAllocationIteratorTest::testAllocate()
     while(!itr->finished()) {
       itr->allocateChunk();
     }
-    CPPUNIT_ASSERT_EQUAL((uint64_t)length1, File(storeDir+"/"+fname1).size());
-    CPPUNIT_ASSERT_EQUAL((uint64_t)length2, File(storeDir+"/"+fname2).size());
-    CPPUNIT_ASSERT_EQUAL((uint64_t)length3, File(storeDir+"/"+fname3).size());
-    CPPUNIT_ASSERT(!File(storeDir+"/"+fname4).isFile());
-
-    CPPUNIT_ASSERT_EQUAL((uint64_t)length5, File(storeDir+"/"+fname5).size());
-    CPPUNIT_ASSERT(!File(storeDir+"/"+fname6).isFile());
-
+    CPPUNIT_ASSERT_EQUAL((uint64_t)length1, File(fileEntry1->getPath()).size());
+    CPPUNIT_ASSERT_EQUAL((uint64_t)length2, File(fileEntry2->getPath()).size());
+    CPPUNIT_ASSERT_EQUAL((uint64_t)length3, File(fileEntry3->getPath()).size());
+    CPPUNIT_ASSERT(!File(fileEntry4->getPath()).isFile());
+    CPPUNIT_ASSERT_EQUAL((uint64_t)length5, File(fileEntry5->getPath()).size());
+    CPPUNIT_ASSERT(!File(fileEntry6->getPath()).isFile());
   } catch(Exception& e) {
     CPPUNIT_FAIL(e.stackTrace());
   }

+ 3 - 4
test/RequestGroupTest.cc

@@ -83,8 +83,7 @@ void RequestGroupTest::testRemoveURIWhoseHostnameIs()
 void RequestGroupTest::testGetFilePath()
 {
   SharedHandle<SingleFileDownloadContext> ctx
-    (new SingleFileDownloadContext(1024, 1024, "myfile"));
-  ctx->setDir("/tmp");
+    (new SingleFileDownloadContext(1024, 1024, "/tmp/myfile"));
   Option op;
   std::deque<std::string> uris;
 
@@ -101,8 +100,8 @@ void RequestGroupTest::testGetFilePath()
 void RequestGroupTest::testCreateDownloadResult()
 {
   SharedHandle<SingleFileDownloadContext> ctx
-    (new SingleFileDownloadContext(1024, 1024*1024, "myfile"));
-  ctx->setDir("/tmp");
+    (new SingleFileDownloadContext(1024, 1024*1024, "/tmp/myfile"));
+  //ctx->setDir("/tmp");
   Option op;
   std::deque<std::string> uris;
   uris.push_back("http://first/file");

+ 6 - 5
test/SingleFileDownloadContextTest.cc

@@ -45,13 +45,14 @@ void SingleFileDownloadContextTest::testGetNumPieces()
 void SingleFileDownloadContextTest::testGetActualBasePath()
 {
   SingleFileDownloadContext ctx(0, 0, "");
-  CPPUNIT_ASSERT_EQUAL(std::string("./index.html"), ctx.getActualBasePath());
+  CPPUNIT_ASSERT_EQUAL(std::string(""), ctx.getActualBasePath());
   ctx.setFilename("aria2.tar.bz2");
-  CPPUNIT_ASSERT_EQUAL(std::string("./aria2.tar.bz2"), ctx.getActualBasePath());
-  ctx.setUFilename("aria.tar.bz2");
-  CPPUNIT_ASSERT_EQUAL(std::string("./aria.tar.bz2"), ctx.getActualBasePath());
+  CPPUNIT_ASSERT_EQUAL(std::string("aria2.tar.bz2"), ctx.getActualBasePath());
+  ctx.setUFilename("/t/aria.tar.bz2");
+  CPPUNIT_ASSERT_EQUAL(std::string("/t/aria.tar.bz2"), ctx.getActualBasePath());
   ctx.setDir("/tmp");
-  CPPUNIT_ASSERT_EQUAL(std::string("/tmp/aria.tar.bz2"), ctx.getActualBasePath());
+  // See dir doesn't effect getActualBasePath().
+  CPPUNIT_ASSERT_EQUAL(std::string("/t/aria.tar.bz2"), ctx.getActualBasePath());
 }
 
 } // namespace aria2