[FFmpeg-devel] [PATCH 2/2] hlsenc: write playlist into a temp file and replace the original atomically

Michael Niedermayer michaelni at gmx.at
Fri Feb 20 13:38:21 CET 2015


On Fri, Feb 20, 2015 at 12:55:14PM +0100, Hendrik Leppkes wrote:
> ---
>  libavformat/hlsenc.c | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
> index 1831c17..0f14e90 100644
> --- a/libavformat/hlsenc.c
> +++ b/libavformat/hlsenc.c
> @@ -242,10 +242,12 @@ static int hls_window(AVFormatContext *s, int last)
>      int target_duration = 0;
>      int ret = 0;
>      AVIOContext *out = NULL;
> +    char temp_filename[1024];
>      int64_t sequence = FFMAX(hls->start_sequence, hls->sequence - hls->nb_entries);
>      int version = hls->flags & HLS_SINGLE_FILE ? 4 : 3;
>  
> -    if ((ret = avio_open2(&out, s->filename, AVIO_FLAG_WRITE,
> +    snprintf(temp_filename, sizeof(temp_filename), "%s.tmp", s->filename);
> +    if ((ret = avio_open2(&out, temp_filename, AVIO_FLAG_WRITE,
>                            &s->interrupt_callback, NULL)) < 0)
>          goto fail;
>  
> @@ -280,6 +282,8 @@ static int hls_window(AVFormatContext *s, int last)
>  
>  fail:
>      avio_closep(&out);
> +    if (ret >= 0)
> +        ff_rename(temp_filename, s->filename, s);

what if s->filename is not a local file ?
or am i missing something that prevents that ?

[...]

-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Freedom in capitalist society always remains about the same as it was in
ancient Greek republics: Freedom for slave owners. -- Vladimir Lenin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 181 bytes
Desc: Digital signature
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20150220/99fc5dbd/attachment.asc>


More information about the ffmpeg-devel mailing list