Skip to content

Commit be926b1

Browse files
committed
remove symlinks
1 parent 47e89a0 commit be926b1

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/ElasticsearchBuildCompletePlugin.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,16 @@
3838
import java.io.FileNotFoundException;
3939
import java.io.IOException;
4040
import java.io.OutputStream;
41+
import java.io.UncheckedIOException;
42+
import java.nio.file.FileVisitResult;
4143
import java.nio.file.Files;
4244
import java.nio.file.Path;
45+
import java.nio.file.SimpleFileVisitor;
46+
import java.nio.file.attribute.BasicFileAttributes;
4347
import java.util.ArrayList;
4448
import java.util.Arrays;
4549
import java.util.List;
50+
import java.util.Objects;
4651
import java.util.Optional;
4752

4853
import javax.inject.Inject;
@@ -102,6 +107,23 @@ private File calculateTargetFile(Project target, String buildNumber) {
102107
}
103108

104109
private List<File> resolveProjectLogs(File projectDir) {
110+
// HACK: Some tests leave behind symlinks, and gradle throws an exception if it encounters symlinks.
111+
// Here we remove them before collecting logs to upload. We could instead build our own path matcher
112+
// but that seemed more complex than just deleting the irrelevant files.
113+
try {
114+
Files.walkFileTree(projectDir.toPath(), new SimpleFileVisitor<>() {
115+
@Override
116+
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
117+
if (Files.isSymbolicLink(file)) {
118+
Files.delete(file);
119+
}
120+
return FileVisitResult.CONTINUE;
121+
}
122+
});
123+
} catch (IOException e) {
124+
throw new UncheckedIOException(e);
125+
}
126+
105127
var projectDirFiles = getFileOperations().fileTree(projectDir);
106128
projectDirFiles.include("**/*.hprof");
107129
projectDirFiles.include("**/build/reports/configuration-cache/**");

0 commit comments

Comments
 (0)