Skip to content

Commit

Permalink
Try to report better error when file is blocked by Firewall
Browse files Browse the repository at this point in the history
  • Loading branch information
forki committed Oct 20, 2015
1 parent 46a1631 commit 73ade42
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/Paket.Core/NuGetV2.fs
Expand Up @@ -393,8 +393,19 @@ let ExtractPackage(fileName:string, targetFolder, packageName:PackageName, versi
else
Directory.CreateDirectory(targetFolder) |> ignore

fixArchive fileName
ZipFile.ExtractToDirectory(fileName, targetFolder)
try
fixArchive fileName
ZipFile.ExtractToDirectory(fileName, targetFolder)
with
| exn ->
let text = ref ""
try
text := File.ReadAllText(fileName)
with
| _ -> ()

let text = if !text = "" then "" else sprintf " Package contains text: %s%s" !text Environment.NewLine
failwithf "Error during extraction of %s.%s%s Message: %s" (Path.GetFullPath fileName) Environment.NewLine text exn.Message

// cleanup folder structure
let rec cleanup (dir : DirectoryInfo) =
Expand Down
26 changes: 26 additions & 0 deletions tests/Paket.Tests/ExtractPackageSpecs.fs
@@ -0,0 +1,26 @@
module Paket.ExtractPackageSpecs

open System.IO
open Paket
open NUnit.Framework
open FsUnit
open System
open System.Net
open Domain

[<Test>]
let ``should report blocked download``() =
let di = Path.Combine(Path.GetTempPath(),"PaketTests/Extract")
if Directory.Exists di then
Directory.Delete(di,true)
Directory.CreateDirectory(di) |> ignore
let fileName = Path.Combine(di,"FSharp.Data.nupkg")
File.Copy("Nuspec/FSharp.Data.nuspec",fileName)

try
NuGetV2.ExtractPackage(fileName,di,PackageName "FSharp.Data",SemVer.Parse("0.1.1"))
|> Async.RunSynchronously

with
| exn -> exn.Message
|> fun error -> error.Contains("Package contains text:") |> shouldEqual true
1 change: 1 addition & 0 deletions tests/Paket.Tests/Paket.Tests.fsproj
Expand Up @@ -87,6 +87,7 @@
<Compile Include="NugetVersionRangeSerializerSpecs.fs" />
<Compile Include="DependencySetSpecs.fs" />
<Compile Include="BindingRedirect.fs" />
<Compile Include="ExtractPackageSpecs.fs" />
<Compile Include="UtilsSpecs.fs" />
<Compile Include="TemplateFileParsing.fs" />
<Compile Include="NuspecWriterSpecs.fs" />
Expand Down

0 comments on commit 73ade42

Please sign in to comment.