Skip to content

Commit c424a24

Browse files
committed
work with output file
1 parent 3f283fd commit c424a24

File tree

2 files changed

+10
-18
lines changed

2 files changed

+10
-18
lines changed

framework/codemodder-base/src/main/java/io/codemodder/CLI.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -281,16 +281,19 @@ public Integer call() throws IOException {
281281

282282
Path outputPath = null;
283283
if (output != null) {
284-
outputPath = output.toPath();
284+
outputPath = output.getAbsoluteFile().toPath();
285+
if(!Files.exists(outputPath)) {
286+
Files.createFile(outputPath);
287+
}
285288

286-
// check if the output file parent directory doesn't exist
287-
if (!Files.exists(outputPath.getParent())) {
288-
// create it
289-
Files.createDirectories(outputPath.getParent());
289+
// check if the output file parent directory doesn't exist or isn't writable
290+
if (!Files.exists(outputPath.getParent()) || !Files.isWritable(outputPath.getParent())) {
291+
log.error("The output file parent directory doesn't exist");
292+
return ERROR_CANT_WRITE_OUTPUT_FILE;
290293
}
291294

292-
if (!Files.isWritable(outputPath) && !Files.isWritable(outputPath.getParent())) {
293-
log.error("The output file (or its parent directory) is not writable");
295+
if (!Files.isWritable(outputPath)) {
296+
log.error("The output file is not writable");
294297
return ERROR_CANT_WRITE_OUTPUT_FILE;
295298
}
296299
}

framework/codemodder-base/src/test/java/io/codemodder/CLITest.java

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -124,17 +124,6 @@ private static void writeLogMessageToFile(final Path outputFile, final String pr
124124
log.info("this is a test");
125125
}
126126

127-
@Test
128-
void output_file_parent_dirs_created() throws IOException {
129-
Path normalCodetf = Files.createTempDirectory("exists");
130-
Path outputFile = normalCodetf.resolve("doesnt/exist/codetf.json");
131-
String[] args =
132-
new String[] {"--dont-exit", "--output", outputFile.toString(), workingRepoDir.toString()};
133-
Runner.run(List.of(Cloud9Changer.class), args);
134-
assertThat(Files.readString(fooJavaFile)).contains("cloud9");
135-
assertThat(Files.exists(outputFile)).isTrue();
136-
}
137-
138127
@Test
139128
void dry_run_works() throws IOException {
140129
Path normalCodetf = Files.createTempFile("normal", ".codetf");

0 commit comments

Comments
 (0)