Skip to content

Commit

Permalink
feat: Add option to not modify readonly files during copy, add loggin…
Browse files Browse the repository at this point in the history
…g of time (#19894)

Allows to skip setting writable flag on copied files by providing the vaadin.frontend.disableWritableFlagCheckOnCopy system property.
This may improve performance in certain scenarios with Windows OS.

Fixes #19866
  • Loading branch information
TatuLund authored Sep 6, 2024
1 parent 4b91372 commit 18761fd
Showing 1 changed file with 16 additions and 6 deletions.
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

0 comments on commit 18761fd

Please sign in to comment.