From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 8C17C4622F for ; Thu, 13 Jul 2023 10:58:26 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 09CD368C694; Thu, 13 Jul 2023 13:57:53 +0300 (EEST) Received: from mail0.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 76CEA68C32F for ; Thu, 13 Jul 2023 13:57:44 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 3D67E240591 for ; Thu, 13 Jul 2023 12:57:44 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id sg3kq2qKx5hH for ; Thu, 13 Jul 2023 12:57:43 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail0.khirnov.net (Postfix) with ESMTPS id 6D5ED2404F5 for ; Thu, 13 Jul 2023 12:57:41 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 36C253A128F for ; Thu, 13 Jul 2023 12:57:35 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Thu, 13 Jul 2023 12:55:26 +0200 Message-Id: <20230713105553.21052-6-anton@khirnov.net> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230713105553.21052-1-anton@khirnov.net> References: <20230713105553.21052-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 06/33] fftools/ffmpeg: return errors from assert_file_overwrite() instead of aborting X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: --- fftools/ffmpeg.h | 2 +- fftools/ffmpeg_demux.c | 4 +++- fftools/ffmpeg_mux_init.c | 11 ++++++++--- fftools/ffmpeg_opt.c | 12 +++++++----- 4 files changed, 19 insertions(+), 10 deletions(-) diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index 3201163a4f..30020cd0f8 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -700,7 +700,7 @@ void show_usage(void); void remove_avoptions(AVDictionary **a, AVDictionary *b); void assert_avoptions(AVDictionary *m); -void assert_file_overwrite(const char *filename); +int assert_file_overwrite(const char *filename); char *file_read(const char *filename); AVDictionary *strip_specifiers(const AVDictionary *dict); const AVCodec *find_codec_or_die(void *logctx, const char *name, diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c index ab99daf9f8..bc915178ec 100644 --- a/fftools/ffmpeg_demux.c +++ b/fftools/ffmpeg_demux.c @@ -1277,7 +1277,9 @@ static int dump_attachment(InputStream *ist, const char *filename) return AVERROR(EINVAL); } - assert_file_overwrite(filename); + ret = assert_file_overwrite(filename); + if (ret < 0) + return ret; if ((ret = avio_open2(&out, filename, AVIO_FLAG_WRITE, &int_cb, NULL)) < 0) { av_log(ist, AV_LOG_FATAL, "Could not open file %s for writing.\n", diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c index 8a3e7b98cf..4d40ceda05 100644 --- a/fftools/ffmpeg_mux_init.c +++ b/fftools/ffmpeg_mux_init.c @@ -2442,7 +2442,9 @@ int of_open(const OptionsContext *o, const char *filename) if (!(oc->oformat->flags & AVFMT_NOFILE)) { /* test if it already exists to avoid losing precious files */ - assert_file_overwrite(filename); + err = assert_file_overwrite(filename); + if (err < 0) + return err; /* open the file */ if ((err = avio_open2(&oc->pb, filename, AVIO_FLAG_WRITE, @@ -2452,8 +2454,11 @@ int of_open(const OptionsContext *o, const char *filename) filename, av_err2str(err)); return err; } - } else if (strcmp(oc->oformat->name, "image2")==0 && !av_filename_number_test(filename)) - assert_file_overwrite(filename); + } else if (strcmp(oc->oformat->name, "image2")==0 && !av_filename_number_test(filename)) { + err = assert_file_overwrite(filename); + if (err < 0) + return err; + } if (o->mux_preload) { av_dict_set_int(&mux->opts, "preload", o->mux_preload*AV_TIME_BASE, 0); diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c index 7f22b22604..300f042660 100644 --- a/fftools/ffmpeg_opt.c +++ b/fftools/ffmpeg_opt.c @@ -652,13 +652,13 @@ const AVCodec *find_codec_or_die(void *logctx, const char *name, return codec; } -void assert_file_overwrite(const char *filename) +int assert_file_overwrite(const char *filename) { const char *proto_name = avio_find_protocol_name(filename); if (file_overwrite && no_file_overwrite) { fprintf(stderr, "Error, both -y and -n supplied. Exiting.\n"); - exit_program(1); + return AVERROR(EINVAL); } if (!file_overwrite) { @@ -670,13 +670,13 @@ void assert_file_overwrite(const char *filename) signal(SIGINT, SIG_DFL); if (!read_yesno()) { av_log(NULL, AV_LOG_FATAL, "Not overwriting - exiting\n"); - exit_program(1); + return AVERROR_EXIT; } term_init(); } else { av_log(NULL, AV_LOG_FATAL, "File '%s' already exists. Exiting.\n", filename); - exit_program(1); + return AVERROR_EXIT; } } } @@ -689,10 +689,12 @@ void assert_file_overwrite(const char *filename) if (!strcmp(filename, file->ctx->url)) { av_log(NULL, AV_LOG_FATAL, "Output %s same as Input #%d - exiting\n", filename, i); av_log(NULL, AV_LOG_WARNING, "FFmpeg cannot edit existing files in-place.\n"); - exit_program(1); + return AVERROR(EINVAL); } } } + + return 0; } /* read file contents into a string */ -- 2.40.1 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".