aboutsummaryrefslogtreecommitdiffstats
path: root/libavformat/hlsenc.c
diff options
context:
space:
mode:
authorHendrik Leppkes <h.leppkes@gmail.com>2015-02-20 12:55:14 +0100
committerMichael Niedermayer <michaelni@gmx.at>2015-02-21 01:50:06 +0100
commitda97e4c64a289ac83c3d53554ff36cdd6586537c (patch)
tree25a567c548f855373fd938a18b262f0b12bc5147 /libavformat/hlsenc.c
parent0d6ae067660f6fbca524b9a77b857d3afc9f8030 (diff)
downloadffmpeg-da97e4c64a289ac83c3d53554ff36cdd6586537c.tar.gz
hlsenc: write playlist into a temp file and replace the original atomically
Reviewed-by: Lukasz Marek <lukasz.m.luki2@gmail.com> Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavformat/hlsenc.c')
-rw-r--r--libavformat/hlsenc.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
index 1831c177ad..0f14e90889 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);
return ret;
}