Browse Source

[2378] Check attempt to load past the end

Michal 'vorner' Vaner 12 years ago
parent
commit
8743e25c80

+ 6 - 0
src/lib/datasrc/tests/zone_loader_unittest.cc

@@ -161,6 +161,12 @@ TEST_F(ZoneLoaderTest, copyUnsigned) {
               destination_client_.rrsets_.front());
     EXPECT_EQ("m.root-servers.net. 3600000 IN AAAA 2001:dc3::35\n",
               destination_client_.rrsets_.back());
+
+    // It isn't possible to try again now
+    EXPECT_THROW(loader.load(), isc::InvalidOperation);
+    EXPECT_THROW(loader.loadIncremental(1), isc::InvalidOperation);
+    // Even 0, which should load nothing, returns the error
+    EXPECT_THROW(loader.loadIncremental(0), isc::InvalidOperation);
 }
 
 }

+ 8 - 1
src/lib/datasrc/zone_loader.cc

@@ -32,7 +32,8 @@ ZoneLoader::ZoneLoader(DataSourceClient& destination, const Name& zone_name,
     // Separate the RRsets as that is possibly faster (the data source doesn't
     // have to aggregate them) and also because our limit semantics.
     iterator_(source.getIterator(zone_name, true)),
-    updater_(destination.getUpdater(zone_name, true, false))
+    updater_(destination.getUpdater(zone_name, true, false)),
+    complete_(false)
 {
     // The getIterator should never return NULL. So we check it.
     // Or should we throw instead?
@@ -69,9 +70,15 @@ copyRRsets(const ZoneUpdaterPtr& destination, const ZoneIteratorPtr& source,
 
 bool
 ZoneLoader::loadIncremental(size_t limit) {
+    if (complete_) {
+        isc_throw(isc::InvalidOperation,
+                  "Loading has been completed previously");
+    }
+
     if (iterator_ != ZoneIteratorPtr()) {
         if (copyRRsets(updater_, iterator_, limit)) {
             updater_->commit();
+            complete_ = true;
             return (true);
         } else {
             return (false);

+ 2 - 0
src/lib/datasrc/zone_loader.h

@@ -119,6 +119,8 @@ private:
     const ZoneIteratorPtr iterator_;
     /// \brief The destination zone updater
     const ZoneUpdaterPtr updater_;
+    /// \brief Indicator if loading was completed
+    bool complete_;
 };
 
 }