Skip to content

Commit

Permalink
Check if file exists before attempting to overwrite it
Browse files Browse the repository at this point in the history
  • Loading branch information
knutwannheden committed May 23, 2023
1 parent 4e38f5d commit 3aa3cfa
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions rewrite-java/src/main/java/org/openrewrite/java/JavaParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,7 @@
import java.lang.reflect.Method;
import java.net.URI;
import java.nio.charset.Charset;
import java.nio.file.FileAlreadyExistsException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.*;
import java.util.*;
import java.util.function.Function;
import java.util.regex.Matcher;
Expand Down Expand Up @@ -172,14 +169,14 @@ static List<Path> dependenciesFromResources(ExecutionContext ctx, String... arti
if (jarPattern.matcher(resource.getPath()).find()) {
try {
Path artifact = resourceTarget.toPath().resolve(Paths.get(resource.getPath()).getFileName());

Files.copy(
requireNonNull(caller.getResourceAsStream("/" + resource.getPath())),
artifact
);
if (!Files.exists(artifact)) {
Files.copy(
requireNonNull(caller.getResourceAsStream("/" + resource.getPath())),
artifact
);
}
missingArtifactNames.remove(artifactName);
artifacts.add(artifact);
} catch (FileAlreadyExistsException ignore) {
} catch (IOException e) {
throw new UncheckedIOException(e);
}
Expand Down

0 comments on commit 3aa3cfa

Please sign in to comment.