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

fix crash when a package contains an invalid file (ie is packaged inc… #2644

Merged
merged 2 commits into from
Aug 21, 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
21 changes: 21 additions & 0 deletions src/Paket.Core/Common/Logging.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
open System
open System.IO
open System.Diagnostics
open System.Collections.Concurrent
open System.Threading

/// [omit]
let mutable verbose = false
Expand Down Expand Up @@ -49,6 +51,25 @@ let traceErrorfn fmt = Printf.ksprintf traceError fmt
/// [omit]
let traceWarnfn fmt = Printf.ksprintf traceWarn fmt

let private omittedWarnings = ref 0
let private warnings = ConcurrentDictionary<obj,Guid>()
let traceIfNotBefore tracer key fmt =
let printer =
if verbose then tracer
else
let g = Guid.NewGuid()
if g = warnings.GetOrAdd(key, fun _ -> g) then
tracer
else
Interlocked.Increment(omittedWarnings) |> ignore
ignore

Printf.ksprintf printer fmt

let getOmittedWarningCount () = omittedWarnings.Value

let traceWarnIfNotBefore key fmt = traceIfNotBefore traceWarn key fmt
let traceErrorIfNotBefore key fmt = traceIfNotBefore traceError key fmt

// Console Trace

Expand Down
4 changes: 4 additions & 0 deletions src/Paket.Core/Common/Logging.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ val traceErrorfn : Printf.StringFormat<'a,unit> -> 'a

val traceWarnfn : Printf.StringFormat<'a,unit> -> 'a

val traceWarnIfNotBefore : 'a -> Printf.StringFormat<'b,unit> -> 'b
val traceErrorIfNotBefore : 'a -> Printf.StringFormat<'b,unit> -> 'b

val getOmittedWarningCount : unit -> int

type Trace = {
Level: TraceLevel
Expand Down
2 changes: 2 additions & 0 deletions src/Paket.Core/Dependencies/NuGetCache.fs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ type NuGetRequestGetVersions =
type UnparsedPackageFile =
{ FullPath : string
PathWithinPackage : string }
member x.BasePath =
x.FullPath.Substring(0, x.FullPath.Length - (x.PathWithinPackage.Length + 1))

module NuGetConfig =
open System.Text
Expand Down
2 changes: 1 addition & 1 deletion src/Paket.Core/Dependencies/NuGetV2.fs
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ let private handleODataEntry nugetURL packageName version entry =
match PlatformMatching.extractPlatforms false restriction with
| Some p -> Some p
| None ->
Logging.traceWarnfn "Could not detect any platforms from '%s' in package %O %O" restriction packageName version
Logging.traceWarnIfNotBefore ("Package", restriction, packageName, version) "Could not detect any platforms from '%s' in package %O %O, please tell the package authors" restriction packageName version
None
else Some PlatformMatching.ParsedPlatformPath.Empty)
|> Option.map (fun pp -> name, version, pp)
Expand Down
2 changes: 1 addition & 1 deletion src/Paket.Core/Dependencies/NuGetV3.fs
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ let getPackageDetails (source:NugetV3Source) (packageName:PackageName) (version:
| x ->
let restrictions, problems = Requirements.parseRestrictionsLegacy false x
for problem in problems do
Logging.traceErrorfn "Could not detect any platforms from '%s' in %O %O" problem.Framework packageName version
Logging.traceErrorIfNotBefore ("Package", problem.Framework, packageName, version) "Could not detect any platforms from '%s' in %O %O, please tell the package authors" problem.Framework packageName version
restrictions
(PackageName dep.Id), (VersionRequirement.Parse dep.Range), targetFramework)
|> Seq.toList
Expand Down
4 changes: 2 additions & 2 deletions src/Paket.Core/Dependencies/Nuspec.fs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ module internal NuSpecParserHelper =
match PlatformMatching.extractPlatforms false framework with
| Some pp -> Some (name, version, pp)
| None ->
Logging.traceWarnfn "Could not detect any platforms from '%s' in '%s'" framework fileName
Logging.traceWarnIfNotBefore ("NuSpecFile", framework, fileName) "Could not detect any platforms from '%s' in '%s', please tell the package authors" framework fileName
None
| _ -> Some(name,version, PlatformMatching.ParsedPlatformPath.Empty)

Expand Down Expand Up @@ -84,7 +84,7 @@ type Nuspec =
match PlatformMatching.extractPlatforms false framework with
| Some p -> Some p
| None ->
Logging.traceWarnfn "Could not detect any platforms from '%s' in '%s'" framework fileName
Logging.traceWarnIfNotBefore ("NuSpecFile", framework, fileName) "Could not detect any platforms from '%s' in '%s', please tell the package authors" framework fileName
None
| _ -> Some PlatformMatching.ParsedPlatformPath.Empty)

