diff --git a/core/src/main/java/org/jboss/galleon/ProvisioningManager.java b/core/src/main/java/org/jboss/galleon/ProvisioningManager.java index 5f40236a5..bc6d45964 100644 --- a/core/src/main/java/org/jboss/galleon/ProvisioningManager.java +++ b/core/src/main/java/org/jboss/galleon/ProvisioningManager.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 Red Hat, Inc. and/or its affiliates + * Copyright 2016-2022 Red Hat, Inc. and/or its affiliates * and other contributors as indicated by the @author tags. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -704,7 +704,7 @@ private void doProvision(ProvisioningLayout layout, F } } try { - IoUtils.copy(stagedDir, home); + IoUtils.copy(stagedDir, home, true); } catch (IOException e) { throw new ProvisioningException(Errors.copyFile(stagedDir, home)); } diff --git a/core/src/main/java/org/jboss/galleon/util/IoUtils.java b/core/src/main/java/org/jboss/galleon/util/IoUtils.java index 904f3e7b2..6049fb32e 100644 --- a/core/src/main/java/org/jboss/galleon/util/IoUtils.java +++ b/core/src/main/java/org/jboss/galleon/util/IoUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 Red Hat, Inc. and/or its affiliates + * Copyright 2016-2022 Red Hat, Inc. and/or its affiliates * and other contributors as indicated by the @author tags. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,6 +20,7 @@ import java.io.IOException; import java.io.StringWriter; import java.nio.charset.StandardCharsets; +import java.nio.file.AccessDeniedException; import java.nio.file.FileAlreadyExistsException; import java.nio.file.FileVisitOption; import java.nio.file.FileVisitResult; @@ -147,6 +148,10 @@ public FileVisitResult postVisitDirectory(Path dir, IOException e) } public static void copy(Path source, Path target) throws IOException { + copy(source, target, false); + } + + public static void copy(Path source, Path target, boolean skipExistingFiles) throws IOException { if(Files.isDirectory(source)) { Files.createDirectories(target); } else { @@ -164,13 +169,24 @@ public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) if (!Files.isDirectory(targetDir)) { throw e; } + } catch (AccessDeniedException e) { + if (!skipExistingFiles || !Files.exists(targetDir)) { + throw e; + } } return FileVisitResult.CONTINUE; } @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { - Files.copy(file, target.resolve(source.relativize(file).toString()), StandardCopyOption.REPLACE_EXISTING); + final Path targetFile = target.resolve(source.relativize(file).toString()); + try { + Files.copy(file, targetFile, StandardCopyOption.REPLACE_EXISTING); + } catch (AccessDeniedException e) { + if (!skipExistingFiles || !Files.exists(targetFile)) { + throw e; + } + } return FileVisitResult.CONTINUE; } });