Skip to content

Commit

Permalink
Use non-exist filename to generate file.
Browse files Browse the repository at this point in the history
Signed-off-by: Eric Wang <skygragon@gmail.com>
  • Loading branch information
skygragon committed Oct 15, 2016
1 parent 71d3ae2 commit 1e85050
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/commands/show.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,13 @@ cmd.handler = function(argv) {
'unknown language "' + argv.lang + '"');
problem.code = template.defaultCode;

// try to use a new filename to avoid overwrite by mistake
var filename = problem.key + h.langToExt(argv.lang);
var i = 0;
while (fs.existsSync(filename)) {
filename = problem.key + '.' + (i++) + h.langToExt(argv.lang);
}

core.exportProblem(problem, filename, !argv.extra);
msg = sprintf('(File: %s)', chalk.yellow.underline(filename));
}
Expand Down

0 comments on commit 1e85050

Please sign in to comment.