Expand Down
2 changes: 1 addition & 1 deletion src/Paket.Core/PackageManagement/NugetConvert.fs
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ let createDependenciesFileR (rootDirectory : DirectoryInfo) nugetEnv mode =
|> List.map (fun fw ->
let restrictions, problems = Requirements.parseRestrictionsLegacy false fw
for problem in problems do
Logging.traceErrorfn "Could not detect any platforms from '%s' in %O %O" problem.Framework name version
Logging.traceErrorfn "Could not detect any platforms from '%s' in %O %O, please tell the package authors" problem.Framework name version
restrictions)
| _ -> []
let restrictions =
Expand Down
2 changes: 1 addition & 1 deletion src/Paket.Core/PaketConfigFiles/InstallModel.fs
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ module InstallModel =
(FolderScanner.choose "invalid tfm" (fun plats ->
let parsed = PlatformMatching.extractPlatforms false plats
if parsed.IsNone then
traceWarnfn "Could not detect any platforms from '%s' in '%s'" plats upf.FullPath
traceWarnIfNotBefore ("File", plats, upf.BasePath) "Could not detect any platforms from '%s' in '%s', please tell the package authors" plats upf.FullPath
parsed)) >> FolderScanner.ParseResult.box) }
{ FolderScanner.AdvancedScanner.Name = "rid";
FolderScanner.AdvancedScanner.Parser =
Expand Down
8 changes: 3 additions & 5 deletions src/Paket.Core/Versioning/PlatformMatching.fs
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,8 @@ let private extractPlatformsPriv = memoize (fun path ->
if platforms.Length = 0 then
if splits.Length = 1 && splits.[0].StartsWith "profile" then
// might be something like portable4.6-profile151
let found =
KnownTargetProfiles.FindPortableProfile splits.[0]
|> ParsedPlatformPath.FromTargetProfile
Some { found with Name = path }
KnownTargetProfiles.TryFindPortableProfile splits.[0]
|> Option.map (ParsedPlatformPath.FromTargetProfile >> fun p -> { p with Name = path })
else
None
else Some { Name = path; Platforms = platforms })
Expand All @@ -46,7 +44,7 @@ let extractPlatforms warn path =
match extractPlatformsPriv path with
| None ->
if warn then
traceWarnfn "Could not detect any platforms from '%s'" path
Logging.traceWarnIfNotBefore ("extractPlatforms", path) "Could not detect any platforms from '%s', please tell the package authors" path
None
| Some s -> Some s

Expand Down
4 changes: 2 additions & 2 deletions src/Paket/Paket.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
<StartAction>Project</StartAction>
<StartProgram>paket.exe</StartProgram>
<StartAction>Project</StartAction>
<StartArguments>restore</StartArguments>
<StartWorkingDirectory>C:\temp\perf\</StartWorkingDirectory>
<StartArguments>update</StartArguments>
<StartWorkingDirectory>C:\proj\testing\testpaketfailure\</StartWorkingDirectory>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<Optimize>true</Optimize>
Expand Down
3 changes: 3 additions & 0 deletions src/Paket/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ let processWithValidation silent validateF commandF (result : ParseResults<'T>)
)

tracefn " - Runtime: %s" (Utils.TimeSpanToReadableString realTime)
let omitted = Logging.getOmittedWarningCount()
if not verbose && omitted > 0 then
traceWarnfn "Paket omitted '%d' warnings similar to the ones above. You can see them in verbose mode" omitted

let processCommand silent commandF result =
processWithValidation silent (fun _ -> true) commandF result
Expand Down
5 changes: 5 additions & 0 deletions tests/Paket.Tests/Versioning/PlatformMatchingSpecs.fs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ let ``Can detect uap10``() =
let p = PlatformMatching.forceExtractPlatforms "uap10"
p.ToTargetProfile false |> shouldEqual (Some (SinglePlatform (FrameworkIdentifier.UAP UAPVersion.V10)))

[<Test>]
let ``Doesn't fail on profiles``() =
let p = PlatformMatching.extractPlatforms false "profiles"
p |> shouldEqual None

[<Test>]
let ``Can detect uap10.1``() =
let p = PlatformMatching.forceExtractPlatforms "UAP10.1"
Expand Down