summaryrefslogtreecommitdiffstats
path: root/base/file_util_posix.cc
diff options
context:
space:
mode:
authorestade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-24 03:29:26 +0000
committerestade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-24 03:29:26 +0000
commit172c55057003795131ecb2ad5dd012b0c1785171 (patch)
tree378dc00f1ad5af386876de3fc5d19e2da0b38ade /base/file_util_posix.cc
parenteb0022ffdefb2fddcb251f5b77a8f9dbfe62d8b2 (diff)
downloadchromium_src-172c55057003795131ecb2ad5dd012b0c1785171.zip
chromium_src-172c55057003795131ecb2ad5dd012b0c1785171.tar.gz
chromium_src-172c55057003795131ecb2ad5dd012b0c1785171.tar.bz2
Order posix file listings by type as well as name.
http://crbug.com/12812 TEST=go to /, see that directories are sorted before other files. Review URL: http://codereview.chromium.org/147063 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@19100 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/file_util_posix.cc')
-rw-r--r--base/file_util_posix.cc29
1 files changed, 25 insertions, 4 deletions
diff --git a/base/file_util_posix.cc b/base/file_util_posix.cc
index aca0ff9..26f4b8f 100644
--- a/base/file_util_posix.cc
+++ b/base/file_util_posix.cc
@@ -28,6 +28,23 @@
#include "base/string_util.h"
#include "base/time.h"
+namespace {
+
+bool IsDirectory(const FTSENT* file) {
+ switch (file->fts_info) {
+ case FTS_D:
+ case FTS_DC:
+ case FTS_DNR:
+ case FTS_DOT:
+ case FTS_DP:
+ return true;
+ default:
+ return false;
+ }
+}
+
+} // namespace
+
namespace file_util {
#if defined(GOOGLE_CHROME_BUILD)
@@ -560,10 +577,14 @@ void FileEnumerator::GetFindInfo(FindInfo* info) {
}
int CompareFiles(const FTSENT** a, const FTSENT** b) {
- // Order lexicographically, ignoring case and whether they are files or
- // directories.
- // TODO(yuzo): make this case-sensitive, directories-then-files, and
- // internationalized.
+ // Order lexicographically with directories before other files.
+ const bool a_is_dir = IsDirectory(*a);
+ const bool b_is_dir = IsDirectory(*b);
+ if (a_is_dir != b_is_dir)
+ return a_is_dir ? -1 : 1;
+
+ // TODO(yuzo): make this internationalized when encoding detection function
+ // becomes available.
return base::strcasecmp((*a)->fts_name, (*b)->fts_name);
}