[vlc-commits] directory: ignore non-regular non-directory files by default

Rémi Denis-Courmont git at videolan.org
Thu Nov 5 20:35:11 CET 2015


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Thu Nov  5 21:23:45 2015 +0200| [d2ed3fb624274e824ab5ba892e8898f3d0eb1502] | committer: Rémi Denis-Courmont

directory: ignore non-regular non-directory files by default

Playing FIFOs and devices (especially character devices) typically
only makes sense if explicitly requested. Playing FIFOs will usually
lock up. Playing devices could have any effects.

Add an option to restore the old behaviour in case someone wants it.

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

 NEWS                       |    2 ++
 modules/access/directory.c |   31 +++++++++++++++++++++++++------
 modules/access/fs.c        |    2 ++
 3 files changed, 29 insertions(+), 6 deletions(-)

diff --git a/NEWS b/NEWS
index 5a3d43a..a5d7ae7 100644
--- a/NEWS
+++ b/NEWS
@@ -27,6 +27,8 @@ Access:
  * SMB/FTP/SFTP accesses can list directories
  * Support for SAT>IP server dialect for RTSP (satip://)
  * New "concat" access module for concatenating byte streams
+ * Named pipes and device nodes are no longer included in directory listings
+   by default. Use --list-special-files to include them back.
 
 Decoder:
  * OMX GPU-zerocopy support for decoding and display on Android using OpenMax IL
diff --git a/modules/access/directory.c b/modules/access/directory.c
index 4ae3e23..f0e5826 100644
--- a/modules/access/directory.c
+++ b/modules/access/directory.c
@@ -45,6 +45,7 @@ struct access_sys_t
 {
     char *base_uri;
     DIR *dir;
+    bool special_files;
 };
 
 /*****************************************************************************
@@ -68,6 +69,7 @@ int DirInit (access_t *access, DIR *dir)
         goto error;
 
     sys->dir = dir;
+    sys->special_files = var_InheritBool(access, "list-special-files");
 
     access->p_sys = sys;
     access->pf_readdir = DirRead;
@@ -126,14 +128,31 @@ input_item_t *DirRead(access_t *access)
 
         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;
+            case S_IFBLK:
+                if (!sys->special_files)
+                    continue;
+                type = ITEM_TYPE_DISC;
+                break;
+            case S_IFCHR:
+                if (!sys->special_files)
+                    continue;
+                type = ITEM_TYPE_CARD;
+                break;
+            case S_IFIFO:
+                if (!sys->special_files)
+                    continue;
+                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 */
+            default:
+                continue; /* ignore */
         }
 #else
         type = ITEM_TYPE_FILE;
diff --git a/modules/access/fs.c b/modules/access/fs.c
index 89a6cb1..edce520 100644
--- a/modules/access/fs.c
+++ b/modules/access/fs.c
@@ -50,4 +50,6 @@ vlc_module_begin ()
 #endif
     set_callbacks( DirOpen, DirClose )
 
+    add_bool("list-special-files", false, N_("List special files"),
+             N_("Include devices and pipes when listing directories"), true)
 vlc_module_end ()



More information about the vlc-commits mailing list