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 private: | |
petkov
2010/12/15 18:40:32
empty line before private (yeah, i know the rest o
thieule
2010/12/15 19:57:01
Done.
| |
281 ext2_filsys filsys_; | |
282 }; | |
petkov
2010/12/15 18:40:32
Add DISALLOW_COPY_AND_ASSIGN
thieule
2010/12/15 19:57:01
Done.
| |
283 | |
274 // Utility class to delete a file when it goes out of scope. | 284 // Utility class to delete a file when it goes out of scope. |
275 class ScopedPathUnlinker { | 285 class ScopedPathUnlinker { |
276 public: | 286 public: |
277 explicit ScopedPathUnlinker(const std::string& path) : path_(path) {} | 287 explicit ScopedPathUnlinker(const std::string& path) : path_(path) {} |
278 ~ScopedPathUnlinker() { | 288 ~ScopedPathUnlinker() { |
279 if (unlink(path_.c_str()) < 0) { | 289 if (unlink(path_.c_str()) < 0) { |
280 std::string err_message = strerror(errno); | 290 std::string err_message = strerror(errno); |
281 LOG(ERROR) << "Unable to unlink path " << path_ << ": " << err_message; | 291 LOG(ERROR) << "Unable to unlink path " << path_ << ": " << err_message; |
282 } | 292 } |
283 } | 293 } |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
382 | 392 |
383 #define TEST_AND_RETURN(_x) \ | 393 #define TEST_AND_RETURN(_x) \ |
384 do { \ | 394 do { \ |
385 bool _success = (_x); \ | 395 bool _success = (_x); \ |
386 if (!_success) { \ | 396 if (!_success) { \ |
387 LOG(ERROR) << #_x " failed."; \ | 397 LOG(ERROR) << #_x " failed."; \ |
388 return; \ | 398 return; \ |
389 } \ | 399 } \ |
390 } while (0) | 400 } while (0) |
391 | 401 |
402 #define TEST_AND_RETURN_FALSE_ERRCODE(_x) \ | |
403 do { \ | |
404 errcode_t _error = (_x); \ | |
405 if (_error) { \ | |
406 errno = _error; \ | |
407 LOG(ERROR) << #_x " failed: " << _error; \ | |
408 return false; \ | |
409 } \ | |
410 } while (0) | |
411 | |
392 | 412 |
393 | 413 |
394 #endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_UTILS_H__ | 414 #endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_UTILS_H__ |
OLD | NEW |