Skip to content
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

try to fix https://github.com/fsprojects/Paket/issues/2640 #2721

Merged
merged 8 commits into from
Sep 5, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions global.json

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ let ``#1189 should allow # in path``() =
lockFile.Groups.[Constants.MainDependencyGroup].Resolution.[PackageName "FAKE"].Version
|> shouldBeGreaterThan (SemVer.Parse "4.7.2")


[<Test>]
let ``#1247 shouldn't load lockfile in full update``() =
updateEx true "i001247-lockfile-error" |> ignore
Expand All @@ -137,7 +138,10 @@ let ``#1450 should resolve with twiddle wakka``() =
let lockFile = update "i001450-twiddle-wakka"
lockFile.Groups.[Constants.MainDependencyGroup].Resolution.[PackageName "EnterpriseLibrary.SemanticLogging"].Version
|> shouldBeSmallerThan (SemVer.Parse "3")


[<Test>]
let ``#2640 shouldn't try GetDetails if package only exists locally``() =
updateEx true "i002640" |> ignore

#if INTERACTIVE
;;
Expand Down
Binary file not shown.
4 changes: 4 additions & 0 deletions integrationtests/scenarios/i002640/before/paket.dependencies
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
source my-package-source
source https://nuget.org/api/v2

nuget paket-issue-i002640-never-exists-on-nuget-gallery 1.0.0
20 changes: 14 additions & 6 deletions src/Paket.Core/Dependencies/NuGet.fs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ open System.Runtime.ExceptionServices
open System.Text
open FSharp.Polyfill
open Paket.NuGetCache
open Paket.PackageResolver

type NuGetContent =
| NuGetDirectory of name:string * contents:NuGetContent list
Expand Down Expand Up @@ -233,7 +234,10 @@ let tryNuGetV3 (auth, nugetV3Url, package:PackageName) =
NuGetV3.findVersionsForPackage(nugetV3Url, auth, package)


