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

Unified Diff: base/file_util_posix.cc

Issue 147063: Order posix file listings by type as well as name.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: pass unit tests Created 11 years, 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | base/file_util_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/file_util_posix.cc
===================================================================
--- base/file_util_posix.cc (revision 19057)
+++ base/file_util_posix.cc (working copy)
@@ -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 @@
}
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);
}
« no previous file with comments | « no previous file | base/file_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698