| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "update_engine/prefs.h" | 5 #include "update_engine/prefs.h" |
| 6 | 6 |
| 7 #include <base/file_util.h> | 7 #include <base/file_util.h> |
| 8 #include <base/logging.h> | 8 #include <base/logging.h> |
| 9 #include <base/string_number_conversions.h> | 9 #include <base/string_number_conversions.h> |
| 10 #include <base/string_util.h> | 10 #include <base/string_util.h> |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 "update-state-signed-sha-256-context"; | 28 "update-state-signed-sha-256-context"; |
| 29 | 29 |
| 30 bool Prefs::Init(const FilePath& prefs_dir) { | 30 bool Prefs::Init(const FilePath& prefs_dir) { |
| 31 prefs_dir_ = prefs_dir; | 31 prefs_dir_ = prefs_dir; |
| 32 return true; | 32 return true; |
| 33 } | 33 } |
| 34 | 34 |
| 35 bool Prefs::GetString(const string& key, string* value) { | 35 bool Prefs::GetString(const string& key, string* value) { |
| 36 FilePath filename; | 36 FilePath filename; |
| 37 TEST_AND_RETURN_FALSE(GetFileNameForKey(key, &filename)); | 37 TEST_AND_RETURN_FALSE(GetFileNameForKey(key, &filename)); |
| 38 TEST_AND_RETURN_FALSE(file_util::ReadFileToString(filename, value)); | 38 if (!file_util::ReadFileToString(filename, value)) { |
| 39 PLOG(INFO) << "Unable to read prefs from " << filename.value() |
| 40 << ". This is likely harmless."; |
| 41 return false; |
| 42 } |
| 39 return true; | 43 return true; |
| 40 } | 44 } |
| 41 | 45 |
| 42 bool Prefs::SetString(const std::string& key, const std::string& value) { | 46 bool Prefs::SetString(const std::string& key, const std::string& value) { |
| 43 FilePath filename; | 47 FilePath filename; |
| 44 TEST_AND_RETURN_FALSE(GetFileNameForKey(key, &filename)); | 48 TEST_AND_RETURN_FALSE(GetFileNameForKey(key, &filename)); |
| 45 TEST_AND_RETURN_FALSE(file_util::CreateDirectory(filename.DirName())); | 49 TEST_AND_RETURN_FALSE(file_util::CreateDirectory(filename.DirName())); |
| 46 TEST_AND_RETURN_FALSE( | 50 TEST_AND_RETURN_FALSE( |
| 47 file_util::WriteFile(filename, value.data(), value.size()) == | 51 file_util::WriteFile(filename, value.data(), value.size()) == |
| 48 static_cast<int>(value.size())); | 52 static_cast<int>(value.size())); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 67 for (size_t i = 0; i < key.size(); ++i) { | 71 for (size_t i = 0; i < key.size(); ++i) { |
| 68 char c = key.at(i); | 72 char c = key.at(i); |
| 69 TEST_AND_RETURN_FALSE(IsAsciiAlpha(c) || IsAsciiDigit(c) || | 73 TEST_AND_RETURN_FALSE(IsAsciiAlpha(c) || IsAsciiDigit(c) || |
| 70 c == '_' || c == '-'); | 74 c == '_' || c == '-'); |
| 71 } | 75 } |
| 72 *filename = prefs_dir_.Append(key); | 76 *filename = prefs_dir_.Append(key); |
| 73 return true; | 77 return true; |
| 74 } | 78 } |
| 75 | 79 |
| 76 } // namespace chromeos_update_engine | 80 } // namespace chromeos_update_engine |
| OLD | NEW |