From patchwork Fri May 24 05:54:45 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gyan Doshi X-Patchwork-Id: 13267 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id C92024485DC for ; Fri, 24 May 2019 08:55:12 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id A8549680AE5; Fri, 24 May 2019 08:55:12 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mx1.mailbox.org (mx1.mailbox.org [80.241.60.212]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 0641168095C for ; Fri, 24 May 2019 08:55:05 +0300 (EEST) Received: from smtp2.mailbox.org (smtp2.mailbox.org [80.241.60.241]) (using TLSv1.2 with cipher ECDHE-RSA-CHACHA20-POLY1305 (256/256 bits)) (No client certificate requested) by mx1.mailbox.org (Postfix) with ESMTPS id EE281506D8 for ; Fri, 24 May 2019 07:55:04 +0200 (CEST) X-Virus-Scanned: amavisd-new at heinlein-support.de Received: from smtp2.mailbox.org ([80.241.60.241]) by spamfilter01.heinlein-hosting.de (spamfilter01.heinlein-hosting.de [80.241.56.115]) (amavisd-new, port 10030) with ESMTP id gyiVAhvBUrvr for ; Fri, 24 May 2019 07:54:48 +0200 (CEST) To: ffmpeg-devel@ffmpeg.org References: <20190522130745.zpljeoow76g5xhtz@phare.normalesup.org> <2b67cafd-f865-a901-a3ab-e54836c52dfb@gyani.pro> <20190523154307.GQ3118@michaelspb> <20190523175001.axnvm5n2x3mfoktf@phare.normalesup.org> <847c4f6d-5136-78aa-89c6-07bee14a46ec@gyani.pro> <20190523192843.hghfbmrz4ztl572a@phare.normalesup.org> <905f4389-cdbf-5cf8-f157-e9bf04f1b942@gyani.pro> From: Gyan Message-ID: <10aefe61-96b9-e395-a34a-b9e2403153c5@gyani.pro> Date: Fri, 24 May 2019 11:24:45 +0530 MIME-Version: 1.0 In-Reply-To: Content-Language: en-US Subject: Re: [FFmpeg-devel] [PATCH] avformat/cache - delete cache file after closing handle X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" On 24-05-2019 02:06 AM, Hendrik Leppkes wrote: > On Thu, May 23, 2019 at 9:55 PM Gyan wrote: >> >> >> On 24-05-2019 12:58 AM, Nicolas George wrote: >>> Gyan (12019-05-24): >>>> avpriv_io_delete will call the file protocol's delete which is guarded >>>> with a header check, not done here. >>> Do you have report of a build failure caused by unlink()? >> No. I assume that the guard in the file proto callback is germane and >> the patch was subject to review. Do you know it isn't? >> >>>> Since we now have a generic wrapper function, isn't that better for >>>> future maintenance? >>> Not that I see. Something that makes it harder to follow the code from >>> the call site to the actual function is not good for maintenance. >> The point of modularizing the op here is to have a single interface - >> why stick with a direct external call? At the time it was added, there >> was no alternative. >> Don't mind it either way, but this feels like a useless game of ping-pong. >> > Just stick to unlink. If there is no reason to change it, then the > preference is to just keep it as-is. > We're not using the file protocol to create the file, so no reason to > use it to delete it. Revised. Gyan From ce3f3853af36b6a601e013da0257d8e7b34b7ede Mon Sep 17 00:00:00 2001 From: Gyan Doshi Date: Wed, 22 May 2019 18:05:04 +0530 Subject: [PATCH v4] avformat/cache - delete cache file after closing handle Verified that cache files get deleted on Windows. --- libavformat/cache.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/libavformat/cache.c b/libavformat/cache.c index 66bbbf54c9..3425be9350 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,11 +298,18 @@ 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); + 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_close(c->inner); av_tree_enumerate(c->root, NULL, NULL, enu_free); av_tree_destroy(c->root);