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

Side by Side Diff: src/platform/update_engine/utils.cc

Issue 1881001: AU: Many minor cleanup changes (Closed) Base URL: ssh://git@chromiumos-git/chromeos
Patch Set: fixes for review Created 10 years, 7 months 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
« no previous file with comments | « src/platform/update_engine/utils.h ('k') | src/platform/update_engine/utils_unittest.cc » ('j') | 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) 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 #include "update_engine/utils.h" 5 #include "update_engine/utils.h"
6 #include <sys/mount.h> 6 #include <sys/mount.h>
7 #include <sys/stat.h> 7 #include <sys/stat.h>
8 #include <sys/types.h> 8 #include <sys/types.h>
9 #include <dirent.h> 9 #include <dirent.h>
10 #include <errno.h> 10 #include <errno.h>
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 TEST_AND_RETURN_FALSE(RecursiveUnlinkDir(path + "/" + 188 TEST_AND_RETURN_FALSE(RecursiveUnlinkDir(path + "/" +
189 dir_entry_p->d_name)); 189 dir_entry_p->d_name));
190 } 190 }
191 TEST_AND_RETURN_FALSE(err == 0); 191 TEST_AND_RETURN_FALSE(err == 0);
192 } 192 }
193 // unlink dir 193 // unlink dir
194 TEST_AND_RETURN_FALSE_ERRNO((rmdir(path.c_str()) == 0) || (errno == ENOENT)); 194 TEST_AND_RETURN_FALSE_ERRNO((rmdir(path.c_str()) == 0) || (errno == ENOENT));
195 return true; 195 return true;
196 } 196 }
197 197
198 string RootDevice(const string& partition_device) {
199 CHECK(!partition_device.empty());
200 string::const_iterator it = --partition_device.end();
201 for (; it >= partition_device.begin(); --it) {
202 if (!isdigit(*it))
203 break;
204 }
205 // Some devices contain a p before the partitions. For example:
206 // /dev/mmc0p4 should be shortened to /dev/mmc0.
207 if (*it == 'p')
208 --it;
209 return string(partition_device.begin(), it + 1);
210 }
211
212 string PartitionNumber(const string& partition_device) {
213 CHECK(!partition_device.empty());
214 string::const_iterator it = --partition_device.end();
215 for (; it >= partition_device.begin(); --it) {
216 if (!isdigit(*it))
217 break;
218 }
219 return string(it + 1, partition_device.end());
220 }
221
198 std::string ErrnoNumberAsString(int err) { 222 std::string ErrnoNumberAsString(int err) {
199 char buf[100]; 223 char buf[100];
200 buf[0] = '\0'; 224 buf[0] = '\0';
201 return strerror_r(err, buf, sizeof(buf)); 225 return strerror_r(err, buf, sizeof(buf));
202 } 226 }
203 227
204 std::string NormalizePath(const std::string& path, bool strip_trailing_slash) { 228 std::string NormalizePath(const std::string& path, bool strip_trailing_slash) {
205 string ret; 229 string ret;
206 bool last_insert_was_slash = false; 230 bool last_insert_was_slash = false;
207 for (string::const_iterator it = path.begin(); it != path.end(); ++it) { 231 for (string::const_iterator it = path.begin(); it != path.end(); ++it) {
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 return false; 374 return false;
351 } 375 }
352 return true; 376 return true;
353 } 377 }
354 378
355 bool UnmountFilesystem(const string& mountpoint) { 379 bool UnmountFilesystem(const string& mountpoint) {
356 TEST_AND_RETURN_FALSE_ERRNO(umount(mountpoint.c_str()) == 0); 380 TEST_AND_RETURN_FALSE_ERRNO(umount(mountpoint.c_str()) == 0);
357 return true; 381 return true;
358 } 382 }
359 383
384 bool GetBootloader(BootLoader* out_bootloader) {
385 // For now, hardcode to syslinux.
386 *out_bootloader = BootLoader_SYSLINUX;
387 return true;
388 }
389
360 const char* GetGErrorMessage(const GError* error) { 390 const char* GetGErrorMessage(const GError* error) {
361 if (!error) 391 if (!error)
362 return "Unknown error."; 392 return "Unknown error.";
363 return error->message; 393 return error->message;
364 } 394 }
365 395
366 const char* const kStatefulPartition = "/mnt/stateful_partition"; 396 const char* const kStatefulPartition = "/mnt/stateful_partition";
367 397
368 } // namespace utils 398 } // namespace utils
369 399
370 } // namespace chromeos_update_engine 400 } // namespace chromeos_update_engine
371 401
OLDNEW
« no previous file with comments | « src/platform/update_engine/utils.h ('k') | src/platform/update_engine/utils_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698