瀏覽代碼

2008-11-14 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>

	Print "[MEMORY]" and filename if a file is not saved in disk and
	just processed in memory. This is the fix for previous comment
	out.
	* src/MemoryBufferPreDownloadHandler.cc
	* src/RequestGroup.cc
	* src/RequestGroup.h
Tatsuhiro Tsujikawa 17 年之前
父節點
當前提交
690340ef02
共有 4 個文件被更改,包括 39 次插入5 次删除
  1. 8 0
      ChangeLog
  2. 1 4
      src/MemoryBufferPreDownloadHandler.cc
  3. 20 1
      src/RequestGroup.cc
  4. 10 0
      src/RequestGroup.h

+ 8 - 0
ChangeLog

@@ -1,3 +1,11 @@
+2008-11-14  Tatsuhiro Tsujikawa  <t-tujikawa@users.sourceforge.net>
+
+	Print "[MEMORY]" and filename if a file is not saved in disk and just
+	processed in memory. This is the fix for previous comment out.
+	* src/MemoryBufferPreDownloadHandler.cc
+	* src/RequestGroup.cc
+	* src/RequestGroup.h
+
 2008-11-14  Tatsuhiro Tsujikawa  <t-tujikawa@users.sourceforge.net>
 
 	Commented out the code which sets virtual directory path "[MEMORY]"

+ 1 - 4
src/MemoryBufferPreDownloadHandler.cc

@@ -49,10 +49,7 @@ void MemoryBufferPreDownloadHandler::execute(RequestGroup* requestGroup)
   requestGroup->setDiskWriterFactory(dwf);
   requestGroup->setFileAllocationEnabled(false);
   requestGroup->setPreLocalFileCheckEnabled(false);
-
-  // TODO to propage direction to save, comment out following 2 lines.
-  //static const std::string DIR_MEMORY("[MEMORY]");
-  //requestGroup->getDownloadContext()->setDir(DIR_MEMORY);
+  requestGroup->markInMemoryDownload();
 }
 
 } // namespace aria2

+ 20 - 1
src/RequestGroup.cc

@@ -125,6 +125,7 @@ RequestGroup::RequestGroup(const Option* option,
   _uriSelector(new InOrderURISelector()),
   _lastModifiedTime(Time::null()),
   _fileNotFoundCount(0),
+  _inMemoryDownload(false),
   _option(option),
   _logger(LogFactory::getInstance())
 {
@@ -892,10 +893,18 @@ DownloadResultHandle RequestGroup::createDownloadResult() const
 	_segmentMan->calculateSessionDownloadLength();
     }
 
+  std::string path;
+  if(inMemoryDownload()) {
+    static const std::string DIR_MEMORY("[MEMORY]");
+    path = DIR_MEMORY+File(getFilePath()).getBasename();
+  } else {
+    path = getFilePath();
+  }
+
   return
     SharedHandle<DownloadResult>
     (new DownloadResult(_gid,
-			getFilePath(),
+			path,
 			getTotalLength(),
 			uris.empty() ? A2STR::NIL:uris.front(),
 			uris.size(),
@@ -1080,4 +1089,14 @@ unsigned int RequestGroup::getNumConcurrentCommand() const
   return _numConcurrentCommand;
 }
 
+void RequestGroup::markInMemoryDownload()
+{
+  _inMemoryDownload = true;
+}
+
+bool RequestGroup::inMemoryDownload() const
+{
+  return _inMemoryDownload;
+}
+
 } // namespace aria2

+ 10 - 0
src/RequestGroup.h

@@ -132,6 +132,10 @@ private:
   WeakHandle<PeerStorage> _peerStorage;
 #endif // ENABLE_BITTORRENT
 
+  // This flag just indicates that the downloaded file is not saved disk but
+  // just sits in memory.
+  bool _inMemoryDownload;
+
   const Option* _option;
 
   Logger* _logger;
@@ -386,6 +390,12 @@ public:
   void updateLastModifiedTime(const Time& time);
 
   void increaseAndValidateFileNotFoundCount();
+
+  // Just set inMemoryDownload flag true.
+  void markInMemoryDownload();
+
+  // Returns inMemoryDownload flag.
+  bool inMemoryDownload() const;
 };
 
 typedef SharedHandle<RequestGroup> RequestGroupHandle;