summaryrefslogtreecommitdiffstats
path: root/base
diff options
context:
space:
mode:
authorestade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-11 23:27:47 +0000
committerestade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-11 23:27:47 +0000
commit1525c68ec291218d831e29ea34aaf5a516daf855 (patch)
tree50dfc5908f79cdee9ceca8a6d82bcd13c6427000 /base
parentd7e2df1d26c084d299feec37695aacd211dae073 (diff)
downloadchromium_src-1525c68ec291218d831e29ea34aaf5a516daf855.zip
chromium_src-1525c68ec291218d831e29ea34aaf5a516daf855.tar.gz
chromium_src-1525c68ec291218d831e29ea34aaf5a516daf855.tar.bz2
Make sure the parent directory always comes first when listing directories.
BUG=35288 TEST=see bug Review URL: http://codereview.chromium.org/596054 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@38854 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r--base/file_util.cc16
-rw-r--r--base/file_util.h13
-rw-r--r--base/file_util_posix.cc5
-rw-r--r--base/file_util_win.cc5
4 files changed, 26 insertions, 13 deletions
diff --git a/base/file_util.cc b/base/file_util.cc
index 1160e39..e0e6772 100644
--- a/base/file_util.cc
+++ b/base/file_util.cc
@@ -209,6 +209,14 @@ bool GetFileSize(const FilePath& file_path, int64* file_size) {
return true;
}
+bool IsDot(const FilePath& path) {
+ return FILE_PATH_LITERAL(".") == path.BaseName().value();
+}
+
+bool IsDotDot(const FilePath& path) {
+ return FILE_PATH_LITERAL("..") == path.BaseName().value();
+}
+
bool CloseFile(FILE* file) {
if (file == NULL)
return true;
@@ -421,12 +429,4 @@ bool FileEnumerator::ShouldSkip(const FilePath& path) {
return IsDot(path) || (IsDotDot(path) && !(INCLUDE_DOT_DOT & file_type_));
}
-bool FileEnumerator::IsDot(const FilePath& path) {
- return FILE_PATH_LITERAL(".") == path.BaseName().value();
-}
-
-bool FileEnumerator::IsDotDot(const FilePath& path) {
- return FILE_PATH_LITERAL("..") == path.BaseName().value();
-}
-
} // namespace
diff --git a/base/file_util.h b/base/file_util.h
index efa4633..cdedfc4 100644
--- a/base/file_util.h
+++ b/base/file_util.h
@@ -307,6 +307,12 @@ bool GetFileSize(const FilePath& file_path, int64* file_size);
// Deprecated temporary compatibility function.
bool GetFileSize(const std::wstring& file_path, int64* file_size);
+// Returns true if the given path's base name is ".".
+bool IsDot(const FilePath& path);
+
+// Returns true if the given path's base name is "..".
+bool IsDotDot(const FilePath& path);
+
// Used to hold information about a given file path. See GetFileInfo below.
struct FileInfo {
// The size of the file in bytes. Undefined when is_directory is true.
@@ -457,15 +463,12 @@ class FileEnumerator {
// Looks inside a FindInfo and determines if it's a directory.
static bool IsDirectory(const FindInfo& info);
+ static FilePath GetFilename(const FindInfo& find_info);
+
private:
// Returns true if the given path should be skipped in enumeration.
bool ShouldSkip(const FilePath& path);
- // Returns true if the given path's base name is ".".
- bool IsDot(const FilePath& path);
-
- // Returns true if the given path's base name is "..".
- bool IsDotDot(const FilePath& path);
#if defined(OS_WIN)
WIN32_FIND_DATA find_data_;
diff --git a/base/file_util_posix.cc b/base/file_util_posix.cc
index 3bd5376..fe24259 100644
--- a/base/file_util_posix.cc
+++ b/base/file_util_posix.cc
@@ -584,6 +584,11 @@ bool FileEnumerator::IsDirectory(const FindInfo& info) {
return S_ISDIR(info.stat.st_mode);
}
+// static
+FilePath FileEnumerator::GetFilename(const FindInfo& find_info) {
+ return FilePath(find_info.filename);
+}
+
FilePath FileEnumerator::Next() {
++current_directory_entry_;
diff --git a/base/file_util_win.cc b/base/file_util_win.cc
index 7c3de4d..9265ce2 100644
--- a/base/file_util_win.cc
+++ b/base/file_util_win.cc
@@ -751,6 +751,11 @@ bool FileEnumerator::IsDirectory(const FindInfo& info) {
return (info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0;
}
+// static
+FilePath FileEnumerator::GetFilename(const FindInfo& find_info) {
+ return FilePath(find_info.cFileName);
+}
+
FilePath FileEnumerator::Next() {
if (!is_in_find_op_) {
if (pending_paths_.empty())