| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium OS Authors. All rights reserved. | 1 // Copyright (c) 2009 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/test_utils.h" | 5 #include "update_engine/test_utils.h" |
| 6 | 6 |
| 7 #include <sys/stat.h> | 7 #include <sys/stat.h> |
| 8 #include <sys/types.h> | 8 #include <sys/types.h> |
| 9 #include <errno.h> | 9 #include <errno.h> |
| 10 #include <stdio.h> | 10 #include <stdio.h> |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 namespace chromeos_update_engine { | 28 namespace chromeos_update_engine { |
| 29 | 29 |
| 30 bool WriteFileVector(const std::string& path, const std::vector<char>& data) { | 30 bool WriteFileVector(const std::string& path, const std::vector<char>& data) { |
| 31 return utils::WriteFile(path.c_str(), &data[0], data.size()); | 31 return utils::WriteFile(path.c_str(), &data[0], data.size()); |
| 32 } | 32 } |
| 33 | 33 |
| 34 bool WriteFileString(const std::string& path, const std::string& data) { | 34 bool WriteFileString(const std::string& path, const std::string& data) { |
| 35 return utils::WriteFile(path.c_str(), data.data(), data.size()); | 35 return utils::WriteFile(path.c_str(), data.data(), data.size()); |
| 36 } | 36 } |
| 37 | 37 |
| 38 off_t FileSize(const string& path) { | |
| 39 struct stat stbuf; | |
| 40 int rc = stat(path.c_str(), &stbuf); | |
| 41 CHECK_EQ(rc, 0); | |
| 42 if (rc < 0) | |
| 43 return rc; | |
| 44 return stbuf.st_size; | |
| 45 } | |
| 46 | |
| 47 std::string Readlink(const std::string& path) { | 38 std::string Readlink(const std::string& path) { |
| 48 vector<char> buf(PATH_MAX + 1); | 39 vector<char> buf(PATH_MAX + 1); |
| 49 ssize_t r = readlink(path.c_str(), &buf[0], buf.size()); | 40 ssize_t r = readlink(path.c_str(), &buf[0], buf.size()); |
| 50 if (r < 0) | 41 if (r < 0) |
| 51 return ""; | 42 return ""; |
| 52 CHECK_LT(r, static_cast<ssize_t>(buf.size())); | 43 CHECK_LT(r, static_cast<ssize_t>(buf.size())); |
| 53 buf.resize(r); | 44 buf.resize(r); |
| 54 string ret; | 45 string ret; |
| 55 ret.insert(ret.begin(), buf.begin(), buf.end()); | 46 ret.insert(ret.begin(), buf.begin(), buf.end()); |
| 56 return ret; | 47 return ret; |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 266 EXPECT_TRUE(expected_paths.empty()); | 257 EXPECT_TRUE(expected_paths.empty()); |
| 267 if (!expected_paths.empty()) { | 258 if (!expected_paths.empty()) { |
| 268 for (set<string>::const_iterator it = expected_paths.begin(); | 259 for (set<string>::const_iterator it = expected_paths.begin(); |
| 269 it != expected_paths.end(); ++it) { | 260 it != expected_paths.end(); ++it) { |
| 270 LOG(INFO) << "extra path: " << *it; | 261 LOG(INFO) << "extra path: " << *it; |
| 271 } | 262 } |
| 272 } | 263 } |
| 273 } | 264 } |
| 274 | 265 |
| 275 } // namespace chromeos_update_engine | 266 } // namespace chromeos_update_engine |
| OLD | NEW |