update_engine: Fix [Memory|File]Storage partial inconsistency
|Prefs::MemoryStorage| and |Prefs::FileStorage| had inconsistency when
dealing with operations through |StorageInterface|, this change keeps
the implementations more consistent. This keeps the underlying
|StorageInterface| impementations behaving as similar as can be whether
|[Memory|File]Storage| is used.
Passing a namespace to |Prefs::FileStorage| backed |Pref| is no longer
recursive in order to restrict to deleting keys.
To delete all keys within a namespace, callers can use
|Prefs::GetSubKeys(...)| and |Prefs::Delete(...)| accordingly.
BUG=chromium:928805
TEST=FEATURES=test emerge-$B update_engine
Change-Id: I3ea8b51e14b1405ca1cdef66f858a18d124ca0aa
Reviewed-on: https://chromium-review.googlesource.com/c/aosp/platform/system/update_engine/+/2195624
Tested-by: Jae Hoon Kim <kimjae@chromium.org>
Commit-Queue: Jae Hoon Kim <kimjae@chromium.org>
Reviewed-by: Amin Hassani <ahassani@chromium.org>
Reviewed-by: Andrew Lassalle <andrewlassalle@chromium.org>
diff --git a/common/prefs.h b/common/prefs.h
index 0116454..3fc1d89 100644
--- a/common/prefs.h
+++ b/common/prefs.h
@@ -42,6 +42,11 @@
// Returns whether the operation succeeded.
virtual bool GetKey(const std::string& key, std::string* value) const = 0;
+ // Get the keys stored within the namespace. If there are no keys in the
+ // namespace, |keys| will be empty. Returns whether the operation succeeded.
+ virtual bool GetSubKeys(const std::string& ns,
+ std::vector<std::string>* keys) const = 0;
+
// Set the value of the key named |key| to |value| regardless of the
// previous value. Returns whether the operation succeeded.
virtual bool SetKey(const std::string& key, const std::string& value) = 0;
@@ -70,6 +75,9 @@
bool Exists(const std::string& key) const override;
bool Delete(const std::string& key) override;
+ bool GetSubKeys(const std::string& ns,
+ std::vector<std::string>* keys) const override;
+
void AddObserver(const std::string& key,
ObserverInterface* observer) override;
void RemoveObserver(const std::string& key,
@@ -111,6 +119,8 @@
// PrefsBase::StorageInterface overrides.
bool GetKey(const std::string& key, std::string* value) const override;
+ bool GetSubKeys(const std::string& ns,
+ std::vector<std::string>* keys) const override;
bool SetKey(const std::string& key, const std::string& value) override;
bool KeyExists(const std::string& key) const override;
bool DeleteKey(const std::string& key) override;
@@ -149,6 +159,8 @@
// PrefsBase::StorageInterface overrides.
bool GetKey(const std::string& key, std::string* value) const override;
+ bool GetSubKeys(const std::string& ns,
+ std::vector<std::string>* keys) const override;
bool SetKey(const std::string& key, const std::string& value) override;
bool KeyExists(const std::string& key) const override;
bool DeleteKey(const std::string& key) override;