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

Side by Side Diff: base/file_util_posix.cc

Issue 10855002: Change the type of file_type parameter to int, as the parameter actually takes or-ed bitmasks, (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Addressed the comments about constant names. Created 8 years, 4 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
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/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 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 return ret; 220 return ret;
221 } 221 }
222 if (!S_ISDIR(file_info.st_mode)) 222 if (!S_ISDIR(file_info.st_mode))
223 return (unlink(path_str) == 0); 223 return (unlink(path_str) == 0);
224 if (!recursive) 224 if (!recursive)
225 return (rmdir(path_str) == 0); 225 return (rmdir(path_str) == 0);
226 226
227 bool success = true; 227 bool success = true;
228 std::stack<std::string> directories; 228 std::stack<std::string> directories;
229 directories.push(path.value()); 229 directories.push(path.value());
230 FileEnumerator traversal(path, true, static_cast<FileEnumerator::FileType>( 230 FileEnumerator traversal(path, true,
231 FileEnumerator::FILES | FileEnumerator::DIRECTORIES | 231 (FileEnumerator::FILES | FileEnumerator::DIRECTORIES |
232 FileEnumerator::SHOW_SYM_LINKS)); 232 FileEnumerator::SHOW_SYM_LINKS));
233 for (FilePath current = traversal.Next(); success && !current.empty(); 233 for (FilePath current = traversal.Next(); success && !current.empty();
234 current = traversal.Next()) { 234 current = traversal.Next()) {
235 FileEnumerator::FindInfo info; 235 FileEnumerator::FindInfo info;
236 traversal.GetFindInfo(&info); 236 traversal.GetFindInfo(&info);
237 237
238 if (S_ISDIR(info.stat.st_mode)) 238 if (S_ISDIR(info.stat.st_mode))
239 directories.push(current.value()); 239 directories.push(current.value());
240 else 240 else
241 success = (unlink(current.value().c_str()) == 0); 241 success = (unlink(current.value().c_str()) == 0);
242 } 242 }
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 } 308 }
309 FilePath real_from_path = from_path; 309 FilePath real_from_path = from_path;
310 if (!AbsolutePath(&real_from_path)) 310 if (!AbsolutePath(&real_from_path))
311 return false; 311 return false;
312 if (real_to_path.value().size() >= real_from_path.value().size() && 312 if (real_to_path.value().size() >= real_from_path.value().size() &&
313 real_to_path.value().compare(0, real_from_path.value().size(), 313 real_to_path.value().compare(0, real_from_path.value().size(),
314 real_from_path.value()) == 0) 314 real_from_path.value()) == 0)
315 return false; 315 return false;
316 316
317 bool success = true; 317 bool success = true;
318 FileEnumerator::FileType traverse_type = 318 int traverse_type = FileEnumerator::FILES | FileEnumerator::SHOW_SYM_LINKS;
319 static_cast<FileEnumerator::FileType>(FileEnumerator::FILES |
320 FileEnumerator::SHOW_SYM_LINKS);
321 if (recursive) 319 if (recursive)
322 traverse_type = static_cast<FileEnumerator::FileType>( 320 traverse_type |= FileEnumerator::DIRECTORIES;
323 traverse_type | FileEnumerator::DIRECTORIES);
324 FileEnumerator traversal(from_path, recursive, traverse_type); 321 FileEnumerator traversal(from_path, recursive, traverse_type);
325 322
326 // We have to mimic windows behavior here. |to_path| may not exist yet, 323 // We have to mimic windows behavior here. |to_path| may not exist yet,
327 // start the loop with |to_path|. 324 // start the loop with |to_path|.
328 FileEnumerator::FindInfo info; 325 FileEnumerator::FindInfo info;
329 FilePath current = from_path; 326 FilePath current = from_path;
330 if (stat(from_path.value().c_str(), &info.stat) < 0) { 327 if (stat(from_path.value().c_str(), &info.stat) < 0) {
331 DLOG(ERROR) << "CopyDirectory() couldn't stat source directory: " 328 DLOG(ERROR) << "CopyDirectory() couldn't stat source directory: "
332 << from_path.value() << " errno = " << errno; 329 << from_path.value() << " errno = " << errno;
333 success = false; 330 success = false;
(...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after
736 base::ThreadRestrictions::AssertIOAllowed(); 733 base::ThreadRestrictions::AssertIOAllowed();
737 int ret = chdir(path.value().c_str()); 734 int ret = chdir(path.value().c_str());
738 return !ret; 735 return !ret;
739 } 736 }
740 737
741 /////////////////////////////////////////////// 738 ///////////////////////////////////////////////
742 // FileEnumerator 739 // FileEnumerator
743 740
744 FileEnumerator::FileEnumerator(const FilePath& root_path, 741 FileEnumerator::FileEnumerator(const FilePath& root_path,
745 bool recursive, 742 bool recursive,
746 FileType file_type) 743 int file_type)
747 : current_directory_entry_(0), 744 : current_directory_entry_(0),
748 root_path_(root_path), 745 root_path_(root_path),
749 recursive_(recursive), 746 recursive_(recursive),
750 file_type_(file_type) { 747 file_type_(file_type) {
751 // INCLUDE_DOT_DOT must not be specified if recursive. 748 // INCLUDE_DOT_DOT must not be specified if recursive.
752 DCHECK(!(recursive && (INCLUDE_DOT_DOT & file_type_))); 749 DCHECK(!(recursive && (INCLUDE_DOT_DOT & file_type_)));
753 pending_paths_.push(root_path); 750 pending_paths_.push(root_path);
754 } 751 }
755 752
756 FileEnumerator::FileEnumerator(const FilePath& root_path, 753 FileEnumerator::FileEnumerator(const FilePath& root_path,
757 bool recursive, 754 bool recursive,
758 FileType file_type, 755 int file_type,
759 const FilePath::StringType& pattern) 756 const FilePath::StringType& pattern)
760 : current_directory_entry_(0), 757 : current_directory_entry_(0),
761 root_path_(root_path), 758 root_path_(root_path),
762 recursive_(recursive), 759 recursive_(recursive),
763 file_type_(file_type), 760 file_type_(file_type),
764 pattern_(root_path.Append(pattern).value()) { 761 pattern_(root_path.Append(pattern).value()) {
765 // INCLUDE_DOT_DOT must not be specified if recursive. 762 // INCLUDE_DOT_DOT must not be specified if recursive.
766 DCHECK(!(recursive && (INCLUDE_DOT_DOT & file_type_))); 763 DCHECK(!(recursive && (INCLUDE_DOT_DOT & file_type_)));
767 // The Windows version of this code appends the pattern to the root_path, 764 // The Windows version of this code appends the pattern to the root_path,
768 // potentially only matching against items in the top-most directory. 765 // potentially only matching against items in the top-most directory.
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after
1160 1157
1161 allowed_group_ids.insert(group_record->gr_gid); 1158 allowed_group_ids.insert(group_record->gr_gid);
1162 } 1159 }
1163 1160
1164 return VerifyPathControlledByUser( 1161 return VerifyPathControlledByUser(
1165 kFileSystemRoot, path, kRootUid, allowed_group_ids); 1162 kFileSystemRoot, path, kRootUid, allowed_group_ids);
1166 } 1163 }
1167 #endif // defined(OS_MACOSX) && !defined(OS_IOS) 1164 #endif // defined(OS_MACOSX) && !defined(OS_IOS)
1168 1165
1169 } // namespace file_util 1166 } // namespace file_util
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698