From b54ac7aca3fc10906ee7813bcec4b0548712c022 Mon Sep 17 00:00:00 2001 From: Andrei Horodniceanu Date: Sun, 17 Dec 2023 15:58:23 +0200 Subject: [PATCH] packagesuppliers/filesystem.d: Only look for versions of package_id When looking for versions of a package don't include any files that aren't versions of the queried package. If a directory contains the files botan-1.zip and botan-math-2.zip the current implementation would report both 1 and math-2 as candidates followed by an error that math-2 is not a valid version. Signed-off-by: Andrei Horodniceanu --- source/dub/packagesuppliers/filesystem.d | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/source/dub/packagesuppliers/filesystem.d b/source/dub/packagesuppliers/filesystem.d index fcb9efddf..8993caa1b 100644 --- a/source/dub/packagesuppliers/filesystem.d +++ b/source/dub/packagesuppliers/filesystem.d @@ -26,12 +26,16 @@ class FileSystemPackageSupplier : PackageSupplier { import std.algorithm.sorting : sort; import std.file : dirEntries, DirEntry, SpanMode; import std.conv : to; + import dub.semver : isValidVersion; Version[] ret; - foreach (DirEntry d; dirEntries(m_path.toNativeString(), package_id~"*", SpanMode.shallow)) { + foreach (DirEntry d; dirEntries(m_path.toNativeString(), package_id~"*.zip", SpanMode.shallow)) { NativePath p = NativePath(d.name); - logDebug("Entry: %s", p); - enforce(to!string(p.head)[$-4..$] == ".zip"); auto vers = p.head.name[package_id.length+1..$-4]; + if (!isValidVersion(vers)) { + logDebug("Ignoring entry '%s' because it isn't a version of package '%s'", p, package_id); + continue; + } + logDebug("Entry: %s", p); logDebug("Version: %s", vers); ret ~= Version(vers); }