{ "test" , share__no_argument, 0, 't' },
{ "stdout" , share__no_argument, 0, 'c' },
{ "silent" , share__no_argument, 0, 's' },
+ { "force" , share__no_argument, 0, 'f' },
{ "delete-input-file", share__no_argument, 0, 0 },
{ "output-prefix" , share__required_argument, 0, 0 },
{ "output-name" , share__required_argument, 0, 'o' },
*/
{ "no-decode-through-errors" , share__no_argument, 0, 0 },
{ "no-silent" , share__no_argument, 0, 0 },
+ { "no-force" , share__no_argument, 0, 0 },
{ "no-seektable" , share__no_argument, 0, 0 },
{ "no-delete-input-file" , share__no_argument, 0, 0 },
{ "no-replay-gain" , share__no_argument, 0, 0 },
FLAC__bool mode_decode;
FLAC__bool verify;
FLAC__bool verbose;
+ FLAC__bool force_file_overwrite;
FLAC__bool continue_through_decode_errors;
replaygain_synthesis_spec_t replaygain_synthesis_spec;
FLAC__bool lax;
option_values.mode_decode = false;
option_values.verify = false;
option_values.verbose = true;
+ option_values.force_file_overwrite = false;
option_values.continue_through_decode_errors = false;
option_values.replaygain_synthesis_spec.apply = false;
option_values.replaygain_synthesis_spec.use_album_gain = true;
int short_option;
int option_index = 1;
FLAC__bool had_error = false;
- const char *short_opts = "0123456789ab:cdeFhHl:mMo:pP:q:r:sS:tT:vV";
+ const char *short_opts = "0123456789ab:cdefFhHl:mMo:pP:q:r:sS:tT:vV";
while ((short_option = share__getopt_long(argc, argv, short_opts, long_options_, &option_index)) != -1) {
switch (short_option) {
else if(0 == strcmp(long_option, "no-silent")) {
option_values.verbose = true;
}
+ else if(0 == strcmp(long_option, "no-force")) {
+ option_values.force_file_overwrite = false;
+ }
else if(0 == strcmp(long_option, "no-seektable")) {
option_values.num_requested_seek_points = 0;
option_values.requested_seek_points[0] = '\0';
case 's':
option_values.verbose = false;
break;
+ case 'f':
+ option_values.force_file_overwrite = true;
+ break;
case 'o':
FLAC__ASSERT(0 != option_argument);
option_values.cmdline_forced_outfilename = option_argument;
printf(" -a, --analyze Same as -d except an analysis file is written\n");
printf(" -c, --stdout Write output to stdout\n");
printf(" -s, --silent Do not write runtime encode/decode statistics\n");
+ printf(" -f, --force Force overwriting of output files\n");
printf(" -o, --output-name=FILENAME Force the output file name\n");
printf(" --output-prefix=STRING Prepend STRING to output names\n");
printf(" --delete-input-file Deletes after a successful encode/decode\n");
printf(" --no-sector-align\n");
printf(" --no-seektable\n");
printf(" --no-silent\n");
+ printf(" --no-force\n");
printf(" --no-verify\n");
}
printf(" -a, --analyze Same as -d except an analysis file is written\n");
printf(" -c, --stdout Write output to stdout\n");
printf(" -s, --silent Do not write runtime encode/decode statistics\n");
+ printf(" -f, --force Force overwriting of output files\n");
printf(" -o, --output-name=FILENAME Force the output file name; usually flac just\n");
printf(" changes the extension. May only be used when\n");
printf(" encoding a single file. May not be used in\n");
printf(" --no-sector-align\n");
printf(" --no-seektable\n");
printf(" --no-silent\n");
+ printf(" --no-force\n");
printf(" --no-verify\n");
}
return 1;
}
+ /*
+ * Error if output file already exists (and -f not used).
+ * Use grabbag__file_get_filesize() as a cheap way to check.
+ */
+ if(!option_values.test_only && !option_values.force_file_overwrite && grabbag__file_get_filesize(outfilename) != (off_t)(-1)) {
+ fprintf(stderr, "ERROR: output file %s already exists, use -f to override\n", outfilename);
+ return 1;
+ }
+
if(0 == strcmp(infilename, "-")) {
infilesize = -1;
encode_infile = grabbag__file_get_binary_stdin();
return 1;
}
+ /*
+ * Error if output file already exists (and -f not used).
+ * Use grabbag__file_get_filesize() as a cheap way to check.
+ */
+ if(!option_values.test_only && !option_values.force_file_overwrite && grabbag__file_get_filesize(outfilename) != (off_t)(-1)) {
+ fprintf(stderr, "ERROR: output file %s already exists, use -f to override\n", outfilename);
+ return 1;
+ }
+
if(!option_values.test_only && !option_values.analyze) {
if(option_values.force_raw_format && (option_values.format_is_big_endian < 0 || option_values.format_is_unsigned_samples < 0))
return usage_error("ERROR: for decoding to a raw file you must specify a value for --endian and --sign\n");