[vlc-devel] [PATCH] sftp: do not try to open directory as a file

Petri Hintukainen phintuka at users.sourceforge.net
Fri Mar 13 10:04:48 CET 2015


From: Petri Hintukainen <phintuka at gmail.com>

Usually opening a directory as a file succeeds.
---
 modules/access/sftp.c | 22 +++++++++++++---------
 1 file changed, 13 insertions(+), 9 deletions(-)

diff --git a/modules/access/sftp.c b/modules/access/sftp.c
index b4577ac..a63ca95 100644
--- a/modules/access/sftp.c
+++ b/modules/access/sftp.c
@@ -225,14 +225,6 @@ static int Open( vlc_object_t* p_this )
         goto error;
     }
 
-    /* Open the given file */
-    p_sys->file = libssh2_sftp_open( p_sys->sftp_session, url.psz_path, LIBSSH2_FXF_READ, 0 );
-    if( !p_sys->file )
-    {
-        msg_Err( p_access, "Unable to open the remote file %s", url.psz_path );
-        goto error;
-    }
-
     /* Get some information */
     LIBSSH2_SFTP_ATTRIBUTES attributes;
     if( libssh2_sftp_stat( p_sys->sftp_session, url.psz_path, &attributes ) )
@@ -240,7 +232,19 @@ static int Open( vlc_object_t* p_this )
         msg_Err( p_access, "Impossible to get information about the remote file %s", url.psz_path );
         goto error;
     }
-    p_sys->filesize = attributes.filesize;
+
+    if( !LIBSSH2_SFTP_S_ISDIR( attributes.permissions ))
+    {
+        /* Open the given file */
+        p_sys->file = libssh2_sftp_open( p_sys->sftp_session, url.psz_path, LIBSSH2_FXF_READ, 0 );
+        p_sys->filesize = attributes.filesize;
+    }
+
+    if( !p_sys->file )
+    {
+        msg_Err( p_access, "Unable to open the remote path %s", url.psz_path );
+        goto error;
+    }
 
     p_sys->i_read_size = var_InheritInteger( p_access, "sftp-readsize" );
 
-- 
2.1.0




More information about the vlc-devel mailing list