vlc | branch: master | Rémi Denis-Courmont <[email protected]> | Mon Sep 3 18:53:04 2012 +0300| [e76b3523c94dee38c9454115ed0b7e978323dd2f] | committer: Rémi Denis-Courmont
file out: option not to overwrite an existing file If --no-sout-file-overwrite is specified, the access output will refuse to overwrite an existing file. Overwrite is enabled by default for backward compatibility with existing command lines. > http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=e76b3523c94dee38c9454115ed0b7e978323dd2f --- modules/access_output/file.c | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/modules/access_output/file.c b/modules/access_output/file.c index b45fa1b..ec874ec 100644 --- a/modules/access_output/file.c +++ b/modules/access_output/file.c @@ -61,6 +61,9 @@ static int Open ( vlc_object_t * ); static void Close( vlc_object_t * ); #define SOUT_CFG_PREFIX "sout-file-" +#define OVERWRITE_TEXT N_("Overwrite existing file") +#define OVERWRITE_LONGTEXT N_( \ + "If the file already exists, it will be overwritten.") #define APPEND_TEXT N_("Append to file") #define APPEND_LONGTEXT N_( "Append to file if it exists instead " \ "of replacing it.") @@ -74,6 +77,8 @@ vlc_module_begin () set_category( CAT_SOUT ) set_subcategory( SUBCAT_SOUT_ACO ) add_shortcut( "file", "stream", "fd" ) + add_bool( SOUT_CFG_PREFIX "overwrite", true, OVERWRITE_TEXT, + OVERWRITE_LONGTEXT, true ) add_bool( SOUT_CFG_PREFIX "append", false, APPEND_TEXT,APPEND_LONGTEXT, true ) #ifdef O_SYNC @@ -89,6 +94,7 @@ vlc_module_end () *****************************************************************************/ static const char *const ppsz_sout_options[] = { "append", + "overwrite", #ifdef O_SYNC "sync", #endif @@ -116,6 +122,7 @@ static int Open( vlc_object_t *p_this ) return VLC_EGENERIC; } + bool overwrite = var_GetBool (p_access, SOUT_CFG_PREFIX"overwrite"); bool append = var_GetBool( p_access, SOUT_CFG_PREFIX "append" ); if (!strcmp (p_access->psz_access, "fd")) @@ -152,20 +159,24 @@ static int Open( vlc_object_t *p_this ) } else { - char *psz_tmp = str_format_time( p_access->psz_path ); - path_sanitize( psz_tmp ); - - fd = vlc_open( psz_tmp, O_RDWR | O_CREAT | O_LARGEFILE | + char *path = str_format_time (p_access->psz_path); + path_sanitize (path); + + int flags = O_RDWR | O_CREAT | O_LARGEFILE; + if (!overwrite) + flags |= O_EXCL; + if (!append) + flags |= O_TRUNC; #ifdef O_SYNC - (var_GetBool( p_access, SOUT_CFG_PREFIX "sync" ) ? O_SYNC : 0) | + if (var_GetBool (p_access, SOUT_CFG_PREFIX"sync")) + flags |= O_SYNC; #endif - (append ? 0 : O_TRUNC), 0666 ); - free( psz_tmp ); + fd = vlc_open (path, flags, 0666); + if (fd == -1) + msg_Err (p_access, "cannot create %s: %m", path); + free (path); if (fd == -1) - { - msg_Err (p_access, "cannot create %s: %m", p_access->psz_path); return VLC_EGENERIC; - } } p_access->pf_write = Write; _______________________________________________ vlc-commits mailing list [email protected] http://mailman.videolan.org/listinfo/vlc-commits
