X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavformat%2Fcache.c;h=1e19dafc6a585cc71d53a0f03acc610105fd6cc2;hb=7b6012efaae549b8e624876dba9550cb003f98b1;hp=66bbbf54c9abf4e9a5ec1e479efadcb8d2bb9d87;hpb=ef71ef5f30ddf1cd61e46628a04608892caf76d2;p=ffmpeg diff --git a/libavformat/cache.c b/libavformat/cache.c index 66bbbf54c9a..1e19dafc6a5 100644 --- a/libavformat/cache.c +++ b/libavformat/cache.c @@ -54,6 +54,7 @@ typedef struct CacheEntry { typedef struct Context { AVClass *class; int fd; + char *filename; struct AVTreeNode *root; int64_t logical_pos; int64_t cache_pos; @@ -72,6 +73,7 @@ static int cmp(const void *key, const void *node) static int cache_open(URLContext *h, const char *arg, int flags, AVDictionary **options) { + int ret; char *buffername; Context *c= h->priv_data; @@ -83,8 +85,12 @@ static int cache_open(URLContext *h, const char *arg, int flags, AVDictionary ** return c->fd; } - unlink(buffername); - av_freep(&buffername); + ret = unlink(buffername); + + if (ret >= 0) + av_freep(&buffername); + else + c->filename = buffername; return ffurl_open_whitelist(&c->inner, arg, flags, &h->interrupt_callback, options, h->protocol_whitelist, h->protocol_blacklist, h); @@ -292,12 +298,19 @@ static int enu_free(void *opaque, void *elem) static int cache_close(URLContext *h) { Context *c= h->priv_data; + int ret; av_log(h, AV_LOG_INFO, "Statistics, cache hits:%"PRId64" cache misses:%"PRId64"\n", c->cache_hit, c->cache_miss); close(c->fd); - ffurl_close(c->inner); + if (c->filename) { + ret = unlink(c->filename); + if (ret < 0) + av_log(h, AV_LOG_ERROR, "Could not delete %s.\n", c->filename); + av_freep(&c->filename); + } + ffurl_closep(&c->inner); av_tree_enumerate(c->root, NULL, NULL, enu_free); av_tree_destroy(c->root); @@ -313,7 +326,7 @@ static const AVOption options[] = { }; static const AVClass cache_context_class = { - .class_name = "Cache", + .class_name = "cache", .item_name = av_default_item_name, .option = options, .version = LIBAVUTIL_VERSION_INT,