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

Side by Side Diff: base/platform_file_posix.cc

Issue 14886003: Make base:ReplaceFile return an informative error. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: ToT Created 7 years, 7 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
« no previous file with comments | « base/platform_file.h ('k') | base/platform_file_win.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/platform_file.h" 5 #include "base/platform_file.h"
6 6
7 #include <fcntl.h> 7 #include <fcntl.h>
8 #include <errno.h> 8 #include <errno.h>
9 #include <sys/stat.h> 9 #include <sys/stat.h>
10 #include <unistd.h> 10 #include <unistd.h>
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 (flags & (PLATFORM_FILE_CREATE_ALWAYS | PLATFORM_FILE_CREATE))) 115 (flags & (PLATFORM_FILE_CREATE_ALWAYS | PLATFORM_FILE_CREATE)))
116 *created = true; 116 *created = true;
117 117
118 if ((descriptor >= 0) && (flags & PLATFORM_FILE_DELETE_ON_CLOSE)) { 118 if ((descriptor >= 0) && (flags & PLATFORM_FILE_DELETE_ON_CLOSE)) {
119 unlink(name.value().c_str()); 119 unlink(name.value().c_str());
120 } 120 }
121 121
122 if (error) { 122 if (error) {
123 if (descriptor >= 0) 123 if (descriptor >= 0)
124 *error = PLATFORM_FILE_OK; 124 *error = PLATFORM_FILE_OK;
125 else { 125 else
126 switch (errno) { 126 *error = ErrnoToPlatformFileError(errno);
127 case EACCES:
128 case EISDIR:
129 case EROFS:
130 case EPERM:
131 *error = PLATFORM_FILE_ERROR_ACCESS_DENIED;
132 break;
133 case ETXTBSY:
134 *error = PLATFORM_FILE_ERROR_IN_USE;
135 break;
136 case EEXIST:
137 *error = PLATFORM_FILE_ERROR_EXISTS;
138 break;
139 case ENOENT:
140 *error = PLATFORM_FILE_ERROR_NOT_FOUND;
141 break;
142 case EMFILE:
143 *error = PLATFORM_FILE_ERROR_TOO_MANY_OPENED;
144 break;
145 case ENOMEM:
146 *error = PLATFORM_FILE_ERROR_NO_MEMORY;
147 break;
148 case ENOSPC:
149 *error = PLATFORM_FILE_ERROR_NO_SPACE;
150 break;
151 case ENOTDIR:
152 *error = PLATFORM_FILE_ERROR_NOT_A_DIRECTORY;
153 break;
154 default:
155 *error = PLATFORM_FILE_ERROR_FAILED;
156 }
157 }
158 } 127 }
159 128
160 return descriptor; 129 return descriptor;
161 } 130 }
162 131
163 FILE* FdopenPlatformFile(PlatformFile file, const char* mode) { 132 FILE* FdopenPlatformFile(PlatformFile file, const char* mode) {
164 return fdopen(file, mode); 133 return fdopen(file, mode);
165 } 134 }
166 135
167 bool ClosePlatformFile(PlatformFile file) { 136 bool ClosePlatformFile(PlatformFile file) {
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 297
329 info->is_directory = S_ISDIR(file_info.st_mode); 298 info->is_directory = S_ISDIR(file_info.st_mode);
330 info->is_symbolic_link = S_ISLNK(file_info.st_mode); 299 info->is_symbolic_link = S_ISLNK(file_info.st_mode);
331 info->size = file_info.st_size; 300 info->size = file_info.st_size;
332 info->last_modified = base::Time::FromTimeT(file_info.st_mtime); 301 info->last_modified = base::Time::FromTimeT(file_info.st_mtime);
333 info->last_accessed = base::Time::FromTimeT(file_info.st_atime); 302 info->last_accessed = base::Time::FromTimeT(file_info.st_atime);
334 info->creation_time = base::Time::FromTimeT(file_info.st_ctime); 303 info->creation_time = base::Time::FromTimeT(file_info.st_ctime);
335 return true; 304 return true;
336 } 305 }
337 306
307 PlatformFileError ErrnoToPlatformFileError(int saved_errno) {
308 switch (saved_errno) {
309 case EACCES:
310 case EISDIR:
311 case EROFS:
312 case EPERM:
313 return PLATFORM_FILE_ERROR_ACCESS_DENIED;
314 case ETXTBSY:
315 return PLATFORM_FILE_ERROR_IN_USE;
316 case EEXIST:
317 return PLATFORM_FILE_ERROR_EXISTS;
318 case ENOENT:
319 return PLATFORM_FILE_ERROR_NOT_FOUND;
320 case EMFILE:
321 return PLATFORM_FILE_ERROR_TOO_MANY_OPENED;
322 case ENOMEM:
323 return PLATFORM_FILE_ERROR_NO_MEMORY;
324 case ENOSPC:
325 return PLATFORM_FILE_ERROR_NO_SPACE;
326 case ENOTDIR:
327 return PLATFORM_FILE_ERROR_NOT_A_DIRECTORY;
328 default:
329 return PLATFORM_FILE_ERROR_FAILED;
330 }
331 }
332
338 } // namespace base 333 } // namespace base
OLDNEW
« no previous file with comments | « base/platform_file.h ('k') | base/platform_file_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698