file locator detects multiple file matches

This commit is contained in:
hneemann 2021-04-22 09:13:28 +02:00
parent b60bf7d807
commit e5383ee30b

View File

@ -78,7 +78,10 @@ public class FileLocator {
* @return this for chained calls * @return this for chained calls
*/ */
public FileLocator setLibraryRoot(File libraryRoot) { public FileLocator setLibraryRoot(File libraryRoot) {
this.libraryRoot = libraryRoot; if (libraryRoot.isFile())
this.libraryRoot = libraryRoot.getParentFile();
else
this.libraryRoot = libraryRoot;
return this; return this;
} }
@ -156,9 +159,6 @@ public class FileLocator {
} }
private int search(File path, ArrayList<File> foundFiles, int fileCounter) throws IOException { private int search(File path, ArrayList<File> foundFiles, int fileCounter) throws IOException {
if (fileCounter < 0)
throw new IOException("to many files");
File[] list = path.listFiles(); File[] list = path.listFiles();
if (list != null) { if (list != null) {
for (File f : list) { for (File f : list) {
@ -168,6 +168,8 @@ public class FileLocator {
throw new IOException("multiple matching files: " + foundFiles); throw new IOException("multiple matching files: " + foundFiles);
} }
fileCounter--; fileCounter--;
if (fileCounter < 0)
throw new IOException("to many files");
} }
for (File f : list) for (File f : list)
if (f.isDirectory() && !f.getName().startsWith(".")) if (f.isDirectory() && !f.getName().startsWith("."))