Skip to content

Commit

Permalink
Fix handling of unreadable files that are now part of ZIP.
Browse files Browse the repository at this point in the history
  • Loading branch information
uhafner committed Feb 19, 2024
1 parent 4fb04ff commit cf2d7af
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -122,7 +122,7 @@ private Issue getIssueWithSource(final AnalysisResult result) {
private void deleteAffectedFilesInBuildFolder(final AnalysisResult result) {
Set<String> 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);
}
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit cf2d7af

Please sign in to comment.