mirror of
https://git.ffmpeg.org/ffmpeg.git
synced 2024-09-19 21:06:42 +00:00
fftools/ffmpeg: return errors from assert_file_overwrite() instead of aborting
This commit is contained in:
parent
2d59873fc1
commit
cce294638b
@ -700,7 +700,7 @@ void show_usage(void);
|
|||||||
void remove_avoptions(AVDictionary **a, AVDictionary *b);
|
void remove_avoptions(AVDictionary **a, AVDictionary *b);
|
||||||
void assert_avoptions(AVDictionary *m);
|
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);
|
char *file_read(const char *filename);
|
||||||
AVDictionary *strip_specifiers(const AVDictionary *dict);
|
AVDictionary *strip_specifiers(const AVDictionary *dict);
|
||||||
const AVCodec *find_codec_or_die(void *logctx, const char *name,
|
const AVCodec *find_codec_or_die(void *logctx, const char *name,
|
||||||
|
@ -1277,7 +1277,9 @@ static int dump_attachment(InputStream *ist, const char *filename)
|
|||||||
return AVERROR(EINVAL);
|
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) {
|
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",
|
av_log(ist, AV_LOG_FATAL, "Could not open file %s for writing.\n",
|
||||||
|
@ -2442,7 +2442,9 @@ int of_open(const OptionsContext *o, const char *filename)
|
|||||||
|
|
||||||
if (!(oc->oformat->flags & AVFMT_NOFILE)) {
|
if (!(oc->oformat->flags & AVFMT_NOFILE)) {
|
||||||
/* test if it already exists to avoid losing precious files */
|
/* 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 */
|
/* open the file */
|
||||||
if ((err = avio_open2(&oc->pb, filename, AVIO_FLAG_WRITE,
|
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));
|
filename, av_err2str(err));
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
} else if (strcmp(oc->oformat->name, "image2")==0 && !av_filename_number_test(filename))
|
} else if (strcmp(oc->oformat->name, "image2")==0 && !av_filename_number_test(filename)) {
|
||||||
assert_file_overwrite(filename);
|
err = assert_file_overwrite(filename);
|
||||||
|
if (err < 0)
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
if (o->mux_preload) {
|
if (o->mux_preload) {
|
||||||
av_dict_set_int(&mux->opts, "preload", o->mux_preload*AV_TIME_BASE, 0);
|
av_dict_set_int(&mux->opts, "preload", o->mux_preload*AV_TIME_BASE, 0);
|
||||||
|
@ -652,13 +652,13 @@ const AVCodec *find_codec_or_die(void *logctx, const char *name,
|
|||||||
return codec;
|
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);
|
const char *proto_name = avio_find_protocol_name(filename);
|
||||||
|
|
||||||
if (file_overwrite && no_file_overwrite) {
|
if (file_overwrite && no_file_overwrite) {
|
||||||
fprintf(stderr, "Error, both -y and -n supplied. Exiting.\n");
|
fprintf(stderr, "Error, both -y and -n supplied. Exiting.\n");
|
||||||
exit_program(1);
|
return AVERROR(EINVAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!file_overwrite) {
|
if (!file_overwrite) {
|
||||||
@ -670,13 +670,13 @@ void assert_file_overwrite(const char *filename)
|
|||||||
signal(SIGINT, SIG_DFL);
|
signal(SIGINT, SIG_DFL);
|
||||||
if (!read_yesno()) {
|
if (!read_yesno()) {
|
||||||
av_log(NULL, AV_LOG_FATAL, "Not overwriting - exiting\n");
|
av_log(NULL, AV_LOG_FATAL, "Not overwriting - exiting\n");
|
||||||
exit_program(1);
|
return AVERROR_EXIT;
|
||||||
}
|
}
|
||||||
term_init();
|
term_init();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
av_log(NULL, AV_LOG_FATAL, "File '%s' already exists. Exiting.\n", filename);
|
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)) {
|
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_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");
|
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 */
|
/* read file contents into a string */
|
||||||
|
Loading…
Reference in New Issue
Block a user