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 #ifndef CHROMEOS_PLATFORM_UPDATE_ENGINE_UTILS_H__ | 5 #ifndef CHROMEOS_PLATFORM_UPDATE_ENGINE_UTILS_H__ |
6 #define CHROMEOS_PLATFORM_UPDATE_ENGINE_UTILS_H__ | 6 #define CHROMEOS_PLATFORM_UPDATE_ENGINE_UTILS_H__ |
7 | 7 |
8 #include <errno.h> | 8 #include <errno.h> |
9 | 9 |
10 #include <algorithm> | 10 #include <algorithm> |
11 #include <set> | 11 #include <set> |
12 #include <string> | 12 #include <string> |
13 #include <vector> | 13 #include <vector> |
14 | 14 |
| 15 #include <ext2fs/ext2fs.h> |
15 #include <glib.h> | 16 #include <glib.h> |
16 | 17 |
17 #include "update_engine/action.h" | 18 #include "update_engine/action.h" |
18 #include "update_engine/action_processor.h" | 19 #include "update_engine/action_processor.h" |
19 | 20 |
20 namespace chromeos_update_engine { | 21 namespace chromeos_update_engine { |
21 | 22 |
22 namespace utils { | 23 namespace utils { |
23 | 24 |
24 // Returns true if this is an official Chrome OS build, false otherwise. | 25 // Returns true if this is an official Chrome OS build, false otherwise. |
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
264 *fd_ = -1; | 265 *fd_ = -1; |
265 } | 266 } |
266 } | 267 } |
267 void set_should_close(bool should_close) { should_close_ = should_close; } | 268 void set_should_close(bool should_close) { should_close_ = should_close; } |
268 private: | 269 private: |
269 int* fd_; | 270 int* fd_; |
270 bool should_close_; | 271 bool should_close_; |
271 DISALLOW_COPY_AND_ASSIGN(ScopedFdCloser); | 272 DISALLOW_COPY_AND_ASSIGN(ScopedFdCloser); |
272 }; | 273 }; |
273 | 274 |
| 275 // Utility class to close a file system |
| 276 class ScopedExt2fsCloser { |
| 277 public: |
| 278 explicit ScopedExt2fsCloser(ext2_filsys filsys) : filsys_(filsys) {} |
| 279 ~ScopedExt2fsCloser() { ext2fs_close(filsys_); } |
| 280 |
| 281 private: |
| 282 ext2_filsys filsys_; |
| 283 DISALLOW_COPY_AND_ASSIGN(ScopedExt2fsCloser); |
| 284 }; |
| 285 |
274 // Utility class to delete a file when it goes out of scope. | 286 // Utility class to delete a file when it goes out of scope. |
275 class ScopedPathUnlinker { | 287 class ScopedPathUnlinker { |
276 public: | 288 public: |
277 explicit ScopedPathUnlinker(const std::string& path) : path_(path) {} | 289 explicit ScopedPathUnlinker(const std::string& path) : path_(path) {} |
278 ~ScopedPathUnlinker() { | 290 ~ScopedPathUnlinker() { |
279 if (unlink(path_.c_str()) < 0) { | 291 if (unlink(path_.c_str()) < 0) { |
280 std::string err_message = strerror(errno); | 292 std::string err_message = strerror(errno); |
281 LOG(ERROR) << "Unable to unlink path " << path_ << ": " << err_message; | 293 LOG(ERROR) << "Unable to unlink path " << path_ << ": " << err_message; |
282 } | 294 } |
283 } | 295 } |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
382 | 394 |
383 #define TEST_AND_RETURN(_x) \ | 395 #define TEST_AND_RETURN(_x) \ |
384 do { \ | 396 do { \ |
385 bool _success = (_x); \ | 397 bool _success = (_x); \ |
386 if (!_success) { \ | 398 if (!_success) { \ |
387 LOG(ERROR) << #_x " failed."; \ | 399 LOG(ERROR) << #_x " failed."; \ |
388 return; \ | 400 return; \ |
389 } \ | 401 } \ |
390 } while (0) | 402 } while (0) |
391 | 403 |
| 404 #define TEST_AND_RETURN_FALSE_ERRCODE(_x) \ |
| 405 do { \ |
| 406 errcode_t _error = (_x); \ |
| 407 if (_error) { \ |
| 408 errno = _error; \ |
| 409 LOG(ERROR) << #_x " failed: " << _error; \ |
| 410 return false; \ |
| 411 } \ |
| 412 } while (0) |
| 413 |
392 | 414 |
393 | 415 |
394 #endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_UTILS_H__ | 416 #endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_UTILS_H__ |
OLD | NEW |