| 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> |
| (...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 287 ~ScopedExt2fsCloser() { ext2fs_close(filsys_); } | 287 ~ScopedExt2fsCloser() { ext2fs_close(filsys_); } |
| 288 | 288 |
| 289 private: | 289 private: |
| 290 ext2_filsys filsys_; | 290 ext2_filsys filsys_; |
| 291 DISALLOW_COPY_AND_ASSIGN(ScopedExt2fsCloser); | 291 DISALLOW_COPY_AND_ASSIGN(ScopedExt2fsCloser); |
| 292 }; | 292 }; |
| 293 | 293 |
| 294 // Utility class to delete a file when it goes out of scope. | 294 // Utility class to delete a file when it goes out of scope. |
| 295 class ScopedPathUnlinker { | 295 class ScopedPathUnlinker { |
| 296 public: | 296 public: |
| 297 explicit ScopedPathUnlinker(const std::string& path) : path_(path) {} | 297 explicit ScopedPathUnlinker(const std::string& path) |
| 298 : path_(path), |
| 299 should_remove_(true) {} |
| 298 ~ScopedPathUnlinker() { | 300 ~ScopedPathUnlinker() { |
| 299 if (unlink(path_.c_str()) < 0) { | 301 if (should_remove_ && unlink(path_.c_str()) < 0) { |
| 300 std::string err_message = strerror(errno); | 302 std::string err_message = strerror(errno); |
| 301 LOG(ERROR) << "Unable to unlink path " << path_ << ": " << err_message; | 303 LOG(ERROR) << "Unable to unlink path " << path_ << ": " << err_message; |
| 302 } | 304 } |
| 303 } | 305 } |
| 306 void set_should_remove(bool should_remove) { should_remove_ = should_remove; } |
| 307 |
| 304 private: | 308 private: |
| 305 const std::string path_; | 309 const std::string path_; |
| 310 bool should_remove_; |
| 306 DISALLOW_COPY_AND_ASSIGN(ScopedPathUnlinker); | 311 DISALLOW_COPY_AND_ASSIGN(ScopedPathUnlinker); |
| 307 }; | 312 }; |
| 308 | 313 |
| 309 // Utility class to delete an empty directory when it goes out of scope. | 314 // Utility class to delete an empty directory when it goes out of scope. |
| 310 class ScopedDirRemover { | 315 class ScopedDirRemover { |
| 311 public: | 316 public: |
| 312 explicit ScopedDirRemover(const std::string& path) | 317 explicit ScopedDirRemover(const std::string& path) |
| 313 : path_(path), | 318 : path_(path), |
| 314 should_remove_(true) {} | 319 should_remove_(true) {} |
| 315 ~ScopedDirRemover() { | 320 ~ScopedDirRemover() { |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 415 if (_error) { \ | 420 if (_error) { \ |
| 416 errno = _error; \ | 421 errno = _error; \ |
| 417 LOG(ERROR) << #_x " failed: " << _error; \ | 422 LOG(ERROR) << #_x " failed: " << _error; \ |
| 418 return false; \ | 423 return false; \ |
| 419 } \ | 424 } \ |
| 420 } while (0) | 425 } while (0) |
| 421 | 426 |
| 422 | 427 |
| 423 | 428 |
| 424 #endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_UTILS_H__ | 429 #endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_UTILS_H__ |
| OLD | NEW |