fix LZMA archive directory structure (#88)

This commit is contained in:
Andrew Stanton-Nurse 2017-05-01 13:11:15 -07:00 committed by GitHub
parent 08ec9a7e49
commit 659c008ea8
3 changed files with 18 additions and 14 deletions

View File

@ -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;

View File

@ -29,9 +29,10 @@ namespace Microsoft.DotNet.Tools.Archive
var extract = app.Option("-x|--extract <outputDirectory>", "Directory to extract to", CommandOptionType.SingleValue);
var archiveFile = app.Option("-a|--archive <file>", "Archive to operate on", CommandOptionType.SingleValue);
var externals = app.Option("--external <external>...", "External files and directories to consider for extraction", CommandOptionType.MultipleValue);
var sources = app.Argument("<sources>...", "Files & directory to include in the archive", multipleValues:true);
var sources = app.Argument("<sources>...", "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);
}
}
}
}

View File

@ -6,7 +6,7 @@
<TargetFramework>netcoreapp2.0</TargetFramework>
<OutputType>Exe</OutputType>
<EnableApiCheck>false</EnableApiCheck>
<RuntimeIdentifier>win7-x64</RuntimeIdentifier>
<RuntimeIdentifiers>win7-x64;linux-x64</RuntimeIdentifiers>
</PropertyGroup>
<ItemGroup>