[vlc-commits] filesystem: fill in input item type

Rémi Denis-Courmont git at videolan.org
Wed Nov 4 20:43:03 CET 2015


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Wed Nov  4 21:39:58 2015 +0200| [c20e03737694de085f5acccf63b7969d81b9d520] | committer: Rémi Denis-Courmont

filesystem: fill in input item type

This restores the directory type, and adds a few more.

Regression from c0660ee36b9aebc051dd9422c1b108089902c8d5 (directory)

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=c20e03737694de085f5acccf63b7969d81b9d520
---

 modules/access/directory.c |   26 +++++++++++++++++++++++++-
 1 file changed, 25 insertions(+), 1 deletion(-)

diff --git a/modules/access/directory.c b/modules/access/directory.c
index 4985855..9b16b16 100644
--- a/modules/access/directory.c
+++ b/modules/access/directory.c
@@ -31,6 +31,8 @@
 # include "config.h"
 #endif
 
+#include <sys/stat.h>
+
 #include <vlc_common.h>
 #include "fs.h"
 #include <vlc_access.h>
@@ -118,6 +120,28 @@ input_item_t* DirRead (access_t *p_access)
 
     while ((entry = vlc_readdir (p_sys->p_dir)) != NULL)
     {
+        int type;
+#ifdef HAVE_OPENAT
+        struct stat st;
+
+        if (fstatat (dirfd (p_sys->p_dir), entry, &st, 0))
+            continue;
+
+        switch (st.st_mode & S_IFMT)
+        {
+            case S_IFBLK: type = ITEM_TYPE_DISC;      break;
+            case S_IFCHR: type = ITEM_TYPE_CARD;      break;
+            case S_IFIFO: type = ITEM_TYPE_STREAM;    break;
+            case S_IFREG: type = ITEM_TYPE_FILE;      break;
+            case S_IFDIR: type = ITEM_TYPE_DIRECTORY; break;
+            /* S_IFLNK cannot occur while following symbolic links */
+            /* S_IFSOCK cannot be opened with open()/openat() */
+            default:      continue; /* ignore */
+        }
+#else
+        type = ITEM_TYPE_FILE;
+#endif
+
         /* Create an input item for the current entry */
         char *encoded_entry = encode_URI_component (entry);
         if (unlikely(entry == NULL))
@@ -132,7 +156,7 @@ input_item_t* DirRead (access_t *p_access)
             return NULL;
 
         input_item_t *item = input_item_NewWithType (uri, entry, 0, NULL, 0, 0,
-                                                     ITEM_TYPE_FILE);
+                                                     type);
         free (uri);
         if (likely(item != NULL))
             return item;



More information about the vlc-commits mailing list