Skip to content

Fix unpacking on Windows #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 1, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 25 additions & 13 deletions src/Pglet/PgletClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.IO.Compression;
using System.Net;
using System.Text.RegularExpressions;
using System.Threading;
Expand Down Expand Up @@ -238,11 +239,6 @@ private static async Task<string> Install()
var pgletBinDir = Path.Combine(pgletHomeDir, "bin");
pgletExe = Path.Combine(pgletBinDir, pgletExe);

if (!Directory.Exists(pgletBinDir))
{
Directory.CreateDirectory(pgletBinDir);
}

var ver = PGLET_VERSION;
var fileName = $"pglet-{ver}-windows-amd64.zip";
if (RuntimeInfo.IsLinux)
Expand Down Expand Up @@ -274,6 +270,13 @@ private static async Task<string> Install()
var packagePath = Path.Combine(tempDir, fileName);
await (new WebClient()).DownloadFileTaskAsync(new Uri(pgletUri), packagePath);

if (Directory.Exists(pgletBinDir))
{
Directory.Delete(pgletBinDir, true);
}

Directory.CreateDirectory(pgletBinDir);

Unpack(packagePath, pgletBinDir);
File.Delete(packagePath);

Expand All @@ -289,18 +292,27 @@ private static async Task<string> Install()

private static void Unpack(string archivePath, string destDirectory)
{
using (Stream stream = File.OpenRead(archivePath))
using (var reader = ReaderFactory.Open(stream))
if (RuntimeInfo.IsWindows)
{
while (reader.MoveToNextEntry())
// unpack zip
ZipFile.ExtractToDirectory(archivePath, destDirectory);
}
else
{
// unpack tar
using (Stream stream = File.OpenRead(archivePath))
using (var reader = ReaderFactory.Open(stream))
{
if (!reader.Entry.IsDirectory)
while (reader.MoveToNextEntry())
{
reader.WriteEntryToDirectory(destDirectory, new ExtractionOptions()
if (!reader.Entry.IsDirectory)
{
ExtractFullPath = true,
Overwrite = true
});
reader.WriteEntryToDirectory(destDirectory, new ExtractionOptions()
{
ExtractFullPath = true,
Overwrite = true
});
}
}
}
}
Expand Down