]> git.sesse.net Git - ffmpeg/commitdiff
hlsenc: write playlist into a temp file and replace the original atomically
authorHendrik Leppkes <h.leppkes@gmail.com>
Fri, 20 Feb 2015 11:54:58 +0000 (12:54 +0100)
committerMartin Storsjö <martin@martin.st>
Fri, 20 Feb 2015 21:55:28 +0000 (23:55 +0200)
Signed-off-by: Martin Storsjö <martin@martin.st>
libavformat/hlsenc.c

index d8fd2546efa85660aacf19c3238e26079fe2e610..21c952630d201332f897231ffbf2705f02508c6c 100644 (file)
@@ -134,9 +134,11 @@ 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->size);
 
-    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;
 
@@ -168,6 +170,8 @@ static int hls_window(AVFormatContext *s, int last)
 
 fail:
     avio_closep(&out);
+    if (ret >= 0)
+        ff_rename(temp_filename, s->filename);
     return ret;
 }