summaryrefslogtreecommitdiff
path: root/common/prefs.cc
diff options
context:
space:
mode:
authorAndrew <andrewlassalle@chromium.org>2020-04-07 15:43:07 -0700
committerCommit Bot <commit-bot@chromium.org>2020-05-05 21:05:43 +0000
commit065d78d6963ca13a38ad305bf751b09ec929cf51 (patch)
tree1f526b5f8e363bf08e9abfe43f48b508006a0815 /common/prefs.cc
parentebea33916754d5522ce6489a910b990b119b7174 (diff)
update_engine: Change DLC metadata path
Change the location of the DLC metadata from /var/lib/dlc to /var/lib/update_engine/dlc_prefs/ to make update_engine the owner of metadata. BUG=chromium:912666 TEST=cros_workon_make update_engine --test TEST=install and uninstall DLCs on DUT. Check new prefs path. Change-Id: I75f5506eee1abc834ad89a7cf363f42e384b695b Reviewed-on: https://chromium-review.googlesource.com/c/aosp/platform/system/update_engine/+/2140007 Tested-by: Andrew Lassalle <andrewlassalle@chromium.org> Commit-Queue: Amin Hassani <ahassani@chromium.org> Reviewed-by: Jae Hoon Kim <kimjae@chromium.org> Reviewed-by: Amin Hassani <ahassani@chromium.org>
Diffstat (limited to 'common/prefs.cc')
-rw-r--r--common/prefs.cc33
1 files changed, 31 insertions, 2 deletions
diff --git a/common/prefs.cc b/common/prefs.cc
index 6d86a504..6a330378 100644
--- a/common/prefs.cc
+++ b/common/prefs.cc
@@ -18,9 +18,11 @@
#include <algorithm>
+#include <base/files/file_enumerator.h>
#include <base/files/file_util.h>
#include <base/logging.h>
#include <base/strings/string_number_conversions.h>
+#include <base/strings/string_split.h>
#include <base/strings/string_util.h>
#include "update_engine/common/utils.h"
@@ -29,6 +31,8 @@ using std::string;
namespace chromeos_update_engine {
+const char kKeySeparator = '/';
+
bool PrefsBase::GetString(const string& key, string* value) const {
return storage_->GetKey(key, value);
}
@@ -104,6 +108,13 @@ void PrefsBase::RemoveObserver(const string& key, ObserverInterface* observer) {
observers_for_key.erase(observer_it);
}
+string PrefsInterface::CreateSubKey(const string& name_space,
+ const string& sub_pref,
+ const string& key) {
+ return base::JoinString({name_space, sub_pref, key},
+ string(1, kKeySeparator));
+}
+
// Prefs
bool Prefs::Init(const base::FilePath& prefs_dir) {
@@ -112,6 +123,24 @@ bool Prefs::Init(const base::FilePath& prefs_dir) {
bool Prefs::FileStorage::Init(const base::FilePath& prefs_dir) {
prefs_dir_ = prefs_dir;
+ // Delete empty directories. Ignore errors when deleting empty directories.
+ base::FileEnumerator namespace_enum(
+ prefs_dir_, false /* recursive */, base::FileEnumerator::DIRECTORIES);
+ for (base::FilePath namespace_path = namespace_enum.Next();
+ !namespace_path.empty();
+ namespace_path = namespace_enum.Next()) {
+ base::FileEnumerator sub_pref_enum(namespace_path,
+ false /* recursive */,
+ base::FileEnumerator::DIRECTORIES);
+ for (base::FilePath sub_pref_path = sub_pref_enum.Next();
+ !sub_pref_path.empty();
+ sub_pref_path = sub_pref_enum.Next()) {
+ if (base::IsDirectoryEmpty(sub_pref_path))
+ base::DeleteFile(sub_pref_path, false);
+ }
+ if (base::IsDirectoryEmpty(namespace_path))
+ base::DeleteFile(namespace_path, false);
+ }
return true;
}
@@ -146,7 +175,7 @@ bool Prefs::FileStorage::KeyExists(const string& key) const {
bool Prefs::FileStorage::DeleteKey(const string& key) {
base::FilePath filename;
TEST_AND_RETURN_FALSE(GetFileNameForKey(key, &filename));
- TEST_AND_RETURN_FALSE(base::DeleteFile(filename, false));
+ TEST_AND_RETURN_FALSE(base::DeleteFile(filename, true));
return true;
}
@@ -157,7 +186,7 @@ bool Prefs::FileStorage::GetFileNameForKey(const string& key,
for (size_t i = 0; i < key.size(); ++i) {
char c = key.at(i);
TEST_AND_RETURN_FALSE(base::IsAsciiAlpha(c) || base::IsAsciiDigit(c) ||
- c == '_' || c == '-');
+ c == '_' || c == '-' || c == kKeySeparator);
}
*filename = prefs_dir_.Append(key);
return true;