From cf2d7af9ebbce9d18893b5c6400d37e59d7a5f77 Mon Sep 17 00:00:00 2001 From: Ulli Hafner Date: Mon, 19 Feb 2024 10:39:45 +0100 Subject: [PATCH] Fix handling of unreadable files that are now part of ZIP. --- .../plugins/analysis/core/util/AffectedFilesResolver.java | 8 +++++++- .../plugins/analysis/core/util/BuildFolderFacade.java | 4 ++-- .../warnings/steps/AffectedFilesResolverITest.java | 8 ++++---- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/plugin/src/main/java/io/jenkins/plugins/analysis/core/util/AffectedFilesResolver.java b/plugin/src/main/java/io/jenkins/plugins/analysis/core/util/AffectedFilesResolver.java index be2c91efa9..66b58e822e 100644 --- a/plugin/src/main/java/io/jenkins/plugins/analysis/core/util/AffectedFilesResolver.java +++ b/plugin/src/main/java/io/jenkins/plugins/analysis/core/util/AffectedFilesResolver.java @@ -250,7 +250,13 @@ boolean isInWorkspace(final String fileName) { } public void copy(final String from, final String to) throws IOException, InterruptedException { - createFile(from).zip(computeBuildFolderFileName(to)); + var file = createFile(from); + if (file.toVirtualFile().canRead()) { + file.zip(computeBuildFolderFileName(to)); + } + else { + throw new IOException("Can't read file: " + from); + } } public boolean existsInBuildFolder(final String fileName) { diff --git a/plugin/src/main/java/io/jenkins/plugins/analysis/core/util/BuildFolderFacade.java b/plugin/src/main/java/io/jenkins/plugins/analysis/core/util/BuildFolderFacade.java index 3a43f45250..25db9abb2f 100644 --- a/plugin/src/main/java/io/jenkins/plugins/analysis/core/util/BuildFolderFacade.java +++ b/plugin/src/main/java/io/jenkins/plugins/analysis/core/util/BuildFolderFacade.java @@ -15,8 +15,8 @@ import hudson.model.Run; /** - * Facade to files in the build folder of the Jenkins master. Encapsulates all calls to the running Jenkins server so - * that tests can replace this facade with a stub. + * Facade to the files in the build folder of the Jenkins controller. Encapsulates all calls to the running Jenkins + * server so that tests can replace this facade with a stub. * * @author Ullrich Hafner */ diff --git a/plugin/src/test/java/io/jenkins/plugins/analysis/warnings/steps/AffectedFilesResolverITest.java b/plugin/src/test/java/io/jenkins/plugins/analysis/warnings/steps/AffectedFilesResolverITest.java index 21e5419177..8bbf3aef79 100644 --- a/plugin/src/test/java/io/jenkins/plugins/analysis/warnings/steps/AffectedFilesResolverITest.java +++ b/plugin/src/test/java/io/jenkins/plugins/analysis/warnings/steps/AffectedFilesResolverITest.java @@ -108,8 +108,8 @@ void shouldShowNoLinkIfSourceCodeHasBeenMadeUnreadable() { } private void makeAffectedFilesInBuildFolderUnreadable(final AnalysisResult result) { - makeFileUnreadable(AffectedFilesResolver.getFile(result.getOwner(), - getIssueWithSource(result).getFileName() + ZIP)); + makeFileUnreadable(AffectedFilesResolver.getZipFile(result.getOwner(), + getIssueWithSource(result).getFileName())); } private Issue getIssueWithSource(final AnalysisResult result) { @@ -122,7 +122,7 @@ private Issue getIssueWithSource(final AnalysisResult result) { private void deleteAffectedFilesInBuildFolder(final AnalysisResult result) { Set files = result.getIssues().getFiles(); for (String fileName : files) { - Path file = AffectedFilesResolver.getFile(result.getOwner(), fileName + ZIP); + Path file = AffectedFilesResolver.getZipFile(result.getOwner(), fileName); try { Files.delete(file); } @@ -178,7 +178,7 @@ void shouldGetIoErrorBySearchingForAffectedFiles() { String consoleLog = getConsoleLog(result); assertThat(consoleLog).contains("0 copied"); - if (isWindows() && Runtime.version().feature() < 21) { // In Windows a file does not exist if it is unreadable + if (isWindows() && Runtime.version().feature() < 21) { // In Windows, a file does not exist if it is unreadable assertThat(consoleLog).contains("4 not-found", "0 with I/O error"); } else {