-
-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #67 from Deadpikle/feature/tar-zip-handling
Use .NET built-in Tar and Zip handling
- Loading branch information
Showing
4 changed files
with
172 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
using System.Formats.Tar; | ||
using System.IO; | ||
using System.IO.Compression; | ||
|
||
namespace DotNetReleaser.Helpers; | ||
|
||
internal static class CompressionHelper | ||
{ | ||
public static string? MakeTarGz(ProjectPackageInfo projectPackageInfo, string publishDir, string artifactsFolder, string rid) | ||
{ | ||
string? outputPath = null; | ||
var publishPath = Path.Combine(Path.GetDirectoryName(projectPackageInfo.ProjectFullPath) ?? "", publishDir); | ||
if (Directory.Exists(publishPath)) | ||
{ | ||
var gzipPath = Path.GetFullPath(Path.Combine(artifactsFolder, | ||
projectPackageInfo.Name + "." + projectPackageInfo.Version + "." + rid + ".tar.gz")); | ||
if (File.Exists(gzipPath)) | ||
{ | ||
return null; // file already exists | ||
} | ||
using FileStream fs = new(gzipPath, FileMode.CreateNew, FileAccess.Write); | ||
using GZipStream gz = new(fs, CompressionMode.Compress, leaveOpen: true); | ||
{ | ||
TarFile.CreateFromDirectory(publishPath, gz, includeBaseDirectory: false); | ||
} | ||
outputPath = gzipPath; | ||
} | ||
return outputPath; | ||
} | ||
|
||
public static string? MakeZip(ProjectPackageInfo projectPackageInfo, string publishDir, string artifactsFolder, string rid) | ||
{ | ||
string? outputPath = null; | ||
var publishPath = Path.Combine(Path.GetDirectoryName(projectPackageInfo.ProjectFullPath) ?? "", publishDir); | ||
if (Directory.Exists(publishPath)) | ||
{ | ||
var zipPath = Path.GetFullPath(Path.Combine(artifactsFolder, | ||
projectPackageInfo.Name + "." + projectPackageInfo.Version + "." + rid + ".zip")); | ||
if (File.Exists(zipPath)) | ||
{ | ||
return null; // file already exists | ||
} | ||
using FileStream fs = new(zipPath, FileMode.CreateNew, FileAccess.Write); | ||
{ | ||
ZipFile.CreateFromDirectory(publishPath, fs, compressionLevel: CompressionLevel.Optimal, includeBaseDirectory: false); | ||
} | ||
outputPath = zipPath; | ||
} | ||
return outputPath; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters