From e5383ee30b60a7a567f5c73faf34ca2498ee8078 Mon Sep 17 00:00:00 2001 From: hneemann Date: Thu, 22 Apr 2021 09:13:28 +0200 Subject: [PATCH] file locator detects multiple file matches --- src/main/java/de/neemann/digital/FileLocator.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/main/java/de/neemann/digital/FileLocator.java b/src/main/java/de/neemann/digital/FileLocator.java index d1519c98a..ba190c457 100644 --- a/src/main/java/de/neemann/digital/FileLocator.java +++ b/src/main/java/de/neemann/digital/FileLocator.java @@ -78,7 +78,10 @@ public class FileLocator { * @return this for chained calls */ public FileLocator setLibraryRoot(File libraryRoot) { - this.libraryRoot = libraryRoot; + if (libraryRoot.isFile()) + this.libraryRoot = libraryRoot.getParentFile(); + else + this.libraryRoot = libraryRoot; return this; } @@ -156,9 +159,6 @@ public class FileLocator { } private int search(File path, ArrayList foundFiles, int fileCounter) throws IOException { - if (fileCounter < 0) - throw new IOException("to many files"); - File[] list = path.listFiles(); if (list != null) { for (File f : list) { @@ -168,6 +168,8 @@ public class FileLocator { throw new IOException("multiple matching files: " + foundFiles); } fileCounter--; + if (fileCounter < 0) + throw new IOException("to many files"); } for (File f : list) if (f.isDirectory() && !f.getName().startsWith("."))