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

Side by Side Diff: base/file_util_posix.cc

Issue 16241: file_util minor cleanup:... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 12 years 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/file_util.cc ('k') | base/file_util_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) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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/file_util.h" 5 #include "base/file_util.h"
6 6
7 #include <errno.h> 7 #include <errno.h>
8 #include <fcntl.h> 8 #include <fcntl.h>
9 #include <fnmatch.h> 9 #include <fnmatch.h>
10 #include <fts.h> 10 #include <fts.h>
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 FTSENT* fts_ent = fts_read(fts); 78 FTSENT* fts_ent = fts_read(fts);
79 while (success && fts_ent != NULL) { 79 while (success && fts_ent != NULL) {
80 switch (fts_ent->fts_info) { 80 switch (fts_ent->fts_info) {
81 case FTS_DNR: 81 case FTS_DNR:
82 case FTS_ERR: 82 case FTS_ERR:
83 // log error 83 // log error
84 success = false; 84 success = false;
85 continue; 85 continue;
86 break; 86 break;
87 case FTS_DP: 87 case FTS_DP:
88 rmdir(fts_ent->fts_accpath); 88 success = (rmdir(fts_ent->fts_accpath) == 0);
89 break; 89 break;
90 case FTS_D: 90 case FTS_D:
91 break; 91 break;
92 case FTS_NSOK: 92 case FTS_NSOK:
93 case FTS_F: 93 case FTS_F:
94 case FTS_SL: 94 case FTS_SL:
95 case FTS_SLNONE: 95 case FTS_SLNONE:
96 unlink(fts_ent->fts_accpath); 96 success = (unlink(fts_ent->fts_accpath) == 0);
97 break; 97 break;
98 default: 98 default:
99 DCHECK(false); 99 DCHECK(false);
100 break; 100 break;
101 } 101 }
102 fts_ent = fts_read(fts); 102 fts_ent = fts_read(fts);
103 } 103 }
104 fts_close(fts); 104 fts_close(fts);
105 } 105 }
106 return success; 106 return success;
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 return false; 208 return false;
209 } 209 }
210 return true; 210 return true;
211 } 211 }
212 212
213 bool PathExists(const FilePath& path) { 213 bool PathExists(const FilePath& path) {
214 struct stat64 file_info; 214 struct stat64 file_info;
215 return (stat64(path.value().c_str(), &file_info) == 0); 215 return (stat64(path.value().c_str(), &file_info) == 0);
216 } 216 }
217 217
218 bool PathIsWritable(const FilePath& path) {
219 FilePath test_path(path);
220 struct stat64 file_info;
221 if (stat64(test_path.value().c_str(), &file_info) != 0) {
222 // If the path doesn't exist, test the parent dir.
223 test_path = test_path.DirName();
224 // If the parent dir doesn't exist, then return false (the path is not
225 // directly writable).
226 if (stat64(test_path.value().c_str(), &file_info) != 0)
227 return false;
228 }
229 if (S_IWOTH & file_info.st_mode)
230 return true;
231 if (getegid() == file_info.st_gid && (S_IWGRP & file_info.st_mode))
232 return true;
233 if (geteuid() == file_info.st_uid && (S_IWUSR & file_info.st_mode))
234 return true;
235 return false;
236 }
237
218 bool DirectoryExists(const FilePath& path) { 238 bool DirectoryExists(const FilePath& path) {
219 struct stat64 file_info; 239 struct stat64 file_info;
220 if (stat64(path.value().c_str(), &file_info) == 0) 240 if (stat64(path.value().c_str(), &file_info) == 0)
221 return S_ISDIR(file_info.st_mode); 241 return S_ISDIR(file_info.st_mode);
222 return false; 242 return false;
223 } 243 }
224 244
225 // TODO(erikkay): implement 245 // TODO(erikkay): implement
226 #if 0 246 #if 0
227 bool GetFileCreationLocalTimeFromHandle(int fd, 247 bool GetFileCreationLocalTimeFromHandle(int fd,
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 return true; 287 return true;
268 } 288 }
269 289
270 bool CreateTemporaryFileNameInDir(const std::wstring& dir, 290 bool CreateTemporaryFileNameInDir(const std::wstring& dir,
271 std::wstring* temp_file) { 291 std::wstring* temp_file) {
272 // Not implemented yet. 292 // Not implemented yet.
273 NOTREACHED(); 293 NOTREACHED();
274 return false; 294 return false;
275 } 295 }
276 296
277 bool CreateNewTempDirectory(const std::wstring& prefix, 297 bool CreateNewTempDirectory(const FilePath::StringType& prefix,
278 std::wstring* new_temp_path) { 298 FilePath* new_temp_path) {
279 FilePath tmpdir; 299 FilePath tmpdir;
280 if (!GetTempDir(&tmpdir)) 300 if (!GetTempDir(&tmpdir))
281 return false; 301 return false;
282 tmpdir = tmpdir.Append(kTempFileName); 302 tmpdir = tmpdir.Append(kTempFileName);
283 std::string tmpdir_string = tmpdir.value(); 303 std::string tmpdir_string = tmpdir.value();
284 // this should be OK since mkdtemp just replaces characters in place 304 // this should be OK since mkdtemp just replaces characters in place
285 char* buffer = const_cast<char*>(tmpdir_string.c_str()); 305 char* buffer = const_cast<char*>(tmpdir_string.c_str());
286 char* dtemp = mkdtemp(buffer); 306 char* dtemp = mkdtemp(buffer);
287 if (!dtemp) 307 if (!dtemp)
288 return false; 308 return false;
289 *new_temp_path = UTF8ToWide(dtemp); 309 *new_temp_path = FilePath(dtemp);
290 return true; 310 return true;
291 } 311 }
292 312
293 bool CreateDirectory(const FilePath& full_path) { 313 bool CreateDirectory(const FilePath& full_path) {
294 std::vector<FilePath> subpaths; 314 std::vector<FilePath> subpaths;
295 315
296 // Collect a list of all parent directories. 316 // Collect a list of all parent directories.
297 FilePath last_path = full_path; 317 FilePath last_path = full_path;
298 subpaths.push_back(full_path); 318 subpaths.push_back(full_path);
299 for (FilePath path = full_path.DirName(); 319 for (FilePath path = full_path.DirName();
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
514 munmap(data_, length_); 534 munmap(data_, length_);
515 if (file_ != -1) 535 if (file_ != -1)
516 close(file_); 536 close(file_);
517 537
518 data_ = NULL; 538 data_ = NULL;
519 length_ = 0; 539 length_ = 0;
520 file_ = -1; 540 file_ = -1;
521 } 541 }
522 542
523 } // namespace file_util 543 } // namespace file_util
OLDNEW
« no previous file with comments | « base/file_util.cc ('k') | base/file_util_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698