summaryrefslogtreecommitdiff
path: root/common/utils.cc
diff options
context:
space:
mode:
authorchrome-bot <chrome-bot@chromium.org>2019-01-13 13:52:20 -0800
committerchrome-bot <chrome-bot@chromium.org>2019-01-13 13:52:20 -0800
commitbacee4044e68cb5d7044e54fe8cfa87baf2960ba (patch)
treeadd5e4a6b9effaf558701198868fbe95c33961f1 /common/utils.cc
parentef13c92c549fee1a73118c32315e4472a5c4ffa3 (diff)
parent7438410328547d8f55b6555ebdcfd9768978fcb9 (diff)
Merge commit '7438410328547d8f55b6555ebdcfd9768978fcb9' into patch_branch
Change-Id: Idc4f0d63865479d4e3b85069270c6c21d52a747d
Diffstat (limited to 'common/utils.cc')
-rw-r--r--common/utils.cc65
1 files changed, 2 insertions, 63 deletions
diff --git a/common/utils.cc b/common/utils.cc
index 1a8fd534..c6090135 100644
--- a/common/utils.cc
+++ b/common/utils.cc
@@ -83,11 +83,6 @@ const int kGetFileFormatMaxHeaderSize = 32;
// The path to the kernel's boot_id.
const char kBootIdPath[] = "/proc/sys/kernel/random/boot_id";
-// A pointer to a null-terminated string containing the root directory where all
-// the temporary files should be created. If null, the system default is used
-// instead.
-const char* root_temp_dir = nullptr;
-
// Return true if |disk_name| is an MTD or a UBI device. Note that this test is
// simply based on the name of the device.
bool IsMtdDeviceName(const string& disk_name) {
@@ -144,15 +139,11 @@ bool GetTempName(const string& path, base::FilePath* template_path) {
}
base::FilePath temp_dir;
- if (root_temp_dir) {
- temp_dir = base::FilePath(root_temp_dir);
- } else {
#ifdef __ANDROID__
- temp_dir = base::FilePath(constants::kNonVolatileDirectory).Append("tmp");
+ temp_dir = base::FilePath(constants::kNonVolatileDirectory).Append("tmp");
#else
- TEST_AND_RETURN_FALSE(base::GetTempDir(&temp_dir));
+ TEST_AND_RETURN_FALSE(base::GetTempDir(&temp_dir));
#endif // __ANDROID__
- }
if (!base::PathExists(temp_dir))
TEST_AND_RETURN_FALSE(base::CreateDirectory(temp_dir));
*template_path = temp_dir.Append(path);
@@ -163,10 +154,6 @@ bool GetTempName(const string& path, base::FilePath* template_path) {
namespace utils {
-void SetRootTempDir(const char* new_root_temp_dir) {
- root_temp_dir = new_root_temp_dir;
-}
-
string ParseECVersion(string input_line) {
base::TrimWhitespaceASCII(input_line, base::TRIM_ALL, &input_line);
@@ -927,12 +914,6 @@ ErrorCode GetBaseErrorCode(ErrorCode code) {
return base_code;
}
-Time TimeFromStructTimespec(struct timespec *ts) {
- int64_t us = static_cast<int64_t>(ts->tv_sec) * Time::kMicrosecondsPerSecond +
- static_cast<int64_t>(ts->tv_nsec) / Time::kNanosecondsPerMicrosecond;
- return Time::UnixEpoch() + TimeDelta::FromMicroseconds(us);
-}
-
string StringVectorToString(const vector<string> &vec_str) {
string str = "[";
for (vector<string>::const_iterator i = vec_str.begin();
@@ -962,48 +943,6 @@ string CalculateP2PFileId(const brillo::Blob& payload_hash,
encoded_hash.c_str());
}
-bool DecodeAndStoreBase64String(const string& base64_encoded,
- base::FilePath *out_path) {
- brillo::Blob contents;
-
- out_path->clear();
-
- if (base64_encoded.size() == 0) {
- LOG(ERROR) << "Can't decode empty string.";
- return false;
- }
-
- if (!brillo::data_encoding::Base64Decode(base64_encoded, &contents) ||
- contents.size() == 0) {
- LOG(ERROR) << "Error decoding base64.";
- return false;
- }
-
- FILE *file = base::CreateAndOpenTemporaryFile(out_path);
- if (file == nullptr) {
- LOG(ERROR) << "Error creating temporary file.";
- return false;
- }
-
- if (fwrite(contents.data(), 1, contents.size(), file) != contents.size()) {
- PLOG(ERROR) << "Error writing to temporary file.";
- if (fclose(file) != 0)
- PLOG(ERROR) << "Error closing temporary file.";
- if (unlink(out_path->value().c_str()) != 0)
- PLOG(ERROR) << "Error unlinking temporary file.";
- out_path->clear();
- return false;
- }
-
- if (fclose(file) != 0) {
- PLOG(ERROR) << "Error closing temporary file.";
- out_path->clear();
- return false;
- }
-
- return true;
-}
-
bool ConvertToOmahaInstallDate(Time time, int *out_num_days) {
time_t unix_time = time.ToTimeT();
// Output of: date +"%s" --date="Jan 1, 2007 0:00 PST".