let rec private getPackageDetails alternativeProjectRoot root force (sources:PackageSource list) packageName (version:SemVerInfo) : Async<PackageResolver.PackageDetails> =
let rec private getPackageDetails alternativeProjectRoot root force (parameters:GetPackageDetailsParameters) : Async<PackageResolver.PackageDetails> =
let sources = parameters.Package.Sources
let packageName = parameters.Package.PackageName
let version = parameters.Version
async {
let inCache =
sources
Expand All @@ -245,10 +249,12 @@ let rec private getPackageDetails alternativeProjectRoot root force (sources:Pac
let tryV2 (nugetSource:NugetSource) force =
NuGetV2.getDetailsFromNuGet
force
parameters.VersionIsAssumed
nugetSource
packageName
version


let tryV3 (nugetSource:NugetV3Source) force =
NuGetV3.GetPackageDetails force nugetSource packageName version

Expand Down Expand Up @@ -357,17 +363,17 @@ let rec private getPackageDetails alternativeProjectRoot root force (sources:Pac
LicenseUrl = nugetObject.LicenseUrl
DirectDependencies = NuGetPackageCache.getDependencies nugetObject |> Set.ofList } }

let rec GetPackageDetails alternativeProjectRoot root force (sources:PackageSource list) groupName packageName (version:SemVerInfo) : Async<PackageResolver.PackageDetails> =
let rec GetPackageDetails alternativeProjectRoot root force (parameters:GetPackageDetailsParameters): Async<PackageResolver.PackageDetails> =
async {
try
return! getPackageDetails alternativeProjectRoot root force sources packageName version
return! getPackageDetails alternativeProjectRoot root force parameters
with
| exn ->
if verbose then
traceWarnfn "GetPackageDetails failed: %O" exn
else
traceWarnfn "Something failed in GetPackageDetails, trying again with force: %s" exn.Message
return! getPackageDetails alternativeProjectRoot root true sources packageName version
return! getPackageDetails alternativeProjectRoot root true parameters
}

let protocolCache = System.Collections.Concurrent.ConcurrentDictionary<_,_>()
Expand Down Expand Up @@ -413,7 +419,9 @@ let getVersionsCached key f (source, auth, nugetURL, package) =


/// Allows to retrieve all version no. for a package from the given sources.
let GetVersions force alternativeProjectRoot root (sources, packageName:PackageName) = async {
let GetVersions force alternativeProjectRoot root (parameters:GetPackageVersionsParameters) = async {
let packageName = parameters.Package.PackageName
let sources = parameters.Package.Sources
let trial force = async {
let getVersionsFailedCacheFileName (source:PackageSource) =
let h = source.Url |> NuGetCache.normalizeUrl |> hash |> abs
Expand Down Expand Up @@ -671,7 +679,7 @@ let DownloadAndExtractPackage(alternativeProjectRoot, root, isLocalOverride:bool
let group = if groupName = Constants.MainDependencyGroup then "" else sprintf " (%O)" groupName
tracefn "Downloading %O %O%s" packageName version group

let! nugetPackage = GetPackageDetails alternativeProjectRoot root force [source] groupName packageName version
let! nugetPackage = GetPackageDetails alternativeProjectRoot root force (GetPackageDetailsParameters.ofParams [source] groupName packageName version)

let encodeURL (url:string) = url.Replace("+","%2B")
let downloadUri =
Expand Down
11 changes: 9 additions & 2 deletions src/Paket.Core/Dependencies/NuGetCache.fs
Original file line number Diff line number Diff line change
Expand Up @@ -465,12 +465,19 @@ let private tryUrlOrBlacklist (f: _ -> Async<'a>) (isOk : 'a -> bool) (source:Nu
| FirstCall t ->
FirstCall (t |> Task.Map (fun (l, r) -> l, (r :?> 'a)))

let tryAndBlacklistUrl doWarn (source:NugetSource) (tryAgain : 'a -> bool) (f : string -> Async<'a>) (urls: UrlToTry list) : Async<'a>=
let tryAndBlacklistUrl doBlackList doWarn (source:NugetSource) (tryAgain : 'a -> bool) (f : string -> Async<'a>) (urls: UrlToTry list) : Async<'a>=
async {
let! tasks, resultIndex =
urls
|> Seq.map (fun url -> async {
let cached = tryUrlOrBlacklist (fun () -> async { return! f url.InstanceUrl }) (tryAgain >> not) (source, url.UrlId)
let cached =
if doBlackList then
tryUrlOrBlacklist (fun () -> async { return! f url.InstanceUrl }) (tryAgain >> not) (source, url.UrlId)
else
async {
let! result = f url.InstanceUrl
return (tryAgain result |> not, result)
} |> Async.StartAsTask |> FirstCall
match cached with
| SubsequentCall task ->
let! result = task |> Async.AwaitTask
Expand Down
13 changes: 7 additions & 6 deletions src/Paket.Core/Dependencies/NuGetV2.fs
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,8 @@ let parseODataEntryDetails (url,nugetURL,packageName:PackageName,version:SemVerI
| ODataSearchResult.Match entry -> entry


let getDetailsFromNuGetViaODataFast nugetSource (packageName:PackageName) (version:SemVerInfo) =
let getDetailsFromNuGetViaODataFast isVersionAssumed nugetSource (packageName:PackageName) (version:SemVerInfo) =
let doBlacklist = not isVersionAssumed
async {
let normalizedVersion = version.Normalize()
let urls =
Expand Down Expand Up @@ -369,24 +370,24 @@ let getDetailsFromNuGetViaODataFast nugetSource (packageName:PackageName) (versi
| Choice1Of2 _ -> false
| _ -> true

let! result = NuGetCache.tryAndBlacklistUrl true nugetSource tryAgain handleUrl urls
let! result = NuGetCache.tryAndBlacklistUrl doBlacklist true nugetSource tryAgain handleUrl urls
match result with
| Choice1Of2 res -> return res
| Choice2Of2 ex -> return raise (exn("error", ex))
}


/// Gets package details from NuGet via OData
let getDetailsFromNuGetViaOData nugetSource (packageName:PackageName) (version:SemVerInfo) =
getDetailsFromNuGetViaODataFast nugetSource packageName version
let getDetailsFromNuGetViaOData isVersionAssumed nugetSource (packageName:PackageName) (version:SemVerInfo) =
getDetailsFromNuGetViaODataFast isVersionAssumed nugetSource packageName version

let getDetailsFromNuGet force nugetSource packageName version =
let getDetailsFromNuGet force isVersionAssumed nugetSource packageName version =
getDetailsFromCacheOr
force
nugetSource.Url
packageName
version
(fun () -> getDetailsFromNuGetViaOData nugetSource packageName version)
(fun () -> getDetailsFromNuGetViaOData isVersionAssumed nugetSource packageName version)

/// Uses the NuGet v2 API to retrieve all packages with the given prefix.
let FindPackages(auth, nugetURL, packageNamePrefix, maxResults) =
Expand Down
Loading