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 <set> | 8 #include <set> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
(...skipping 20 matching lines...) Expand all Loading... |
31 | 31 |
32 // Returns true if the file exists for sure. Returns false if it doesn't exist, | 32 // Returns true if the file exists for sure. Returns false if it doesn't exist, |
33 // or an error occurs. | 33 // or an error occurs. |
34 bool FileExists(const char* path); | 34 bool FileExists(const char* path); |
35 | 35 |
36 // The last 6 chars of path must be XXXXXX. They will be randomly changed | 36 // The last 6 chars of path must be XXXXXX. They will be randomly changed |
37 // and a non-existent path will be returned. Intentionally makes a copy | 37 // and a non-existent path will be returned. Intentionally makes a copy |
38 // of the string passed in. | 38 // of the string passed in. |
39 // NEVER CALL THIS FUNCTION UNLESS YOU ARE SURE | 39 // NEVER CALL THIS FUNCTION UNLESS YOU ARE SURE |
40 // THAT YOUR PROCESS WILL BE THE ONLY THING WRITING FILES IN THIS DIRECTORY. | 40 // THAT YOUR PROCESS WILL BE THE ONLY THING WRITING FILES IN THIS DIRECTORY. |
41 std::string TempFilename(string path); | 41 std::string TempFilename(std::string path); |
42 | 42 |
43 // Deletes a directory and all its contents synchronously. Returns true | 43 // Deletes a directory and all its contents synchronously. Returns true |
44 // on success. This may be called with a regular file--it will just unlink it. | 44 // on success. This may be called with a regular file--it will just unlink it. |
45 // This WILL cross filesystem boundaries. | 45 // This WILL cross filesystem boundaries. |
46 bool RecursiveUnlinkDir(const std::string& path); | 46 bool RecursiveUnlinkDir(const std::string& path); |
47 | 47 |
48 // Synchronously mount or unmount a filesystem. Return true on success. | 48 // Synchronously mount or unmount a filesystem. Return true on success. |
49 // Mounts as ext3 with default options. | 49 // Mounts as ext3 with default options. |
50 bool MountFilesystem(const string& device, const string& mountpoint); | 50 bool MountFilesystem(const std::string& device, const std::string& mountpoint); |
51 bool UnmountFilesystem(const string& mountpoint); | 51 bool UnmountFilesystem(const std::string& mountpoint); |
52 | 52 |
53 // Log a string in hex to LOG(INFO). Useful for debugging. | 53 // Log a string in hex to LOG(INFO). Useful for debugging. |
54 void HexDumpArray(const unsigned char* const arr, const size_t length); | 54 void HexDumpArray(const unsigned char* const arr, const size_t length); |
55 inline void HexDumpString(const std::string& str) { | 55 inline void HexDumpString(const std::string& str) { |
56 HexDumpArray(reinterpret_cast<const unsigned char*>(str.data()), str.size()); | 56 HexDumpArray(reinterpret_cast<const unsigned char*>(str.data()), str.size()); |
57 } | 57 } |
58 inline void HexDumpVector(const std::vector<char>& vect) { | 58 inline void HexDumpVector(const std::vector<char>& vect) { |
59 HexDumpArray(reinterpret_cast<const unsigned char*>(&vect[0]), vect.size()); | 59 HexDumpArray(reinterpret_cast<const unsigned char*>(&vect[0]), vect.size()); |
60 } | 60 } |
61 | 61 |
62 extern const string kStatefulPartition; | 62 extern const char* const kStatefulPartition; |
63 | 63 |
64 bool StringHasSuffix(const std::string& str, const std::string& suffix); | 64 bool StringHasSuffix(const std::string& str, const std::string& suffix); |
65 bool StringHasPrefix(const std::string& str, const std::string& prefix); | 65 bool StringHasPrefix(const std::string& str, const std::string& prefix); |
66 | 66 |
67 template<typename KeyType, typename ValueType> | 67 template<typename KeyType, typename ValueType> |
68 bool MapContainsKey(const std::map<KeyType, ValueType>& m, const KeyType& k) { | 68 bool MapContainsKey(const std::map<KeyType, ValueType>& m, const KeyType& k) { |
69 return m.find(k) != m.end(); | 69 return m.find(k) != m.end(); |
70 } | 70 } |
| 71 template<typename KeyType> |
| 72 bool SetContainsKey(const std::set<KeyType>& s, const KeyType& k) { |
| 73 return s.find(k) != s.end(); |
| 74 } |
71 | 75 |
72 template<typename ValueType> | 76 template<typename ValueType> |
73 std::set<ValueType> SetWithValue(const ValueType& value) { | 77 std::set<ValueType> SetWithValue(const ValueType& value) { |
74 std::set<ValueType> ret; | 78 std::set<ValueType> ret; |
75 ret.insert(value); | 79 ret.insert(value); |
76 return ret; | 80 return ret; |
77 } | 81 } |
78 | 82 |
79 // Returns the currently booted device. "/dev/sda1", for example. | 83 // Returns the currently booted device. "/dev/sda1", for example. |
80 // This will not interpret LABEL= or UUID=. You'll need to use findfs | 84 // This will not interpret LABEL= or UUID=. You'll need to use findfs |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 bool _success = (_x); \ | 183 bool _success = (_x); \ |
180 if (!_success) { \ | 184 if (!_success) { \ |
181 LOG(ERROR) << #_x " failed."; \ | 185 LOG(ERROR) << #_x " failed."; \ |
182 return; \ | 186 return; \ |
183 } \ | 187 } \ |
184 } while (0) | 188 } while (0) |
185 | 189 |
186 | 190 |
187 | 191 |
188 #endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_UTILS_H__ | 192 #endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_UTILS_H__ |
OLD | NEW |