tools: erase all requested entries from CS in nfdc
This change modifies the behavior of nfdc cs
erase to erase up to the requested count of CS
entries, instead of requiring the user to
continually rerun the command to reach the
desired count of erases.
refs #4744
Change-Id: Ia9b6fa2b4f97769fe6fa911a7b0b5c641ce215dc
diff --git a/tools/nfdc/cs-module.cpp b/tools/nfdc/cs-module.cpp
index 1b9915e..cdaad5a 100644
--- a/tools/nfdc/cs-module.cpp
+++ b/tools/nfdc/cs-module.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2014-2019, Regents of the University of California,
+ * Copyright (c) 2014-2020, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -92,26 +92,42 @@
auto prefix = ctx.args.get<Name>("prefix");
auto count = ctx.args.getOptional<uint64_t>("count");
+ uint64_t numErased = 0;
+ bool wasLimited = false;
+ bool wasSuccessful = true;
+
ControlParameters params;
params.setName(prefix);
- if (count) {
- params.setCount(*count);
+
+ // The cs/erase command can have a limit on the number of CS entries erased in a single operation.
+ // Therefore, we may need to run cs/erase multiple times to achieve the desired number of erases.
+ do {
+ if (count) {
+ params.setCount(*count - numErased);
+ }
+
+ wasSuccessful = false;
+
+ ctx.controller.start<ndn::nfd::CsEraseCommand>(
+ params,
+ [&] (const ControlParameters& resp) {
+ wasSuccessful = true;
+ numErased += resp.getCount();
+ wasLimited = resp.hasCapacity();
+ },
+ ctx.makeCommandFailureHandler("erasing cached Data"),
+ ctx.makeCommandOptions());
+
+ ctx.face.processEvents();
+ } while (wasSuccessful && wasLimited);
+
+ if (wasSuccessful) {
+ text::ItemAttributes ia;
+ ctx.out << "cs-erased "
+ << ia("prefix") << prefix
+ << ia("count") << numErased
+ << '\n';
}
-
- ctx.controller.start<ndn::nfd::CsEraseCommand>(
- params,
- [&] (const ControlParameters& resp) {
- text::ItemAttributes ia;
- ctx.out << "cs-erased "
- << ia("prefix") << resp.getName()
- << ia("count") << resp.getCount()
- << ia("has-more") << text::YesNo{resp.hasCapacity()}
- << '\n';
- },
- ctx.makeCommandFailureHandler("erasing cached Data"),
- ctx.makeCommandOptions());
-
- ctx.face.processEvents();
}
void