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 |