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

Side by Side Diff: base/file_util_posix.cc

Issue 113287: posix: directories should only be readable by the user. (Closed)
Patch Set: fixed Created 11 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
« no previous file with comments | « base/file_util.h ('k') | no next file » | 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 <dirent.h> 7 #include <dirent.h>
8 #include <errno.h> 8 #include <errno.h>
9 #include <fcntl.h> 9 #include <fcntl.h>
10 #include <fnmatch.h> 10 #include <fnmatch.h>
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 case FTS_D: // Preorder directory. 207 case FTS_D: // Preorder directory.
208 // If we encounter a subdirectory in a non-recursive copy, prune it 208 // If we encounter a subdirectory in a non-recursive copy, prune it
209 // from the traversal. 209 // from the traversal.
210 if (!recursive && ent->fts_level > 0) { 210 if (!recursive && ent->fts_level > 0) {
211 if (fts_set(fts, ent, FTS_SKIP) != 0) 211 if (fts_set(fts, ent, FTS_SKIP) != 0)
212 error = errno; 212 error = errno;
213 continue; 213 continue;
214 } 214 }
215 215
216 // Try creating the target dir, continuing on it if it exists already. 216 // Try creating the target dir, continuing on it if it exists already.
217 // Rely on the user's umask to produce correct permissions. 217 if (mkdir(target_path.value().c_str(), 0700) != 0) {
218 if (mkdir(target_path.value().c_str(), 0777) != 0) {
219 if (errno != EEXIST) 218 if (errno != EEXIST)
220 error = errno; 219 error = errno;
221 } 220 }
222 break; 221 break;
223 case FTS_F: // Regular file. 222 case FTS_F: // Regular file.
224 case FTS_NSOK: // File, no stat info requested. 223 case FTS_NSOK: // File, no stat info requested.
225 errno = 0; 224 errno = 0;
226 if (!CopyFile(FilePath(ent->fts_path), target_path)) 225 if (!CopyFile(FilePath(ent->fts_path), target_path))
227 error = errno ? errno : EINVAL; 226 error = errno ? errno : EINVAL;
228 break; 227 break;
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
418 for (FilePath path = full_path.DirName(); 417 for (FilePath path = full_path.DirName();
419 path.value() != last_path.value(); path = path.DirName()) { 418 path.value() != last_path.value(); path = path.DirName()) {
420 subpaths.push_back(path); 419 subpaths.push_back(path);
421 last_path = path; 420 last_path = path;
422 } 421 }
423 422
424 // Iterate through the parents and create the missing ones. 423 // Iterate through the parents and create the missing ones.
425 for (std::vector<FilePath>::reverse_iterator i = subpaths.rbegin(); 424 for (std::vector<FilePath>::reverse_iterator i = subpaths.rbegin();
426 i != subpaths.rend(); ++i) { 425 i != subpaths.rend(); ++i) {
427 if (!DirectoryExists(*i)) { 426 if (!DirectoryExists(*i)) {
428 if (mkdir(i->value().c_str(), 0777) != 0) 427 if (mkdir(i->value().c_str(), 0700) != 0)
429 return false; 428 return false;
430 } 429 }
431 } 430 }
432 return true; 431 return true;
433 } 432 }
434 433
435 bool GetFileInfo(const FilePath& file_path, FileInfo* results) { 434 bool GetFileInfo(const FilePath& file_path, FileInfo* results) {
436 struct stat64 file_info; 435 struct stat64 file_info;
437 if (stat64(file_path.value().c_str(), &file_info) != 0) 436 if (stat64(file_path.value().c_str(), &file_info) != 0)
438 return false; 437 return false;
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
633 munmap(data_, length_); 632 munmap(data_, length_);
634 if (file_ != -1) 633 if (file_ != -1)
635 close(file_); 634 close(file_);
636 635
637 data_ = NULL; 636 data_ = NULL;
638 length_ = 0; 637 length_ = 0;
639 file_ = -1; 638 file_ = -1;
640 } 639 }
641 640
642 } // namespace file_util 641 } // namespace file_util
OLDNEW
« no previous file with comments | « base/file_util.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698