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

Unified Diff: base/test/test_file_util_posix.cc

Issue 9355050: Added read-only file error test. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Added comment. Created 8 years, 10 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
Index: base/test/test_file_util_posix.cc
diff --git a/base/test/test_file_util_posix.cc b/base/test/test_file_util_posix.cc
index 0096c9e815df5e3c723012cd5e73b555e176c063..57b4411dcbf0f7e95a5c920210809061d2a0e950 100644
--- a/base/test/test_file_util_posix.cc
+++ b/base/test/test_file_util_posix.cc
@@ -140,4 +140,33 @@ bool MakeFileUnwritable(const FilePath& path) {
return DenyFilePermission(path, S_IWUSR | S_IWGRP | S_IWOTH);
}
+void* GetPermissionInfo(const FilePath& path, size_t* length) {
+ DCHECK(length != NULL);
+ *length = 0;
+
+ struct stat stat_buf;
+ if (stat(path.value().c_str(), &stat_buf) != 0)
+ return NULL;
+
+ *length = sizeof(mode_t);
+ mode_t* mode = new mode_t;
+ *mode = stat_buf.st_mode;
+
+ return mode;
+}
+
+bool RestorePermissionInfo(const FilePath& path, void* info, size_t length) {
+ if (!info || !length)
+ return false;
+
+ DCHECK_EQ(sizeof(mode_t), length);
+ mode_t* mode = reinterpret_cast<mode_t*>(info);
+
+ int rv = HANDLE_EINTR(chmod(path.value().c_str(), *mode));
+
+ delete mode; // AKA info.
+
+ return rv == 0;
+}
+
} // namespace file_util

Powered by Google App Engine
This is Rietveld 408576698