[EFL] Use eina_file_ls() in EFL implementation of FileSystem listDirectory()
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 26 Jun 2012 23:39:57 +0000 (23:39 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 26 Jun 2012 23:39:57 +0000 (23:39 +0000)
https://bugs.webkit.org/show_bug.cgi?id=89976

Patch by Christophe Dumez <christophe.dumez@intel.com> on 2012-06-26
Reviewed by Antonio Gomes.

Rewrite EFL implementation of Filesystem listDirectory() in order to
use eina_file_ls() instead of POSIX C functions. This results in
shorter code.

No new tests, behavior has not changed.

* platform/efl/FileSystemEfl.cpp:
(WebCore::listDirectory):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@121300 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/platform/efl/FileSystemEfl.cpp

index eaea708..2ef2d39 100755 (executable)
@@ -1,3 +1,19 @@
+2012-06-26  Christophe Dumez  <christophe.dumez@intel.com>
+
+        [EFL] Use eina_file_ls() in EFL implementation of FileSystem listDirectory()
+        https://bugs.webkit.org/show_bug.cgi?id=89976
+
+        Reviewed by Antonio Gomes.
+
+        Rewrite EFL implementation of Filesystem listDirectory() in order to
+        use eina_file_ls() instead of POSIX C functions. This results in
+        shorter code.
+
+        No new tests, behavior has not changed.
+
+        * platform/efl/FileSystemEfl.cpp:
+        (WebCore::listDirectory):
+
 2012-06-26  Alice Cheng  <alice_cheng@apple.com>
 
         Crash at WebCore::TextIterator::handleTextBox
index d4adb16..c6bff15 100644 (file)
@@ -86,50 +86,19 @@ String homeDirectoryPath()
 
 Vector<String> listDirectory(const String& path, const String& filter)
 {
-    Vector<String> entries;
-    CString cpath = path.utf8();
+    Vector<String> matchingEntries;
     CString cfilter = filter.utf8();
-    char filePath[PATH_MAX];
-    char* fileName;
-    size_t fileNameSpace;
-    DIR* dir;
+    const char *f_name;
 
-    if (cpath.length() + NAME_MAX >= sizeof(filePath))
-        return entries;
-    // loop invariant: directory part + '/'
-    memcpy(filePath, cpath.data(), cpath.length());
-    fileName = filePath + cpath.length();
-    if (cpath.length() > 0 && filePath[cpath.length() - 1] != '/') {
-        fileName[0] = '/';
-        fileName++;
+    Eina_Iterator* it = eina_file_ls(path.utf8().data());
+    EINA_ITERATOR_FOREACH(it, f_name) {
+        if (!fnmatch(cfilter.data(), f_name, 0))
+            matchingEntries.append(String::fromUTF8(f_name));
+        eina_stringshare_del(f_name);
     }
-    fileNameSpace = sizeof(filePath) - (fileName - filePath) - 1;
+    eina_iterator_free(it);
 
-    dir = opendir(cpath.data());
-    if (!dir)
-        return entries;
-
-    struct dirent* de;
-    while (de = readdir(dir)) {
-        size_t nameLen;
-        if (de->d_name[0] == '.') {
-            if (de->d_name[1] == '\0')
-                continue;
-            if (de->d_name[1] == '.' && de->d_name[2] == '\0')
-                continue;
-        }
-        if (fnmatch(cfilter.data(), de->d_name, 0))
-            continue;
-
-        nameLen = strlen(de->d_name);
-        if (nameLen >= fileNameSpace)
-            continue; // maybe assert? it should never happen anyway...
-
-        memcpy(fileName, de->d_name, nameLen + 1);
-        entries.append(filePath);
-    }
-    closedir(dir);
-    return entries;
+    return matchingEntries;
 }
 
 }