]> git.sesse.net Git - vlc/blobdiff - modules/access/directory.c
ts demux: fix eac3 mistaken for ac3
[vlc] / modules / access / directory.c
index 8683d93c03fe8551fd2c6e7f06bca55006ed3b34..2798b5bfc34c5f2f8767ff04f38e81a3a04c03fa 100644 (file)
@@ -1,25 +1,25 @@
 /*****************************************************************************
  * directory.c: expands a directory (directory: access plug-in)
  *****************************************************************************
- * Copyright (C) 2002-2008 the VideoLAN team
+ * Copyright (C) 2002-2008 VLC authors and VideoLAN
  * $Id$
  *
  * Authors: Derk-Jan Hartman <hartman at videolan dot org>
  *          RĂ©mi Denis-Courmont
  *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
  * (at your option) any later version.
  *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
 
 /*****************************************************************************
 
 #include <sys/types.h>
 #include <sys/stat.h>
+#include <errno.h>
 #ifdef HAVE_UNISTD_H
 #   include <unistd.h>
 #   include <fcntl.h>
-#elif defined( WIN32 ) && !defined( UNDER_CE )
+#elif defined( WIN32 )
 #   include <io.h>
 #endif
 
@@ -79,6 +80,7 @@ struct access_sys_t
     bool header;
     int i_item_count;
     char *xspf_ext;
+    int (*compar)(const char **a, const char **b);
 };
 
 /* Select non-hidden files only */
@@ -96,6 +98,11 @@ static int collate (const char **a, const char **b)
 #endif
 }
 
+static int version (const char **a, const char **b)
+{
+    return strverscmp (*a, *b);
+}
+
 /*****************************************************************************
  * Open: open the directory
  *****************************************************************************/
@@ -126,7 +133,7 @@ int DirInit (access_t *p_access, DIR *handle)
             uri = NULL;
     }
     else
-        uri = make_URI (p_access->psz_filepath, "file");
+        uri = vlc_path2uri (p_access->psz_filepath, "file");
     if (unlikely(uri == NULL))
         goto error;
 
@@ -137,10 +144,22 @@ int DirInit (access_t *p_access, DIR *handle)
         free (uri);
         goto error;
     }
+
+    char *psz_sort = var_InheritString (p_access, "directory-sort");
+    if (!psz_sort)
+        p_sys->compar = collate;
+    else if (!strcasecmp (psz_sort, "version"))
+        p_sys->compar = version;
+    else if (!strcasecmp (psz_sort, "none"))
+        p_sys->compar = NULL;
+    else
+        p_sys->compar = collate;
+    free(psz_sort);
+
     root->parent = NULL;
     root->handle = handle;
     root->uri = uri;
-    root->filec = vlc_loaddir (handle, &root->filev, visible, collate);
+    root->filec = vlc_loaddir (handle, &root->filev, visible, p_sys->compar);
     if (root->filec < 0)
         root->filev = NULL;
     root->i = 0;
@@ -279,7 +298,7 @@ block_t *DirBlock (access_t *p_access)
             if (unlikely(len == -1))
                 goto fatal;
 
-            block_t *block = block_heap_Alloc (footer, footer, len);
+            block_t *block = block_heap_Alloc (footer, len);
             if (unlikely(block == NULL))
                 free (footer);
             p_access->info.b_eof = true;
@@ -306,22 +325,18 @@ block_t *DirBlock (access_t *p_access)
     {
         DIR *handle;
 #ifdef HAVE_OPENAT
-        int fd = vlc_openat (dirfd (current->handle), entry, O_RDONLY);
+        int fd = vlc_openat (dirfd (current->handle), entry,
+                             O_RDONLY | O_DIRECTORY);
         if (fd == -1)
+        {
+            if (errno == ENOTDIR)
+                goto notdir;
             goto skip; /* File cannot be opened... forget it */
+        }
 
         struct stat st;
-        if (fstat (fd, &st))
-        {
-            close (fd);
-            goto skip; /* cannot stat?! */
-        }
-        if (!S_ISDIR (st.st_mode))
-        {
-            close (fd);
-            goto notdir;
-        }
-        if (p_sys->mode == MODE_NONE
+        if (fstat (fd, &st)
+         || p_sys->mode == MODE_NONE
          || has_inode_loop (current, st.st_dev, st.st_ino)
          || (handle = fdopendir (fd)) == NULL)
         {
@@ -348,7 +363,7 @@ block_t *DirBlock (access_t *p_access)
         }
         sub->parent = current;
         sub->handle = handle;
-        sub->filec = vlc_loaddir (handle, &sub->filev, visible, collate);
+        sub->filec = vlc_loaddir (handle, &sub->filev, visible, p_sys->compar);
         if (sub->filec < 0)
             sub->filev = NULL;
         sub->i = 0;
@@ -435,7 +450,7 @@ notdir:
         p_sys->xspf_ext = NULL;
     free (old_xspf_ext);
 
-    block_t *block = block_heap_Alloc (entry, entry, len);
+    block_t *block = block_heap_Alloc (entry, len);
     if (unlikely(block == NULL))
     {
         free (entry);