-
Notifications
You must be signed in to change notification settings - Fork 100
Bugfix - Correctly match package names from local repos #1731
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
fd2e9f6
235665a
e2769c9
20b8cba
ce5d36a
d45bb92
d3b0609
9cdc095
98c6809
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -255,32 +255,48 @@ private FindResults FindNameHelper(string packageName, string[] tags, bool inclu | |
FindResults findResponse = new FindResults(); | ||
errRecord = null; | ||
|
||
WildcardPattern pkgNamePattern = new WildcardPattern($"{packageName}.*", WildcardOptions.IgnoreCase); | ||
NuGetVersion latestVersion = new NuGetVersion("0.0.0.0"); | ||
String latestVersionPath = String.Empty; | ||
string actualPkgName = packageName; | ||
|
||
// this regex pattern matches packageName followed by a version (4 digit or 3 with prerelease word) | ||
string regexPattern = $"{packageName}" + @".\d+\.\d+\.\d+(?:-\w+|.\d)*.nupkg"; | ||
Regex rx = new Regex(regexPattern, RegexOptions.Compiled | RegexOptions.IgnoreCase); | ||
_cmdletPassedIn.WriteDebug($"package file name pattern to be searched for is: {regexPattern}"); | ||
|
||
foreach (string path in Directory.GetFiles(Repository.Uri.LocalPath)) | ||
{ | ||
string packageFullName = Path.GetFileName(path); | ||
MatchCollection matches = rx.Matches(packageFullName); | ||
if (matches.Count == 0) | ||
{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It might be nice to add logging here saying no matches were found. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this condition just means that as we're iterating through the files, if a file's name doesn't match it'll be reflected as |
||
continue; | ||
} | ||
|
||
if (!String.IsNullOrEmpty(packageFullName) && pkgNamePattern.IsMatch(packageFullName)) | ||
Match match = matches[0]; | ||
|
||
GroupCollection groups = match.Groups; | ||
if (groups.Count == 0) | ||
{ | ||
NuGetVersion nugetVersion = GetInfoFromFileName(packageFullName: packageFullName, packageName: packageName, actualName: out actualPkgName, out errRecord); | ||
_cmdletPassedIn.WriteDebug($"Version parsed as '{nugetVersion}'"); | ||
continue; | ||
} | ||
|
||
if (errRecord != null) | ||
{ | ||
return findResponse; | ||
} | ||
Capture group = groups[0]; | ||
|
||
if ((!nugetVersion.IsPrerelease || includePrerelease) && (nugetVersion > latestVersion)) | ||
NuGetVersion nugetVersion = GetInfoFromFileName(packageFullName: packageFullName, packageName: packageName, actualName: out actualPkgName, out errRecord); | ||
_cmdletPassedIn.WriteDebug($"Version parsed as '{nugetVersion}'"); | ||
|
||
if (errRecord != null) | ||
{ | ||
return findResponse; | ||
} | ||
|
||
if ((!nugetVersion.IsPrerelease || includePrerelease) && (nugetVersion > latestVersion)) | ||
{ | ||
if (nugetVersion > latestVersion) | ||
{ | ||
if (nugetVersion > latestVersion) | ||
{ | ||
latestVersion = nugetVersion; | ||
latestVersionPath = path; | ||
} | ||
latestVersion = nugetVersion; | ||
latestVersionPath = path; | ||
} | ||
} | ||
} | ||
|
@@ -371,29 +387,46 @@ private FindResults FindVersionHelper(string packageName, string version, string | |
return findResponse; | ||
} | ||
|
||
WildcardPattern pkgNamePattern = new WildcardPattern($"{packageName}.*", WildcardOptions.IgnoreCase); | ||
// this regex pattern matches packageName followed by the requested version | ||
string regexPattern = $"{packageName}.{requiredVersion.ToNormalizedString()}" + @".nupkg"; | ||
Regex rx = new Regex(regexPattern, RegexOptions.Compiled | RegexOptions.IgnoreCase); | ||
_cmdletPassedIn.WriteDebug($"pattern is: {regexPattern}"); | ||
string pkgPath = String.Empty; | ||
string actualPkgName = String.Empty; | ||
|
||
foreach (string path in Directory.GetFiles(Repository.Uri.LocalPath)) | ||
{ | ||
string packageFullName = Path.GetFileName(path); | ||
if (!String.IsNullOrEmpty(packageFullName) && pkgNamePattern.IsMatch(packageFullName)) | ||
MatchCollection matches = rx.Matches(packageFullName); | ||
if (matches.Count == 0) | ||
{ | ||
NuGetVersion nugetVersion = GetInfoFromFileName(packageFullName: packageFullName, packageName: packageName, actualName: out actualPkgName, out errRecord); | ||
_cmdletPassedIn.WriteDebug($"'{packageName}' version parsed as '{nugetVersion}'"); | ||
continue; | ||
} | ||
|
||
if (errRecord != null) | ||
{ | ||
return findResponse; | ||
} | ||
Match match = matches[0]; | ||
|
||
if (nugetVersion == requiredVersion) | ||
{ | ||
_cmdletPassedIn.WriteDebug("Found matching version"); | ||
string pkgFullName = $"{actualPkgName}.{nugetVersion.ToString()}.nupkg"; | ||
pkgPath = Path.Combine(Repository.Uri.LocalPath, pkgFullName); | ||
break; | ||
} | ||
GroupCollection groups = match.Groups; | ||
if (groups.Count == 0) | ||
{ | ||
continue; | ||
} | ||
|
||
Capture group = groups[0]; | ||
|
||
NuGetVersion nugetVersion = GetInfoFromFileName(packageFullName: packageFullName, packageName: packageName, actualName: out actualPkgName, out errRecord); | ||
_cmdletPassedIn.WriteDebug($"Version parsed as '{nugetVersion}'"); | ||
|
||
if (errRecord != null) | ||
{ | ||
return findResponse; | ||
} | ||
|
||
if (nugetVersion == requiredVersion) | ||
{ | ||
_cmdletPassedIn.WriteDebug("Found matching version"); | ||
string pkgFullName = $"{actualPkgName}.{nugetVersion.ToString()}.nupkg"; | ||
pkgPath = Path.Combine(Repository.Uri.LocalPath, pkgFullName); | ||
break; | ||
} | ||
} | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.