From 659c008ea8f1310ed091dd327e9572736c39222a Mon Sep 17 00:00:00 2001 From: Andrew Stanton-Nurse Date: Mon, 1 May 2017 13:11:15 -0700 Subject: [PATCH] fix LZMA archive directory structure (#88) --- .../IndexedArchive.cs | 21 +++++++++++-------- src/dotnet-archive/Program.cs | 9 ++++---- src/dotnet-archive/dotnet-archive.csproj | 2 +- 3 files changed, 18 insertions(+), 14 deletions(-) diff --git a/src/Microsoft.DotNet.Archive/IndexedArchive.cs b/src/Microsoft.DotNet.Archive/IndexedArchive.cs index bb4c9bbd14..e94912ea5b 100644 --- a/src/Microsoft.DotNet.Archive/IndexedArchive.cs +++ b/src/Microsoft.DotNet.Archive/IndexedArchive.cs @@ -18,7 +18,8 @@ namespace Microsoft.DotNet.Archive { public DestinationFileInfo(string destinationPath, string hash) { - DestinationPath = destinationPath; + // Normalize the path + DestinationPath = destinationPath.Replace(Path.DirectorySeparatorChar, '/'); Hash = hash; } @@ -30,11 +31,13 @@ namespace Microsoft.DotNet.Archive { public ArchiveSource(string sourceArchive, string sourceFile, string archivePath, string hash, long size) { - SourceArchive = sourceArchive; - SourceFile = sourceFile; - ArchivePath = archivePath; Hash = hash; Size = size; + + // Normalize the paths + SourceArchive = sourceArchive?.Replace(Path.DirectorySeparatorChar, '/'); + SourceFile = sourceFile.Replace(Path.DirectorySeparatorChar, '/'); + ArchivePath = archivePath.Replace(Path.DirectorySeparatorChar, '/'); } public string SourceArchive { get; set; } @@ -85,7 +88,7 @@ namespace Microsoft.DotNet.Archive public IndexedArchive() { } - + private static Stream CreateTemporaryStream() { string temp = Path.GetTempPath(); @@ -246,7 +249,7 @@ namespace Microsoft.DotNet.Archive using (var archiveStream = File.Create(DestinationPath)) using (var archive = new ZipArchive(archiveStream, ZipArchiveMode.Create)) { - foreach(var zipSource in entries) + foreach (var zipSource in entries) { var entry = archive.CreateEntry(zipSource.Item1, CompressionLevel.Optimal); using (var entryStream = entry.Open()) @@ -400,9 +403,9 @@ namespace Microsoft.DotNet.Archive CheckDisposed(); using (var fs = File.OpenRead(externalFile)) { - string hash = GetHash(fs); + string hash = GetHash(fs); // $ prefix indicates that the file is not in the archive and path is relative to an external directory - _archiveFiles[hash] = new ArchiveSource(null, null, "$" + hash , hash, fs.Length); + _archiveFiles[hash] = new ArchiveSource(null, null, "$" + hash, hash, fs.Length); _externalFiles[hash] = externalFile; } } @@ -441,7 +444,7 @@ namespace Microsoft.DotNet.Archive using (var sourceArchive = new ZipArchive(File.OpenRead(sourceZipFile), ZipArchiveMode.Read)) { - foreach(var entry in sourceArchive.Entries) + foreach (var entry in sourceArchive.Entries) { string hash = null; long size = entry.Length; diff --git a/src/dotnet-archive/Program.cs b/src/dotnet-archive/Program.cs index 3376bf47ef..c73f5f41af 100644 --- a/src/dotnet-archive/Program.cs +++ b/src/dotnet-archive/Program.cs @@ -29,9 +29,10 @@ namespace Microsoft.DotNet.Tools.Archive var extract = app.Option("-x|--extract ", "Directory to extract to", CommandOptionType.SingleValue); var archiveFile = app.Option("-a|--archive ", "Archive to operate on", CommandOptionType.SingleValue); var externals = app.Option("--external ...", "External files and directories to consider for extraction", CommandOptionType.MultipleValue); - var sources = app.Argument("...", "Files & directory to include in the archive", multipleValues:true); + var sources = app.Argument("...", "Files & directory to include in the archive", multipleValues: true); - app.OnExecute(() => { + app.OnExecute(() => + { if (extract.HasValue() && sources.Values.Any()) { @@ -67,7 +68,7 @@ namespace Microsoft.DotNet.Tools.Archive if (sources.Values.Any()) { - foreach(var source in sources.Values) + foreach (var source in sources.Values) { if (Directory.Exists(source)) { @@ -91,6 +92,6 @@ namespace Microsoft.DotNet.Tools.Archive }); return app.Execute(args); - } + } } } diff --git a/src/dotnet-archive/dotnet-archive.csproj b/src/dotnet-archive/dotnet-archive.csproj index 5ea7e8fb45..3d41a55f58 100644 --- a/src/dotnet-archive/dotnet-archive.csproj +++ b/src/dotnet-archive/dotnet-archive.csproj @@ -6,7 +6,7 @@ netcoreapp2.0 Exe false - win7-x64 + win7-x64;linux-x64