OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "base/test/test_file_util.h" | 5 #include "base/test/test_file_util.h" |
6 | 6 |
7 #include <errno.h> | 7 #include <errno.h> |
8 #include <fcntl.h> | 8 #include <fcntl.h> |
9 #include <sys/stat.h> | 9 #include <sys/stat.h> |
10 #include <sys/types.h> | 10 #include <sys/types.h> |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 } | 133 } |
134 | 134 |
135 bool MakeFileUnreadable(const FilePath& path) { | 135 bool MakeFileUnreadable(const FilePath& path) { |
136 return DenyFilePermission(path, S_IRUSR | S_IRGRP | S_IROTH); | 136 return DenyFilePermission(path, S_IRUSR | S_IRGRP | S_IROTH); |
137 } | 137 } |
138 | 138 |
139 bool MakeFileUnwritable(const FilePath& path) { | 139 bool MakeFileUnwritable(const FilePath& path) { |
140 return DenyFilePermission(path, S_IWUSR | S_IWGRP | S_IWOTH); | 140 return DenyFilePermission(path, S_IWUSR | S_IWGRP | S_IWOTH); |
141 } | 141 } |
142 | 142 |
| 143 void* GetPermissionInfo(const FilePath& path, size_t* length) { |
| 144 DCHECK(length != NULL); |
| 145 *length = 0; |
| 146 |
| 147 struct stat stat_buf; |
| 148 if (stat(path.value().c_str(), &stat_buf) != 0) |
| 149 return NULL; |
| 150 |
| 151 *length = sizeof(mode_t); |
| 152 mode_t* mode = new mode_t; |
| 153 *mode = stat_buf.st_mode; |
| 154 |
| 155 return mode; |
| 156 } |
| 157 |
| 158 bool RestorePermissionInfo(const FilePath& path, void* info, size_t length) { |
| 159 if (!info || !length) |
| 160 return false; |
| 161 |
| 162 DCHECK_EQ(sizeof(mode_t), length); |
| 163 mode_t* mode = reinterpret_cast<mode_t*>(info); |
| 164 |
| 165 int rv = HANDLE_EINTR(chmod(path.value().c_str(), *mode)); |
| 166 |
| 167 delete mode; // AKA info. |
| 168 |
| 169 return rv == 0; |
| 170 } |
| 171 |
143 } // namespace file_util | 172 } // namespace file_util |
OLD | NEW |