Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add option to not modify readonly files during copy, add logging of time #19894

Merged
merged 7 commits into from
Sep 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import java.util.stream.Stream;

import org.apache.commons.io.FileUtils;
import org.apache.commons.io.filefilter.FileFilterUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -55,6 +54,11 @@ public class TaskCopyLocalFrontendFiles
this.options = options;
}

private static boolean shouldApplyWriteableFlag() {
return !Boolean.parseBoolean(System.getProperty(
"vaadin.frontend.disableWritableFlagCheckOnCopy", "false"));
}

@Override
public void execute() {
File target = options.getJarFrontendResourcesFolder();
Expand Down Expand Up @@ -96,16 +100,22 @@ static Set<String> copyLocalResources(File source, File target,
return Collections.emptySet();
}
try {
long start = System.nanoTime();
Set<String> handledFiles = new HashSet<>(TaskCopyFrontendFiles
.getFilesInDirectory(source, relativePathExclusions));
FileUtils.copyDirectory(source, target,
withoutExclusions(source, relativePathExclusions));
try (Stream<Path> fileStream = Files
.walk(Paths.get(target.getPath()))) {
// used with try-with-resources as defined in walk API note
fileStream.filter(file -> !Files.isWritable(file)).forEach(
filePath -> filePath.toFile().setWritable(true));
if (shouldApplyWriteableFlag()) {
try (Stream<Path> fileStream = Files
.walk(Paths.get(target.getPath()))) {
// used with try-with-resources as defined in walk API note
fileStream.filter(file -> !Files.isWritable(file)).forEach(
filePath -> filePath.toFile().setWritable(true));
}
}
long ms = (System.nanoTime() - start) / 1000000;
log().info("Copied {} local frontend files. Took {} ms.",
handledFiles.size(), ms);
return handledFiles;
} catch (IOException e) {
throw new UncheckedIOException(String.format(
Expand Down
Loading