[vlc-commits] playlist: indirectly write when exporting to ml.xspf

Francois Cartegnie git at videolan.org
Fri Feb 14 15:20:14 CET 2014


vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Fri Feb 14 15:18:11 2014 +0100| [34174cd25cbaeb9aa6fd9a9f30ffc1be6a6cb782] | committer: Francois Cartegnie

playlist: indirectly write when exporting to ml.xspf

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

 src/playlist/loadsave.c |   31 ++++++++++++++++++++++++-------
 1 file changed, 24 insertions(+), 7 deletions(-)

diff --git a/src/playlist/loadsave.c b/src/playlist/loadsave.c
index a789c9f..92ba806 100644
--- a/src/playlist/loadsave.c
+++ b/src/playlist/loadsave.c
@@ -182,19 +182,19 @@ int playlist_MLLoad( playlist_t *p_playlist )
 
 int playlist_MLDump( playlist_t *p_playlist )
 {
-    char *psz_datadir;
+    char *psz_temp;
 
-    psz_datadir = config_GetUserDir( VLC_DATA_DIR );
+    psz_temp = config_GetUserDir( VLC_DATA_DIR );
 
-    if( !psz_datadir ) /* XXX: This should never happen */
+    if( !psz_temp ) /* XXX: This should never happen */
     {
         msg_Err( p_playlist, "no data directory, cannot save media library") ;
         return VLC_EGENERIC;
     }
 
-    char psz_dirname[ strlen( psz_datadir ) + sizeof( DIR_SEP "ml.xspf")];
-    strcpy( psz_dirname, psz_datadir );
-    free( psz_datadir );
+    char psz_dirname[ strlen( psz_temp ) + sizeof( DIR_SEP "ml.xspf")];
+    strcpy( psz_dirname, psz_temp );
+    free( psz_temp );
     if( config_CreateDir( (vlc_object_t *)p_playlist, psz_dirname ) )
     {
         return VLC_EGENERIC;
@@ -202,8 +202,25 @@ int playlist_MLDump( playlist_t *p_playlist )
 
     strcat( psz_dirname, DIR_SEP "ml.xspf" );
 
-    playlist_Export( p_playlist, psz_dirname, p_playlist->p_media_library,
+    if ( asprintf( &psz_temp, "%s.tmp", psz_dirname ) < 1 )
+        return VLC_EGENERIC;
+
+    int i_ret = playlist_Export( p_playlist, psz_temp, p_playlist->p_media_library,
                      "export-xspf" );
+    if ( i_ret != VLC_SUCCESS )
+    {
+        vlc_unlink( psz_temp );
+        free( psz_temp );
+        return i_ret;
+    }
 
+    i_ret = vlc_rename( psz_temp, psz_dirname );
+    free( psz_temp );
+    if( i_ret == -1 )
+    {
+        msg_Err( p_playlist, "could not rename %s.tmp: %s",
+                 psz_dirname, vlc_strerror_c(errno) );
+        return VLC_EGENERIC;
+    }
     return VLC_SUCCESS;
 }



More information about the vlc-commits mailing list