Skip to content

Commit

Permalink
Use .NET 4.5's version of ZipArchive - references #729
Browse files Browse the repository at this point in the history
  • Loading branch information
forki committed Mar 28, 2015
1 parent 0b29ce4 commit da22c3f
Show file tree
Hide file tree
Showing 11 changed files with 54 additions and 59 deletions.
2 changes: 1 addition & 1 deletion build.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ Target "MergePaketTool" (fun _ ->
CreateDir buildMergedDir

let toPack =
["paket.exe"; "Paket.Core.dll"; "FSharp.Core.dll"; "Ionic.Zip.dll"; "Newtonsoft.Json.dll"; "UnionArgParser.dll"]
["paket.exe"; "Paket.Core.dll"; "FSharp.Core.dll"; "Newtonsoft.Json.dll"; "UnionArgParser.dll"]
|> List.map (fun l -> buildDir @@ l)
|> separated " "

Expand Down
1 change: 0 additions & 1 deletion paket.dependencies
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ nuget NUnit.Runners
nuget NUnit
nuget FAKE
nuget FSharp.Formatting
nuget DotNetZip
nuget FSharp.Core

github forki/FsUnit FsUnit.fs
Expand Down
1 change: 0 additions & 1 deletion paket.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
NUGET
remote: https://nuget.org/api/v2
specs:
DotNetZip (1.9.3)
FAKE (3.26.1)
FSharp.Compiler.Service (0.0.86)
FSharp.Core (3.1.2.1)
Expand Down
21 changes: 7 additions & 14 deletions src/Paket.Core/NuGetV2.fs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ open System
open System.IO
open System.Net
open Newtonsoft.Json
open Ionic.Zip
open System.IO.Compression
open System.Xml
open System.Text.RegularExpressions
open Paket.Logging
Expand Down Expand Up @@ -297,12 +297,11 @@ let getDetailsFromLocalFile localNugetPath package (version:SemVerInfo) =

if not nupkg.Exists then
failwithf "The package %s %s can't be found in %s.%sPlease check the feed definition in your paket.dependencies file." package (version.ToString()) localNugetPath Environment.NewLine
let zip = ZipFile.Read(nupkg.FullName)
let zippedNuspec = (zip |> Seq.find (fun f -> f.FileName.EndsWith ".nuspec"))
let zip = ZipFile.OpenRead(nupkg.FullName)
let zippedNuspec = zip.Entries |> Seq.find (fun f -> f.FullName.EndsWith ".nuspec")
let fileName = FileInfo(Path.Combine(Path.GetTempPath(), zippedNuspec.Name)).FullName

zippedNuspec.Extract(Path.GetTempPath(), ExtractExistingFileAction.OverwriteSilently)

let fileName = FileInfo(Path.Combine(Path.GetTempPath(), zippedNuspec.FileName)).FullName
zippedNuspec.ExtractToFile(fileName, true)

let nuspec = Nuspec.Load fileName

Expand Down Expand Up @@ -331,15 +330,8 @@ let ExtractPackage(fileName:string, targetFolder, name, version:SemVerInfo) =
if isExtracted fileName then
verbosefn "%s %A already extracted" name version
else
use zip = ZipFile.Read(fileName)
Directory.CreateDirectory(targetFolder) |> ignore
for e in zip do
try
e.Extract(targetFolder, ExtractExistingFileAction.OverwriteSilently)
with
| :? Ionic.Zip.BadCrcException as exn ->
traceWarnfn "Bad Crc during unzipping %s in %s %A: %s" e.FileName name version exn.Message
| exn -> failwithf "Error during unzipping %s in %s %A: %s" e.FileName name version exn.Message
ZipFile.ExtractToDirectory(fileName, targetFolder)

// cleanup folder structure
let rec cleanup (dir : DirectoryInfo) =
Expand All @@ -354,6 +346,7 @@ let ExtractPackage(fileName:string, targetFolder, name, version:SemVerInfo) =
let newName = file.Name.Replace("%2B", "+").Replace("%20", " ")
if file.Name <> newName && not (File.Exists <| Path.Combine(file.DirectoryName, newName)) then
File.Move(file.FullName, Path.Combine(file.DirectoryName, newName))

cleanup (DirectoryInfo targetFolder)
tracefn "%s %A unzipped to %s" name version targetFolder
return targetFolder
Expand Down
37 changes: 24 additions & 13 deletions src/Paket.Core/NupkgWriter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
open System
open System.IO
open System.Xml.Linq
open Ionic.Zip
open System.IO.Compression
open Paket
open System.Text
open System.Xml
Expand Down Expand Up @@ -178,20 +178,33 @@ let Write (core : CompleteCoreInfo) optional workingDir outputDir =
if File.Exists outputPath then
File.Delete outputPath

use zipFile = new ZipFile(outputPath)
use zipFile = ZipFile.Open(outputPath,ZipArchiveMode.Create)

let addEntry (zipFile : ZipFile) path writer =
let writeDel _ stream = writer stream
zipFile.AddEntry(path, WriteDelegate(writeDel)) |> ignore
let addEntry (zipFile : ZipArchive) path writerF =
let entry = zipFile.CreateEntry(path)
use stream = entry.Open()
writerF stream
stream.Close()

// adds all files in a directory to the zipFile
let rec addDir source target =
for file in Directory.EnumerateFiles(source,"*.*",SearchOption.TopDirectoryOnly) do
let fi = FileInfo file
zipFile.CreateEntryFromFile(fi.FullName,Path.Combine(target,fi.Name)) |> ignore

for dir in Directory.EnumerateDirectories(source,"*",SearchOption.TopDirectoryOnly) do
let di = DirectoryInfo dir
addDir di.FullName (Path.Combine(target,di.Name))

// add files
for fileName,targetFileName in optional.Files do
let targetFileName = targetFileName.Replace(" ", "%20")
let source = Path.Combine(workingDir, fileName)
if Directory.Exists source then
zipFile.AddDirectory(source, targetFileName.Replace(" ", "%20")) |> ignore
if Directory.Exists source then
addDir source targetFileName
else
if File.Exists source then
zipFile.AddFile(source, targetFileName.Replace(" ", "%20")) |> ignore
if File.Exists source then
zipFile.CreateEntryFromFile(source, targetFileName) |> ignore
else
failwithf "Could not find source file %s" source

Expand All @@ -201,10 +214,8 @@ let Write (core : CompleteCoreInfo) optional workingDir outputDir =

let fileList =
zipFile.Entries
|> Seq.filter (fun e -> not e.IsDirectory)
|> Seq.map (fun e -> e.FileName)
|> Seq.map (fun e -> e.FullName)

contentTypeDoc fileList
|> xDocWriter
|> addEntry zipFile contentTypePath
zipFile.Save()
|> addEntry zipFile contentTypePath
15 changes: 3 additions & 12 deletions src/Paket.Core/Paket.Core.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<OutputType>Library</OutputType>
<RootNamespace>Paket</RootNamespace>
<AssemblyName>Paket.Core</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<TargetFSharpCoreVersion>4.3.0.0</TargetFSharpCoreVersion>
<Name>Paket</Name>
<TargetFrameworkProfile />
Expand Down Expand Up @@ -131,22 +131,13 @@
<Reference Include="System.Core" />
<Reference Include="System.Data" />
<Reference Include="System.Data.Linq" />
<Reference Include="System.IO.Compression" />
<Reference Include="System.IO.Compression.FileSystem" />
<Reference Include="System.Numerics" />
<Reference Include="System.Security" />
<Reference Include="System.Xml" />
<Reference Include="System.Xml.Linq" />
</ItemGroup>
<Choose>
<When Condition="($(TargetFrameworkIdentifier) == '.NETFramework' And ($(TargetFrameworkVersion) == 'v2.0' Or $(TargetFrameworkVersion) == 'v3.0' Or $(TargetFrameworkVersion) == 'v3.5' Or $(TargetFrameworkVersion) == 'v4.0' Or $(TargetFrameworkVersion) == 'v4.5' Or $(TargetFrameworkVersion) == 'v4.5.1' Or $(TargetFrameworkVersion) == 'v4.5.2' Or $(TargetFrameworkVersion) == 'v4.5.3' Or $(TargetFrameworkVersion) == 'v4.6')) Or ($(TargetFrameworkIdentifier) == 'MonoAndroid') Or ($(TargetFrameworkIdentifier) == 'MonoTouch')">
<ItemGroup>
<Reference Include="Ionic.Zip">
<HintPath>..\..\packages\DotNetZip\lib\net20\Ionic.Zip.dll</HintPath>
<Private>True</Private>
<Paket>True</Paket>
</Reference>
</ItemGroup>
</When>
</Choose>
<Choose>
<When Condition="$(TargetFrameworkIdentifier) == '.NETFramework' And ($(TargetFrameworkVersion) == 'v4.0' Or $(TargetFrameworkVersion) == 'v4.5' Or $(TargetFrameworkVersion) == 'v4.5.1' Or $(TargetFrameworkVersion) == 'v4.5.2' Or $(TargetFrameworkVersion) == 'v4.5.3' Or $(TargetFrameworkVersion) == 'v4.6')">
<ItemGroup>
Expand Down
6 changes: 2 additions & 4 deletions src/Paket.Core/RemoteDownload.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
open Paket
open Newtonsoft.Json.Linq
open System.IO
open Ionic.Zip
open Paket.Logging
open Paket.ModuleResolver
open System.IO.Compression

// Gets the sha1 of a branch
let getSHA1OfBranch origin owner project branch =
Expand Down Expand Up @@ -57,10 +57,8 @@ let downloadDependenciesFile(rootPath,parserF,remoteFile:ModuleResolver.Resolved


let ExtractZip(fileName : string, targetFolder) =
let zip = ZipFile.Read(fileName)
Directory.CreateDirectory(targetFolder) |> ignore
for zipEntry in zip do
zipEntry.Extract(targetFolder, ExtractExistingFileAction.OverwriteSilently)
ZipFile.ExtractToDirectory(fileName,targetFolder)

let rec DirectoryCopy(sourceDirName, destDirName, copySubDirs) =
let dir = new DirectoryInfo(sourceDirName)
Expand Down
1 change: 0 additions & 1 deletion src/Paket.Core/paket.references
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
Newtonsoft.Json
DotNetZip
FSharp.Core
File:ErrorHandling.fs .
File:Globbing.fs .
23 changes: 13 additions & 10 deletions src/Paket/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -8,48 +8,51 @@
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Razor" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
<bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Net.Http.Extensions" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.2.28.0" newVersion="2.2.28.0" />
<bindingRedirect oldVersion="0.0.0.0-2.2.29.0" newVersion="2.2.29.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Net.Http.Primitives" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.2.28.0" newVersion="4.2.28.0" />
<bindingRedirect oldVersion="0.0.0.0-4.2.29.0" newVersion="4.2.29.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="nunit.framework" publicKeyToken="96d09a1eb7f44a77" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.6.3.13283" newVersion="2.6.3.13283" />
<bindingRedirect oldVersion="0.0.0.0-2.6.4.14350" newVersion="2.6.4.14350" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="RazorEngine" publicKeyToken="9ee697374c7e744a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-3.3.0.0" newVersion="3.3.0.0" />
<bindingRedirect oldVersion="0.0.0.0-3.5.3.0" newVersion="3.5.3.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.IO" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.6.9.0" newVersion="2.6.9.0" />
<bindingRedirect oldVersion="0.0.0.0-2.6.10.0" newVersion="2.6.10.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.6.9.0" newVersion="2.6.9.0" />
<bindingRedirect oldVersion="0.0.0.0-2.6.10.0" newVersion="2.6.10.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Threading.Tasks" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.6.9.0" newVersion="2.6.9.0" />
<bindingRedirect oldVersion="0.0.0.0-2.6.10.0" newVersion="2.6.10.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Net.Http.WebRequest" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.2.28.0" newVersion="2.2.28.0" />
<bindingRedirect oldVersion="0.0.0.0-2.2.29.0" newVersion="2.2.29.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.2.28.0" newVersion="2.2.28.0" />
<bindingRedirect oldVersion="0.0.0.0-2.2.29.0" newVersion="2.2.29.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
</configuration>
4 changes: 3 additions & 1 deletion src/Paket/Paket.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<OutputType>Exe</OutputType>
<RootNamespace>Paket</RootNamespace>
<AssemblyName>paket</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<TargetFSharpCoreVersion>4.3.0.0</TargetFSharpCoreVersion>
<Name>Paket</Name>
<TargetFrameworkProfile />
Expand Down Expand Up @@ -73,6 +73,8 @@
<Reference Include="System.Core" />
<Reference Include="System.Data" />
<Reference Include="System.Data.Linq" />
<Reference Include="System.IO.Compression" />
<Reference Include="System.IO.Compression.FileSystem" />
<Reference Include="System.Numerics" />
<Reference Include="System.Xml" />
</ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion tests/Paket.Tests/Paket.Tests.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<OutputType>Library</OutputType>
<RootNamespace>Paket.Tests</RootNamespace>
<AssemblyName>Paket.Tests</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<TargetFSharpCoreVersion>4.3.0.0</TargetFSharpCoreVersion>
<Name>Paket.Tests</Name>
<TargetFrameworkProfile />
Expand Down

0 comments on commit da22c3f

Please sign in to comment.