aboutsummaryrefslogtreecommitdiffstats
path: root/libavformat/hlsenc.c
diff options
context:
space:
mode:
authorBela Bodecs <bodecsb@vivanet.hu>2016-12-29 12:00:20 +0800
committerBela Bodecs <bodecsb@vivanet.hu>2016-12-29 12:00:20 +0800
commit9ec52a0a9b086d8a916a580ad594c126cd810a45 (patch)
tree312a6be50563ba938129aace0f20b06afe561b0b /libavformat/hlsenc.c
parenta830ab3f3b1dc06dcd565a2145eb6bcbd4fbf381 (diff)
downloadffmpeg-9ec52a0a9b086d8a916a580ad594c126cd810a45.tar.gz
libavformat/hlsenc: fix delete_segments when use_localtime_mkdir
When delete_segments hls_flag is specified, deleting old segments may fail in certain cases when use_localtime_mkdir is in effect and hls_segment_filename expression contains subdirs. This patch fixes this behaviour. Signed-off-by: Bela Bodecs <bodecsb@vivanet.hu> Signed-off-by: Steven Liu <lq@chinaffmpeg.org>
Diffstat (limited to 'libavformat/hlsenc.c')
-rw-r--r--libavformat/hlsenc.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
index cf4d4bd7e9..c9d8e3cee5 100644
--- a/libavformat/hlsenc.c
+++ b/libavformat/hlsenc.c
@@ -194,7 +194,7 @@ static int hls_delete_old_segments(HLSContext *hls) {
}
}
- if (segment) {
+ if (segment && !hls->use_localtime_mkdir) {
if (hls->segment_filename) {
dirname = av_strdup(hls->segment_filename);
} else {
@@ -211,15 +211,20 @@ static int hls_delete_old_segments(HLSContext *hls) {
while (segment) {
av_log(hls, AV_LOG_DEBUG, "deleting old segment %s\n",
segment->filename);
- path_size = strlen(dirname) + strlen(segment->filename) + 1;
+ path_size = (hls->use_localtime_mkdir ? 0 : strlen(dirname)) + strlen(segment->filename) + 1;
path = av_malloc(path_size);
if (!path) {
ret = AVERROR(ENOMEM);
goto fail;
}
- av_strlcpy(path, dirname, path_size);
- av_strlcat(path, segment->filename, path_size);
+ if (hls->use_localtime_mkdir)
+ av_strlcpy(path, segment->filename, path_size);
+ else { // segment->filename contains basename only
+ av_strlcpy(path, dirname, path_size);
+ av_strlcat(path, segment->filename, path_size);
+ }
+
if (unlink(path) < 0) {
av_log(hls, AV_LOG_ERROR, "failed to delete old segment %s: %s\n",
path, strerror(errno));