From 0e675c06d1a1caa24d7c5ef1b9e59570a472c7ca Mon Sep 17 00:00:00 2001 From: Jesse Glick Date: Mon, 23 Oct 2023 14:36:12 -0400 Subject: [PATCH] Ignore temporary files in `BindingStepTest.grep` --- .../credentialsbinding/impl/BindingStepTest.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/test/java/org/jenkinsci/plugins/credentialsbinding/impl/BindingStepTest.java b/src/test/java/org/jenkinsci/plugins/credentialsbinding/impl/BindingStepTest.java index 2aa3e6b6..810d4743 100644 --- a/src/test/java/org/jenkinsci/plugins/credentialsbinding/impl/BindingStepTest.java +++ b/src/test/java/org/jenkinsci/plugins/credentialsbinding/impl/BindingStepTest.java @@ -44,8 +44,10 @@ import hudson.slaves.WorkspaceList; import hudson.util.Secret; import java.io.File; +import java.io.FileNotFoundException; import java.io.IOException; import java.nio.charset.StandardCharsets; +import java.nio.file.NoSuchFileException; import java.util.Collections; import java.util.Set; import java.util.TreeSet; @@ -468,8 +470,14 @@ private static void grep(File dir, String text, String prefix, Set match String qualifiedName = prefix + kid.getName(); if (kid.isDirectory()) { grep(kid, text, qualifiedName + "/", matches); - } else if (kid.isFile() && FileUtils.readFileToString(kid, StandardCharsets.UTF_8).contains(text)) { - matches.add(qualifiedName); + } else { + try { + if (FileUtils.readFileToString(kid, StandardCharsets.UTF_8).contains(text)) { + matches.add(qualifiedName); + } + } catch (FileNotFoundException | NoSuchFileException x) { + // ignore, e.g. tmp file + } } } }