OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium 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 #include <algorithm> | 9 #include <algorithm> |
10 #include <set> | 10 #include <set> |
11 #include <string> | 11 #include <string> |
12 #include <vector> | 12 #include <vector> |
| 13 #include <glib.h> |
13 #include "update_engine/action.h" | 14 #include "update_engine/action.h" |
14 #include "update_engine/action_processor.h" | 15 #include "update_engine/action_processor.h" |
15 | 16 |
16 namespace chromeos_update_engine { | 17 namespace chromeos_update_engine { |
17 | 18 |
18 namespace utils { | 19 namespace utils { |
19 | 20 |
20 // Writes the data passed to path. The file at path will be overwritten if it | 21 // Writes the data passed to path. The file at path will be overwritten if it |
21 // exists. Returns true on success, false otherwise. | 22 // exists. Returns true on success, false otherwise. |
22 bool WriteFile(const char* path, const char* data, int data_len); | 23 bool WriteFile(const char* path, const char* data, int data_len); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 // on success. This may be called with a regular file--it will just unlink it. | 72 // on success. This may be called with a regular file--it will just unlink it. |
72 // This WILL cross filesystem boundaries. | 73 // This WILL cross filesystem boundaries. |
73 bool RecursiveUnlinkDir(const std::string& path); | 74 bool RecursiveUnlinkDir(const std::string& path); |
74 | 75 |
75 // Synchronously mount or unmount a filesystem. Return true on success. | 76 // Synchronously mount or unmount a filesystem. Return true on success. |
76 // Mounts as ext3 with default options. | 77 // Mounts as ext3 with default options. |
77 bool MountFilesystem(const std::string& device, const std::string& mountpoint, | 78 bool MountFilesystem(const std::string& device, const std::string& mountpoint, |
78 unsigned long flags); | 79 unsigned long flags); |
79 bool UnmountFilesystem(const std::string& mountpoint); | 80 bool UnmountFilesystem(const std::string& mountpoint); |
80 | 81 |
| 82 // Returns the error message, if any, from a GError pointer. |
| 83 const char* GetGErrorMessage(const GError* error); |
| 84 |
81 // Log a string in hex to LOG(INFO). Useful for debugging. | 85 // Log a string in hex to LOG(INFO). Useful for debugging. |
82 void HexDumpArray(const unsigned char* const arr, const size_t length); | 86 void HexDumpArray(const unsigned char* const arr, const size_t length); |
83 inline void HexDumpString(const std::string& str) { | 87 inline void HexDumpString(const std::string& str) { |
84 HexDumpArray(reinterpret_cast<const unsigned char*>(str.data()), str.size()); | 88 HexDumpArray(reinterpret_cast<const unsigned char*>(str.data()), str.size()); |
85 } | 89 } |
86 inline void HexDumpVector(const std::vector<char>& vect) { | 90 inline void HexDumpVector(const std::vector<char>& vect) { |
87 HexDumpArray(reinterpret_cast<const unsigned char*>(&vect[0]), vect.size()); | 91 HexDumpArray(reinterpret_cast<const unsigned char*>(&vect[0]), vect.size()); |
88 } | 92 } |
89 | 93 |
90 extern const char* const kStatefulPartition; | 94 extern const char* const kStatefulPartition; |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
260 bool _success = (_x); \ | 264 bool _success = (_x); \ |
261 if (!_success) { \ | 265 if (!_success) { \ |
262 LOG(ERROR) << #_x " failed."; \ | 266 LOG(ERROR) << #_x " failed."; \ |
263 return; \ | 267 return; \ |
264 } \ | 268 } \ |
265 } while (0) | 269 } while (0) |
266 | 270 |
267 | 271 |
268 | 272 |
269 #endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_UTILS_H__ | 273 #endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_UTILS_H__ |
OLD | NEW |