[vlc-commits] dvb: scan: remove dir walk for matching filename

Francois Cartegnie git at videolan.org
Sun Apr 10 13:56:09 CEST 2016


vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Wed Apr  6 14:02:26 2016 +0200| [de93a73b9e6d2a48d9a471c00db5420f5ea2591d] | committer: Francois Cartegnie

dvb: scan: remove dir walk for matching filename

nonsense testing each file from dir instead of
directly opening the file by path.

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

 modules/access/dvb/scan.c |   56 +++++++++------------------------------------
 modules/access/dvb/scan.h |    1 -
 2 files changed, 11 insertions(+), 46 deletions(-)

diff --git a/modules/access/dvb/scan.c b/modules/access/dvb/scan.c
index ff08c85..fba66cb 100644
--- a/modules/access/dvb/scan.c
+++ b/modules/access/dvb/scan.c
@@ -248,56 +248,22 @@ static int ScanDvbSNextFast( scan_t *p_scan, scan_configuration_t *p_cfg, double
     /* if there are no transponders in mem, laod from config file */
     if( !*pi_count )
     {
-        DIR *p_dir;
-
-        char *psz_dir = NULL;
+        char *psz_path = NULL;
         char *data_dir = config_GetDataDir();
 
-        if( asprintf( &psz_dir, "%s" DIR_SEP "dvb" DIR_SEP "dvb-s", data_dir ) == -1 )
-            psz_dir = NULL;
-        free( data_dir );
-
-        if( !psz_dir )
-        {
-            free( p_scan->parameter.sat_info.psz_name );
-            return VLC_EGENERIC;
-        }
-
-        /* open config directory */
-        if( !( p_dir = vlc_opendir( psz_dir ) ) )
+        if( !data_dir ||
+             asprintf( &psz_path, "%s" DIR_SEP "dvb" DIR_SEP "dvb-s" DIR_SEP "%s", data_dir,
+                       p_scan->parameter.sat_info.psz_name ) == -1 )
         {
-            msg_Err( p_scan->p_obj, "could not open satellite info directory (%s)", psz_dir );
-            free( p_scan->parameter.sat_info.psz_name );
-            return VLC_EGENERIC;
-        }
-
-        /* find the requested file in the directory */
-        for( ; ; ) {
-            const char *psz_filename = vlc_readdir( p_dir );
-
-            if( psz_filename == NULL )
-                break;
-
-            if( !strncmp( p_scan->parameter.sat_info.psz_name, psz_filename, 20 ) )
-            {
-                if( asprintf( &p_scan->parameter.sat_info.psz_path, "%s" DIR_SEP "%s", psz_dir, psz_filename ) == -1 )
-                    p_scan->parameter.sat_info.psz_path = NULL;
-                break;
-            }
-        }
-
-        closedir( p_dir );
-
-        if( !p_scan->parameter.sat_info.psz_path )
-        {
-            msg_Err( p_scan->p_obj, "could not find satellite config (%s)", p_scan->parameter.sat_info.psz_name );
+            free( data_dir );
             free( p_scan->parameter.sat_info.psz_name );
             return VLC_EGENERIC;
         }
+        free( data_dir );
 
-        msg_Dbg( p_scan->p_obj, "using satellite config file (%s)", p_scan->parameter.sat_info.psz_path );
+        msg_Dbg( p_scan->p_obj, "using satellite config file (%s)", psz_path );
 
-        FILE *f = vlc_fopen( p_scan->parameter.sat_info.psz_path, "r" );
+        FILE *f = vlc_fopen( psz_path, "r" );
 
         /* parse file */
         if( f )
@@ -340,13 +306,13 @@ static int ScanDvbSNextFast( scan_t *p_scan, scan_configuration_t *p_cfg, double
         }
         else
         {
-            msg_Err( p_scan->p_obj, "failed to open satellite file (%s)", p_scan->parameter.sat_info.psz_path );
+            msg_Err( p_scan->p_obj, "failed to open satellite file (%s)", psz_path );
             free( p_scan->parameter.sat_info.psz_name );
-            free( p_scan->parameter.sat_info.psz_path );
+            free( psz_path );
             return VLC_EGENERIC;
         }
         free( p_scan->parameter.sat_info.psz_name );
-        free( p_scan->parameter.sat_info.psz_path );
+        free( psz_path );
     }
 
     if( p_scan->i_index < *pi_count )
diff --git a/modules/access/dvb/scan.h b/modules/access/dvb/scan.h
index 78c32a3..578413a 100644
--- a/modules/access/dvb/scan.h
+++ b/modules/access/dvb/scan.h
@@ -70,7 +70,6 @@ typedef struct scan_parameter_t
     struct
     {
         char *psz_name;         /* satellite name */
-        char *psz_path;         /* config file path */
 
         scan_dvbs_transponder_t *p_transponders;
         unsigned i_count;



More information about the vlc-commits mailing list