From da22c3f755d29e16cadaec8397f332f05b6d7784 Mon Sep 17 00:00:00 2001 From: Steffen Forkmann Date: Sat, 28 Mar 2015 09:25:47 +0100 Subject: [PATCH] Use .NET 4.5's version of ZipArchive - references #729 --- build.fsx | 2 +- paket.dependencies | 1 - paket.lock | 1 - src/Paket.Core/NuGetV2.fs | 21 ++++++---------- src/Paket.Core/NupkgWriter.fs | 37 ++++++++++++++++++---------- src/Paket.Core/Paket.Core.fsproj | 15 +++-------- src/Paket.Core/RemoteDownload.fs | 6 ++--- src/Paket.Core/paket.references | 1 - src/Paket/App.config | 23 +++++++++-------- src/Paket/Paket.fsproj | 4 ++- tests/Paket.Tests/Paket.Tests.fsproj | 2 +- 11 files changed, 54 insertions(+), 59 deletions(-) diff --git a/build.fsx b/build.fsx index 6baf978d5b..bf167476c4 100644 --- a/build.fsx +++ b/build.fsx @@ -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 " " diff --git a/paket.dependencies b/paket.dependencies index b52a45a001..cae3cb1db6 100644 --- a/paket.dependencies +++ b/paket.dependencies @@ -6,7 +6,6 @@ nuget NUnit.Runners nuget NUnit nuget FAKE nuget FSharp.Formatting -nuget DotNetZip nuget FSharp.Core github forki/FsUnit FsUnit.fs diff --git a/paket.lock b/paket.lock index 3df1eead88..e1e5bcab21 100644 --- a/paket.lock +++ b/paket.lock @@ -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) diff --git a/src/Paket.Core/NuGetV2.fs b/src/Paket.Core/NuGetV2.fs index 96033a2c8c..894fafd76f 100644 --- a/src/Paket.Core/NuGetV2.fs +++ b/src/Paket.Core/NuGetV2.fs @@ -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 @@ -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 @@ -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) = @@ -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 diff --git a/src/Paket.Core/NupkgWriter.fs b/src/Paket.Core/NupkgWriter.fs index 9822950dbd..1364674cbe 100644 --- a/src/Paket.Core/NupkgWriter.fs +++ b/src/Paket.Core/NupkgWriter.fs @@ -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 @@ -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 @@ -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 \ No newline at end of file diff --git a/src/Paket.Core/Paket.Core.fsproj b/src/Paket.Core/Paket.Core.fsproj index f75a7a0f51..456df0f030 100644 --- a/src/Paket.Core/Paket.Core.fsproj +++ b/src/Paket.Core/Paket.Core.fsproj @@ -9,7 +9,7 @@ Library Paket Paket.Core - v4.0 + v4.5 4.3.0.0 Paket @@ -131,22 +131,13 @@ + + - - - - - ..\..\packages\DotNetZip\lib\net20\Ionic.Zip.dll - True - True - - - - diff --git a/src/Paket.Core/RemoteDownload.fs b/src/Paket.Core/RemoteDownload.fs index c8c740d8f8..65e059c59e 100644 --- a/src/Paket.Core/RemoteDownload.fs +++ b/src/Paket.Core/RemoteDownload.fs @@ -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 = @@ -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) diff --git a/src/Paket.Core/paket.references b/src/Paket.Core/paket.references index e0d9f7a80c..feebd4da7e 100644 --- a/src/Paket.Core/paket.references +++ b/src/Paket.Core/paket.references @@ -1,5 +1,4 @@ Newtonsoft.Json -DotNetZip FSharp.Core File:ErrorHandling.fs . File:Globbing.fs . \ No newline at end of file diff --git a/src/Paket/App.config b/src/Paket/App.config index 960081db2d..87d9128bdc 100644 --- a/src/Paket/App.config +++ b/src/Paket/App.config @@ -8,19 +8,19 @@ - + - + - + - + @@ -28,28 +28,31 @@ - + - + - + - + - + - + + + + \ No newline at end of file diff --git a/src/Paket/Paket.fsproj b/src/Paket/Paket.fsproj index fca503c0bf..b1eada02e0 100644 --- a/src/Paket/Paket.fsproj +++ b/src/Paket/Paket.fsproj @@ -9,7 +9,7 @@ Exe Paket paket - v4.0 + v4.5 4.3.0.0 Paket @@ -73,6 +73,8 @@ + + diff --git a/tests/Paket.Tests/Paket.Tests.fsproj b/tests/Paket.Tests/Paket.Tests.fsproj index 7c65f5bdeb..ce5ddcdc91 100644 --- a/tests/Paket.Tests/Paket.Tests.fsproj +++ b/tests/Paket.Tests/Paket.Tests.fsproj @@ -9,7 +9,7 @@ Library Paket.Tests Paket.Tests - v4.0 + v4.5 4.3.0.0 Paket.Tests