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

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: 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 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 return ret; 216 return ret;
217 } 217 }
218 if (!S_ISDIR(file_info.st_mode)) 218 if (!S_ISDIR(file_info.st_mode))
219 return (unlink(path_str) == 0); 219 return (unlink(path_str) == 0);
220 if (!recursive) 220 if (!recursive)
221 return (rmdir(path_str) == 0); 221 return (rmdir(path_str) == 0);
222 222
223 bool success = true; 223 bool success = true;
224 std::stack<std::string> directories; 224 std::stack<std::string> directories;
225 directories.push(path.value()); 225 directories.push(path.value());
226 FileEnumerator traversal(path, true, static_cast<FileEnumerator::FileType>( 226 FileEnumerator traversal(
227 FileEnumerator::FILES | FileEnumerator::DIRECTORIES | 227 path,
jar (doing other things) 2012/08/06 18:27:02 nit: IMO, put lines 227 and 228 on line 226. It i
Haruki Sato 2012/08/06 23:22:18 Done. Thank you for the thourough review.
228 FileEnumerator::SHOW_SYM_LINKS)); 228 true,
229 (FileEnumerator::FILES | FileEnumerator::DIRECTORIES |
230 FileEnumerator::SHOW_SYM_LINKS));
229 for (FilePath current = traversal.Next(); success && !current.empty(); 231 for (FilePath current = traversal.Next(); success && !current.empty();
230 current = traversal.Next()) { 232 current = traversal.Next()) {
231 FileEnumerator::FindInfo info; 233 FileEnumerator::FindInfo info;
232 traversal.GetFindInfo(&info); 234 traversal.GetFindInfo(&info);
233 235
234 if (S_ISDIR(info.stat.st_mode)) 236 if (S_ISDIR(info.stat.st_mode))
235 directories.push(current.value()); 237 directories.push(current.value());
236 else 238 else
237 success = (unlink(current.value().c_str()) == 0); 239 success = (unlink(current.value().c_str()) == 0);
238 } 240 }
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 } 306 }
305 FilePath real_from_path = from_path; 307 FilePath real_from_path = from_path;
306 if (!AbsolutePath(&real_from_path)) 308 if (!AbsolutePath(&real_from_path))
307 return false; 309 return false;
308 if (real_to_path.value().size() >= real_from_path.value().size() && 310 if (real_to_path.value().size() >= real_from_path.value().size() &&
309 real_to_path.value().compare(0, real_from_path.value().size(), 311 real_to_path.value().compare(0, real_from_path.value().size(),
310 real_from_path.value()) == 0) 312 real_from_path.value()) == 0)
311 return false; 313 return false;
312 314
313 bool success = true; 315 bool success = true;
314 FileEnumerator::FileType traverse_type = 316 int traverse_type = FileEnumerator::FILES | FileEnumerator::SHOW_SYM_LINKS;
315 static_cast<FileEnumerator::FileType>(FileEnumerator::FILES |
316 FileEnumerator::SHOW_SYM_LINKS);
317 if (recursive) 317 if (recursive)
318 traverse_type = static_cast<FileEnumerator::FileType>( 318 traverse_type |= FileEnumerator::DIRECTORIES;
319 traverse_type | FileEnumerator::DIRECTORIES);
320 FileEnumerator traversal(from_path, recursive, traverse_type); 319 FileEnumerator traversal(from_path, recursive, traverse_type);
321 320
322 // We have to mimic windows behavior here. |to_path| may not exist yet, 321 // We have to mimic windows behavior here. |to_path| may not exist yet,
323 // start the loop with |to_path|. 322 // start the loop with |to_path|.
324 FileEnumerator::FindInfo info; 323 FileEnumerator::FindInfo info;
325 FilePath current = from_path; 324 FilePath current = from_path;
326 if (stat(from_path.value().c_str(), &info.stat) < 0) { 325 if (stat(from_path.value().c_str(), &info.stat) < 0) {
327 DLOG(ERROR) << "CopyDirectory() couldn't stat source directory: " 326 DLOG(ERROR) << "CopyDirectory() couldn't stat source directory: "
328 << from_path.value() << " errno = " << errno; 327 << from_path.value() << " errno = " << errno;
329 success = false; 328 success = false;
(...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after
732 base::ThreadRestrictions::AssertIOAllowed(); 731 base::ThreadRestrictions::AssertIOAllowed();
733 int ret = chdir(path.value().c_str()); 732 int ret = chdir(path.value().c_str());
734 return !ret; 733 return !ret;
735 } 734 }
736 735
737 /////////////////////////////////////////////// 736 ///////////////////////////////////////////////
738 // FileEnumerator 737 // FileEnumerator
739 738
740 FileEnumerator::FileEnumerator(const FilePath& root_path, 739 FileEnumerator::FileEnumerator(const FilePath& root_path,
741 bool recursive, 740 bool recursive,
742 FileType file_type) 741 int file_type)
743 : current_directory_entry_(0), 742 : current_directory_entry_(0),
744 root_path_(root_path), 743 root_path_(root_path),
745 recursive_(recursive), 744 recursive_(recursive),
746 file_type_(file_type) { 745 file_type_(file_type) {
747 // INCLUDE_DOT_DOT must not be specified if recursive. 746 // INCLUDE_DOT_DOT must not be specified if recursive.
748 DCHECK(!(recursive && (INCLUDE_DOT_DOT & file_type_))); 747 DCHECK(!(recursive && (INCLUDE_DOT_DOT & file_type_)));
749 pending_paths_.push(root_path); 748 pending_paths_.push(root_path);
750 } 749 }
751 750
752 FileEnumerator::FileEnumerator(const FilePath& root_path, 751 FileEnumerator::FileEnumerator(const FilePath& root_path,
753 bool recursive, 752 bool recursive,
754 FileType file_type, 753 int file_type,
755 const FilePath::StringType& pattern) 754 const FilePath::StringType& pattern)
756 : current_directory_entry_(0), 755 : current_directory_entry_(0),
757 root_path_(root_path), 756 root_path_(root_path),
758 recursive_(recursive), 757 recursive_(recursive),
759 file_type_(file_type), 758 file_type_(file_type),
760 pattern_(root_path.Append(pattern).value()) { 759 pattern_(root_path.Append(pattern).value()) {
761 // INCLUDE_DOT_DOT must not be specified if recursive. 760 // INCLUDE_DOT_DOT must not be specified if recursive.
762 DCHECK(!(recursive && (INCLUDE_DOT_DOT & file_type_))); 761 DCHECK(!(recursive && (INCLUDE_DOT_DOT & file_type_)));
763 // The Windows version of this code appends the pattern to the root_path, 762 // The Windows version of this code appends the pattern to the root_path,
764 // potentially only matching against items in the top-most directory. 763 // potentially only matching against items in the top-most directory.
(...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after
1151 1150
1152 allowed_group_ids.insert(group_record->gr_gid); 1151 allowed_group_ids.insert(group_record->gr_gid);
1153 } 1152 }
1154 1153
1155 return VerifyPathControlledByUser( 1154 return VerifyPathControlledByUser(
1156 kFileSystemRoot, path, kRootUid, allowed_group_ids); 1155 kFileSystemRoot, path, kRootUid, allowed_group_ids);
1157 } 1156 }
1158 #endif // defined(OS_MACOSX) && !defined(OS_IOS) 1157 #endif // defined(OS_MACOSX) && !defined(OS_IOS)
1159 1158
1160 } // namespace file_util 1159 } // namespace file_util
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698