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

Side by Side Diff: base/files/file_util_posix.cc

Issue 2875563002: base: get rid of RealPath() function (Closed)
Patch Set: Created 3 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 | « no previous file | 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) 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/files/file_util.h" 5 #include "base/files/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 <libgen.h> 10 #include <libgen.h>
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 ThreadRestrictions::AssertIOAllowed(); 80 ThreadRestrictions::AssertIOAllowed();
81 return stat64(path, sb); 81 return stat64(path, sb);
82 } 82 }
83 static int CallLstat(const char *path, stat_wrapper_t *sb) { 83 static int CallLstat(const char *path, stat_wrapper_t *sb) {
84 ThreadRestrictions::AssertIOAllowed(); 84 ThreadRestrictions::AssertIOAllowed();
85 return lstat64(path, sb); 85 return lstat64(path, sb);
86 } 86 }
87 #endif // !(defined(OS_BSD) || defined(OS_MACOSX) || defined(OS_NACL)) 87 #endif // !(defined(OS_BSD) || defined(OS_MACOSX) || defined(OS_NACL))
88 88
89 #if !defined(OS_NACL_NONSFI) 89 #if !defined(OS_NACL_NONSFI)
90 // Helper for NormalizeFilePath(), defined below.
91 bool RealPath(const FilePath& path, FilePath* real_path) {
92 ThreadRestrictions::AssertIOAllowed(); // For realpath().
93 FilePath::CharType buf[PATH_MAX];
94 if (!realpath(path.value().c_str(), buf))
95 return false;
96
97 *real_path = FilePath(buf);
98 return true;
99 }
100
101 // Helper for VerifyPathControlledByUser. 90 // Helper for VerifyPathControlledByUser.
102 bool VerifySpecificPathControlledByUser(const FilePath& path, 91 bool VerifySpecificPathControlledByUser(const FilePath& path,
103 uid_t owner_uid, 92 uid_t owner_uid,
104 const std::set<gid_t>& group_gids) { 93 const std::set<gid_t>& group_gids) {
105 stat_wrapper_t stat_info; 94 stat_wrapper_t stat_info;
106 if (CallLstat(path.value().c_str(), &stat_info) != 0) { 95 if (CallLstat(path.value().c_str(), &stat_info) != 0) {
107 DPLOG(ERROR) << "Failed to get information on path " 96 DPLOG(ERROR) << "Failed to get information on path "
108 << path.value(); 97 << path.value();
109 return false; 98 return false;
110 } 99 }
(...skipping 559 matching lines...) Expand 10 before | Expand all | Expand 10 after
670 if (!DirectoryExists(*i)) { 659 if (!DirectoryExists(*i)) {
671 if (error) 660 if (error)
672 *error = File::OSErrorToFileError(saved_errno); 661 *error = File::OSErrorToFileError(saved_errno);
673 return false; 662 return false;
674 } 663 }
675 } 664 }
676 return true; 665 return true;
677 } 666 }
678 667
679 bool NormalizeFilePath(const FilePath& path, FilePath* normalized_path) { 668 bool NormalizeFilePath(const FilePath& path, FilePath* normalized_path) {
680 FilePath real_path_result; 669 FilePath real_path_result = MakeAbsoluteFilePath(path);
681 if (!RealPath(path, &real_path_result)) 670 if (real_path_result.empty())
682 return false; 671 return false;
683 672
684 // To be consistant with windows, fail if |real_path_result| is a 673 // To be consistant with windows, fail if |real_path_result| is a
685 // directory. 674 // directory.
686 stat_wrapper_t file_info; 675 stat_wrapper_t file_info;
687 if (CallStat(real_path_result.value().c_str(), &file_info) != 0 || 676 if (CallStat(real_path_result.value().c_str(), &file_info) != 0 ||
688 S_ISDIR(file_info.st_mode)) 677 S_ISDIR(file_info.st_mode))
689 return false; 678 return false;
690 679
691 *normalized_path = real_path_result; 680 *normalized_path = real_path_result;
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after
1019 return false; 1008 return false;
1020 1009
1021 DeleteFile(from_path, true); 1010 DeleteFile(from_path, true);
1022 return true; 1011 return true;
1023 } 1012 }
1024 1013
1025 } // namespace internal 1014 } // namespace internal
1026 1015
1027 #endif // !defined(OS_NACL_NONSFI) 1016 #endif // !defined(OS_NACL_NONSFI)
1028 } // namespace base 1017 } // namespace base
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698