summaryrefslogtreecommitdiffstats
path: root/base/file_util_posix.cc
diff options
context:
space:
mode:
authorestade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2008-11-19 23:52:02 +0000
committerestade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2008-11-19 23:52:02 +0000
commit5dce90240ecb2259290cd3aa12294b832b09eee9 (patch)
treeefbb4f40583404e421b12e5dc2a1e0259f9dd186 /base/file_util_posix.cc
parente4bac199faccb0b0e45673d21aa5dae0ea77a787 (diff)
downloadchromium_src-5dce90240ecb2259290cd3aa12294b832b09eee9.zip
chromium_src-5dce90240ecb2259290cd3aa12294b832b09eee9.tar.gz
chromium_src-5dce90240ecb2259290cd3aa12294b832b09eee9.tar.bz2
Port directory lister to posix.
Fix of issue 11437. Review URL: http://codereview.chromium.org/11293 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@5730 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/file_util_posix.cc')
-rw-r--r--base/file_util_posix.cc48
1 files changed, 29 insertions, 19 deletions
diff --git a/base/file_util_posix.cc b/base/file_util_posix.cc
index 1afb573..5760a68 100644
--- a/base/file_util_posix.cc
+++ b/base/file_util_posix.cc
@@ -409,6 +409,16 @@ FileEnumerator::~FileEnumerator() {
fts_close(fts_);
}
+void FileEnumerator::GetFindInfo(FindInfo* info) {
+ DCHECK(info);
+
+ if (!is_in_find_op_)
+ return;
+
+ memcpy(&(info->stat), fts_ent_->fts_statp, sizeof(info->stat));
+ info->filename.assign(fts_ent_->fts_name);
+}
+
// As it stands, this method calls itself recursively when the next item of
// the fts enumeration doesn't match (type, pattern, etc.). In the case of
// large directories with many files this can be quite deep.
@@ -417,12 +427,12 @@ std::wstring FileEnumerator::Next() {
if (!is_in_find_op_) {
if (pending_paths_.empty())
return std::wstring();
-
+
// The last find FindFirstFile operation is done, prepare a new one.
root_path_ = pending_paths_.top();
TrimTrailingSeparator(&root_path_);
pending_paths_.pop();
-
+
// Start a new find operation.
int ftsflags = FTS_LOGICAL;
char top_dir[PATH_MAX];
@@ -433,41 +443,41 @@ std::wstring FileEnumerator::Next() {
return Next();
is_in_find_op_ = true;
}
-
- FTSENT* fts_ent = fts_read(fts_);
- if (fts_ent == NULL) {
+
+ fts_ent_ = fts_read(fts_);
+ if (fts_ent_ == NULL) {
fts_close(fts_);
fts_ = NULL;
is_in_find_op_ = false;
return Next();
}
-
+
// Level 0 is the top, which is always skipped.
- if (fts_ent->fts_level == 0)
+ if (fts_ent_->fts_level == 0)
return Next();
-
+
// Patterns are only matched on the items in the top-most directory.
// (see Windows implementation)
- if (fts_ent->fts_level == 1 && pattern_.length() > 0) {
- if (fnmatch(WideToUTF8(pattern_).c_str(), fts_ent->fts_path, 0) != 0) {
- if (fts_ent->fts_info == FTS_D)
- fts_set(fts_, fts_ent, FTS_SKIP);
+ if (fts_ent_->fts_level == 1 && pattern_.length() > 0) {
+ if (fnmatch(WideToUTF8(pattern_).c_str(), fts_ent_->fts_path, 0) != 0) {
+ if (fts_ent_->fts_info == FTS_D)
+ fts_set(fts_, fts_ent_, FTS_SKIP);
return Next();
}
}
-
- std::wstring cur_file(UTF8ToWide(fts_ent->fts_path));
- if (fts_ent->fts_info == FTS_D) {
+
+ std::wstring cur_file(UTF8ToWide(fts_ent_->fts_path));
+ if (fts_ent_->fts_info == FTS_D) {
// If not recursive, then prune children.
if (!recursive_)
- fts_set(fts_, fts_ent, FTS_SKIP);
+ fts_set(fts_, fts_ent_, FTS_SKIP);
return (file_type_ & FileEnumerator::DIRECTORIES) ? cur_file : Next();
- } else if (fts_ent->fts_info == FTS_F) {
+ } else if (fts_ent_->fts_info == FTS_F) {
return (file_type_ & FileEnumerator::FILES) ? cur_file : Next();
}
// TODO(erikkay) - verify that the other fts_info types aren't interesting
return Next();
}
-
-
+
+
} // namespace file_util