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

Unified Diff: utils.cc

Issue 2868105: Disable automatic update checks if booting from a removable device. (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/update_engine.git
Patch Set: Created 10 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « utils.h ('k') | utils_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: utils.cc
diff --git a/utils.cc b/utils.cc
index d691739bb3100d77cb4da3ad6fe4a78327569f70..05acc1545dbf1eb2d0c70d90a73b5a40921a1c10 100644
--- a/utils.cc
+++ b/utils.cc
@@ -3,6 +3,7 @@
// found in the LICENSE file.
#include "update_engine/utils.h"
+
#include <sys/mount.h>
#include <sys/stat.h>
#include <sys/types.h>
@@ -13,7 +14,12 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
+
#include <algorithm>
+
+#include "base/file_path.h"
+#include "base/file_util.h"
+#include "base/string_util.h"
#include "chromeos/obsolete_logging.h"
#include "update_engine/file_writer.h"
#include "update_engine/omaha_request_params.h"
@@ -207,7 +213,10 @@ bool RecursiveUnlinkDir(const std::string& path) {
}
string RootDevice(const string& partition_device) {
- CHECK(!partition_device.empty());
+ FilePath device_path(partition_device);
+ if (device_path.DirName().value() != "/dev") {
+ return "";
+ }
string::const_iterator it = --partition_device.end();
for (; it >= partition_device.begin(); --it) {
if (!isdigit(*it))
@@ -230,6 +239,26 @@ string PartitionNumber(const string& partition_device) {
return string(it + 1, partition_device.end());
}
+string SysfsBlockDevice(const string& device) {
+ FilePath device_path(device);
+ if (device_path.DirName().value() != "/dev") {
+ return "";
+ }
+ return FilePath("/sys/block").Append(device_path.BaseName()).value();
+}
+
+bool IsRemovableDevice(const std::string& device) {
+ string sysfs_block = SysfsBlockDevice(device);
+ string removable;
+ if (sysfs_block.empty() ||
+ !file_util::ReadFileToString(FilePath(sysfs_block).Append("removable"),
+ &removable)) {
+ return false;
+ }
+ TrimWhitespaceASCII(removable, TRIM_ALL, &removable);
+ return removable == "1";
+}
+
std::string ErrnoNumberAsString(int err) {
char buf[100];
buf[0] = '\0';
« no previous file with comments | « utils.h ('k') | utils_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698