Skip to content
Permalink
Browse files
Fix regression in Util#listFiles() in config restoration.
I was able to test it after the [JENKINS-44997](https://issues.jenkins-ci.org/browse/JENKINS-44997) fix

File#listFiles() returns empty list when the file does not exist.
But in my case I was getting Error due to the isDirectory() check

#10
  • Loading branch information
oleg-nenashev committed Jun 21, 2017
1 parent 17c9607 commit 22ae79ae8fe8b372805ad55b8359a637257efa14
Showing with 8 additions and 2 deletions.
  1. +8 −2 src/main/java/org/jenkinsci/plugins/periodicbackup/Util.java
@@ -167,14 +167,20 @@ public static File[] listFiles(@Nonnull File directory) throws PeriodicBackupExc

/**
* Secure version of the listFiles() logic
* @param directory Directory to be listed
* @param directory Directory to be listed
* @param fileFilter Optional file filter
* @return Files in the directory
* @return Files in the directory.
* If the directory does not exist, an empty list will be returned
* @throws PeriodicBackupException Whatever error
*/
@Nonnull
@Restricted(NoExternalUse.class)
public static File[] listFiles(@Nonnull File directory, @CheckForNull FileFilter fileFilter) throws PeriodicBackupException {
if (!directory.exists()) {
// Not our business to check if the directory exists
return new File[0];
}

if (!directory.isDirectory()) {
throw new PeriodicBackupException(formatMessage(directory, "File is not a directory"));
}

0 comments on commit 22ae79a

Please sign in to comment.