Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(306)

Side by Side Diff: utils.h

Issue 5684002: Add support for bsdiff of file system metadata blocks (Closed) Base URL: http://git.chromium.org/git/update_engine.git@master
Patch Set: Created 10 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« test_utils.cc ('K') | « test_utils.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <glib.h> 15 #include <glib.h>
16 16
17 #include <ext2fs/ext2fs.h>
18
17 #include "update_engine/action.h" 19 #include "update_engine/action.h"
18 #include "update_engine/action_processor.h" 20 #include "update_engine/action_processor.h"
19 21
20 namespace chromeos_update_engine { 22 namespace chromeos_update_engine {
21 23
22 namespace utils { 24 namespace utils {
23 25
24 // Returns true if this is an official Chrome OS build, false otherwise. 26 // Returns true if this is an official Chrome OS build, false otherwise.
25 bool IsOfficialBuild(); 27 bool IsOfficialBuild();
26 28
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 *fd_ = -1; 266 *fd_ = -1;
265 } 267 }
266 } 268 }
267 void set_should_close(bool should_close) { should_close_ = should_close; } 269 void set_should_close(bool should_close) { should_close_ = should_close; }
268 private: 270 private:
269 int* fd_; 271 int* fd_;
270 bool should_close_; 272 bool should_close_;
271 DISALLOW_COPY_AND_ASSIGN(ScopedFdCloser); 273 DISALLOW_COPY_AND_ASSIGN(ScopedFdCloser);
272 }; 274 };
273 275
276 // Utility class to close a file system
277 class ScopedExt2fsCloser {
278 public:
279 explicit ScopedExt2fsCloser(ext2_filsys filsys) : filsys_(filsys) {}
280 ~ScopedExt2fsCloser() { ext2fs_close(filsys_); }
281 private:
282 ext2_filsys filsys_;
283 };
284
274 // Utility class to delete a file when it goes out of scope. 285 // Utility class to delete a file when it goes out of scope.
275 class ScopedPathUnlinker { 286 class ScopedPathUnlinker {
276 public: 287 public:
277 explicit ScopedPathUnlinker(const std::string& path) : path_(path) {} 288 explicit ScopedPathUnlinker(const std::string& path) : path_(path) {}
278 ~ScopedPathUnlinker() { 289 ~ScopedPathUnlinker() {
279 if (unlink(path_.c_str()) < 0) { 290 if (unlink(path_.c_str()) < 0) {
280 std::string err_message = strerror(errno); 291 std::string err_message = strerror(errno);
281 LOG(ERROR) << "Unable to unlink path " << path_ << ": " << err_message; 292 LOG(ERROR) << "Unable to unlink path " << path_ << ": " << err_message;
282 } 293 }
283 } 294 }
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 393
383 #define TEST_AND_RETURN(_x) \ 394 #define TEST_AND_RETURN(_x) \
384 do { \ 395 do { \
385 bool _success = (_x); \ 396 bool _success = (_x); \
386 if (!_success) { \ 397 if (!_success) { \
387 LOG(ERROR) << #_x " failed."; \ 398 LOG(ERROR) << #_x " failed."; \
388 return; \ 399 return; \
389 } \ 400 } \
390 } while (0) 401 } while (0)
391 402
403 #define TEST_AND_RETURN_FALSE_ERRCODE(_x) \
404 do { \
405 errcode_t _error = (_x); \
406 if (_error) { \
407 errno = _error; \
408 LOG(ERROR) << #_x " failed: " << _error; \
409 return false; \
410 } \
411 } while (0)
412
392 413
393 414
394 #endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_UTILS_H__ 415 #endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_UTILS_H__
OLDNEW
« test_utils.cc ('K') | « test_utils.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698