Skip to content

Commit db68b68

Browse files
author
twojstaryzdomu
committed
Abort further processing if output file already exists
1 parent 8813db3 commit db68b68

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

ChangeLog

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,5 @@
7272
the output filenames as done by default in earlier releases.
7373

7474
Sealed various memory leaks. Refactored exit statements.
75+
76+
Abort further processing if output file already exists.

bchunk.c

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@
4747
"\tGodmar Back <[email protected]>, Colas Nahaboo <[email protected]>\n" \
4848
"\tMatthew Green <[email protected]> & twojstaryzdomu <@github.com>.\n" \
4949
"\tReleased under the GNU GPL, version 2 or later (at your option).\n\n"
50+
51+
#define HINT "\nUse '-t' to include track # in output filename. " \
52+
"Remaining tracks were not processed\n"
5053

5154
#define CUELLEN 1024
5255
#define SECTLEN 2352
@@ -332,10 +335,15 @@ int writetrack(FILE *bf, struct track_t *track)
332335
int16_t i;
333336
float fl;
334337

335-
printf("%2d: %s ", track->num, track->output);
338+
if (!(f = fopen(track->output, "wbx"))) {
339+
if (errno == EEXIST)
340+
die_format(5, "%2d: skipped: output file %s already exists, aborting\n%s",
341+
track->num, track->output, HINT);
342+
else
343+
die_format(4, " Could not fopen track file: %s\n", strerror(errno));
344+
}
336345

337-
if (!(f = fopen(track->output, "wb")))
338-
die_format(4, " Could not fopen track file: %s\n", strerror(errno));
346+
printf("%2d: %s ", track->num, track->output);
339347

340348
if (fseek(bf, track->start, SEEK_SET))
341349
die_format(4, " Could not fseek to track location: %s\n", strerror(errno));
@@ -463,6 +471,9 @@ int set_output(struct track_t *track, char *binfile, char *basefile, int trackad
463471
die(4, "set_output(): asprintf() failed, out of memory\n");
464472
free(bname);
465473
bname = NULL;
474+
if (strcmp(track->output, track->file) == 0)
475+
die_format(5, "%2d: skipped: output file %s same as input file, aborting\n%s",
476+
track->num, track->output, HINT);
466477
return 1;
467478
}
468479

0 commit comments

Comments
 (0)