From 390538d0b5936cbad9bcdff9ec2e04772751a35c Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Sun, 7 Sep 2008 08:29:09 +0000 Subject: [PATCH] 2008-09-07 Tatsuhiro Tsujikawa Fixed the bug that exception is thrown when MultiDiskAdaptor::size() is called if the number of file entries are greater than max open files. * src/AbstractSingleDiskAdaptor.cc * src/AbstractSingleDiskAdaptor.h * src/DiskAdaptor.h * src/MultiDiskAdaptor.cc * src/MultiDiskAdaptor.h * test/MultiDiskAdaptorTest.cc --- ChangeLog | 11 +++++++++++ src/AbstractSingleDiskAdaptor.cc | 2 +- src/AbstractSingleDiskAdaptor.h | 2 +- src/DiskAdaptor.h | 2 +- src/MultiDiskAdaptor.cc | 3 ++- src/MultiDiskAdaptor.h | 2 +- test/MultiDiskAdaptorTest.cc | 30 ++++++++++++++++++++++++++++++ 7 files changed, 47 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 8e7b0029..fa1c50e0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2008-09-07 Tatsuhiro Tsujikawa + + Fixed the bug that exception is thrown when MultiDiskAdaptor::size() is + called if the number of file entries are greater than max open files. + * src/AbstractSingleDiskAdaptor.cc + * src/AbstractSingleDiskAdaptor.h + * src/DiskAdaptor.h + * src/MultiDiskAdaptor.cc + * src/MultiDiskAdaptor.h + * test/MultiDiskAdaptorTest.cc + 2008-09-07 Tatsuhiro Tsujikawa Added a constuctor that receives struct timeval. diff --git a/src/AbstractSingleDiskAdaptor.cc b/src/AbstractSingleDiskAdaptor.cc index 0114a646..ca21b1c6 100644 --- a/src/AbstractSingleDiskAdaptor.cc +++ b/src/AbstractSingleDiskAdaptor.cc @@ -78,7 +78,7 @@ bool AbstractSingleDiskAdaptor::fileExists() return File(getFilePath()).exists(); } -uint64_t AbstractSingleDiskAdaptor::size() const +uint64_t AbstractSingleDiskAdaptor::size() { return diskWriter->size(); } diff --git a/src/AbstractSingleDiskAdaptor.h b/src/AbstractSingleDiskAdaptor.h index aa776a28..36a2ede9 100644 --- a/src/AbstractSingleDiskAdaptor.h +++ b/src/AbstractSingleDiskAdaptor.h @@ -66,7 +66,7 @@ public: virtual bool fileExists(); - virtual uint64_t size() const; + virtual uint64_t size(); virtual void truncate(uint64_t length); diff --git a/src/DiskAdaptor.h b/src/DiskAdaptor.h index ddf562b7..031b588c 100644 --- a/src/DiskAdaptor.h +++ b/src/DiskAdaptor.h @@ -68,7 +68,7 @@ public: virtual std::string getFilePath() = 0; - virtual uint64_t size() const = 0; + virtual uint64_t size() = 0; // optional behavior virtual void truncate(uint64_t length) {} diff --git a/src/MultiDiskAdaptor.cc b/src/MultiDiskAdaptor.cc index 9ce2ecb9..2df1b68d 100644 --- a/src/MultiDiskAdaptor.cc +++ b/src/MultiDiskAdaptor.cc @@ -411,11 +411,12 @@ bool MultiDiskAdaptor::fileExists() } // TODO call DiskWriter::openFile() before calling this function. -uint64_t MultiDiskAdaptor::size() const +uint64_t MultiDiskAdaptor::size() { uint64_t size = 0; for(DiskWriterEntries::const_iterator itr = diskWriterEntries.begin(); itr != diskWriterEntries.end(); ++itr) { + openIfNot(*itr, &DiskWriterEntry::openFile, _cachedTopDirPath); size += (*itr)->size(); } return size; diff --git a/src/MultiDiskAdaptor.h b/src/MultiDiskAdaptor.h index cabd1f20..bc7500f2 100644 --- a/src/MultiDiskAdaptor.h +++ b/src/MultiDiskAdaptor.h @@ -147,7 +147,7 @@ public: return getTopDirPath(); } - virtual uint64_t size() const; + virtual uint64_t size(); virtual SharedHandle fileAllocationIterator(); diff --git a/test/MultiDiskAdaptorTest.cc b/test/MultiDiskAdaptorTest.cc index ca5960f6..295bce55 100644 --- a/test/MultiDiskAdaptorTest.cc +++ b/test/MultiDiskAdaptorTest.cc @@ -17,6 +17,7 @@ class MultiDiskAdaptorTest:public CppUnit::TestFixture { CPPUNIT_TEST(testWriteData); CPPUNIT_TEST(testReadData); CPPUNIT_TEST(testCutTrailingGarbage); + CPPUNIT_TEST(testSize); CPPUNIT_TEST_SUITE_END(); private: SharedHandle adaptor; @@ -31,6 +32,7 @@ public: void testWriteData(); void testReadData(); void testCutTrailingGarbage(); + void testSize(); }; @@ -167,4 +169,32 @@ void MultiDiskAdaptorTest::testCutTrailingGarbage() File(topDirPath+"/"+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 entries[] = { + SharedHandle(new FileEntry(prefix+"1", 1, 0)), + SharedHandle(new FileEntry(prefix+"2", 1, 1)) + }; + for(size_t i = 0; i < arrayLength(entries); ++i) { + createFile(topDirPath+"/"+entries[i]->getPath(), + entries[i]->getLength()); + } + std::deque > fileEntries + (&entries[0], &entries[arrayLength(entries)]); + + MultiDiskAdaptor adaptor; + adaptor.setStoreDir(dir); + adaptor.setTopDir(topDir); + adaptor.setFileEntries(fileEntries); + adaptor.setMaxOpenFiles(1); + + adaptor.openFile(); + + CPPUNIT_ASSERT_EQUAL((uint64_t)2, adaptor.size()); +} + } // namespace aria2