Skip to content

Commit

Permalink
Merge pull request #307 from spyrkob/GAL-335
Browse files Browse the repository at this point in the history
[GAL-335] Readonly files in server directory break update operation
  • Loading branch information
jfdenise authored Jun 29, 2022
2 parents 4632451 + b2dc011 commit f8c8fbb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
4 changes: 2 additions & 2 deletions core/src/main/java/org/jboss/galleon/ProvisioningManager.java
Original file line number Diff line number Diff line change
@@ -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");
Expand Down Expand Up @@ -704,7 +704,7 @@ private void doProvision(ProvisioningLayout<FeaturePackRuntimeBuilder> layout, F
}
}
try {
IoUtils.copy(stagedDir, home);
IoUtils.copy(stagedDir, home, true);
} catch (IOException e) {
throw new ProvisioningException(Errors.copyFile(stagedDir, home));
}
Expand Down
20 changes: 18 additions & 2 deletions core/src/main/java/org/jboss/galleon/util/IoUtils.java
Original file line number Diff line number Diff line change
@@ -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");
Expand All @@ -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;
Expand Down Expand Up @@ -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 {
Expand All @@ -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;
}
});
Expand Down

0 comments on commit f8c8fbb

Please sign in to comment.