]> git.sesse.net Git - vlc/commitdiff
metaengine: folder: test uri against folder first. (fix #10380)
authorFrancois Cartegnie <fcvlcdev@free.fr>
Sun, 9 Mar 2014 20:50:34 +0000 (21:50 +0100)
committerFrancois Cartegnie <fcvlcdev@free.fr>
Sun, 9 Mar 2014 20:55:39 +0000 (21:55 +0100)
because make_path strips last segment

modules/meta_engine/folder.c

index 5cdb6eabb148fcc6fa805594e01762d50188aa7b..2e463eb0d5908f7e8c9e6d457e21cd6920e45525 100644 (file)
@@ -75,24 +75,54 @@ static int FindMeta( vlc_object_t *p_this )
     art_finder_t *p_finder = (art_finder_t *)p_this;
     input_item_t *p_item = p_finder->p_item;
     bool b_have_art = false;
+    struct stat statinfo;
+    char *psz_path = NULL;
 
     if( !p_item )
         return VLC_EGENERIC;
 
-    char *psz_dir = input_item_GetURI( p_item );
-    if( !psz_dir )
+    char *psz_uri = input_item_GetURI( p_item );
+    if( !psz_uri )
         return VLC_EGENERIC;
 
-    char *psz_path = make_path( psz_dir );
-    free( psz_dir );
-    if( psz_path == NULL )
-        return VLC_EGENERIC;
+    if ( *psz_uri && psz_uri[strlen( psz_uri ) - 1] != DIR_SEP_CHAR )
+    {
+        if ( asprintf( &psz_path, "%s"DIR_SEP, psz_uri ) == -1 )
+        {
+            free( psz_uri );
+            return VLC_EGENERIC;
+        }
+        char *psz_basedir = make_path( psz_path );
+        FREENULL( psz_path );
+        if( psz_basedir == NULL )
+        {
+            free( psz_uri );
+            return VLC_EGENERIC;
+        }
+        if( vlc_stat( psz_basedir, &statinfo ) == 0 && S_ISDIR(statinfo.st_mode) )
+            psz_path = psz_basedir;
+        else
+            free( psz_basedir );
+    }
+
+    if ( psz_path == NULL )
+    {
+        char *psz_basedir = make_path( psz_uri );
+        if( psz_basedir == NULL )
+        {
+            free( psz_uri );
+            return VLC_EGENERIC;
+        }
+
+        char *psz_buf = strrchr( psz_basedir, DIR_SEP_CHAR );
+        if( psz_buf )
+            *++psz_buf = '\0';
+        else
+            *psz_basedir = '\0'; /* relative path */
+        psz_path = psz_basedir;
+    }
 
-    char *psz_buf = strrchr( psz_path, DIR_SEP_CHAR );
-    if( psz_buf )
-        *++psz_buf = '\0';
-    else
-        *psz_path = '\0'; /* relative path */
+    free( psz_uri );
 
     for( int i = -1; !b_have_art && i < i_covers; i++ )
     {
@@ -118,8 +148,7 @@ static int FindMeta( vlc_object_t *p_this )
         if( unlikely(filepath == NULL) )
             continue;
 
-        struct stat dummy;
-        if( vlc_stat( filepath, &dummy ) == 0 )
+        if( vlc_stat( filepath, &statinfo ) == 0 && S_ISREG(statinfo.st_mode) )
         {
             char *psz_uri = vlc_path2uri( filepath, "file" );
             if( psz_uri )