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

Side by Side 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, 9 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 | Annotate | Revision Log
OLDNEW
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
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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698