Skip to content
This repository has been archived by the owner on Apr 13, 2023. It is now read-only.

Copy Ubuntu 18 binaries on exception #69

Merged
merged 2 commits into from
Dec 25, 2020
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ if ($LASTEXITCODE -ne 0) {
throw "Failed to publish application."
}

$targets = 'win-x64','linux-x64','osx-x64'
$targets = 'win-x64','linux-x64','osx-x64','ubuntu.18.04-x64'
foreach ($target in $targets) {
dotnet publish $proj -c Release --self-contained true -r $target --output "$publishOutputDir\$target"
if ($LASTEXITCODE -ne 0) {
Expand Down
7 changes: 5 additions & 2 deletions src/JournalCli/Cmdlets/CmdletBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@ namespace JournalCli.Cmdlets
public abstract class CmdletBase : PSCmdlet
{
private readonly ISystemProcess _systemProcess = SystemProcessFactory.Create();
private readonly Lazy<string> _assemblyName = new Lazy<string>(() => Assembly.GetExecutingAssembly().FullName);
private readonly Lazy<string> _assemblyName = new(() => Assembly.GetExecutingAssembly().FullName);

protected CmdletBase()
{
// ReSharper disable AssignNullToNotNullAttribute
LogsDirectory = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "logs");
ModuleDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
LogsDirectory = Path.Combine(ModuleDirectory, "logs");
var path = Path.Combine(LogsDirectory, ".log");
// ReSharper restore AssignNullToNotNullAttribute
Log.Logger = new LoggerConfiguration()
Expand All @@ -28,6 +29,8 @@ protected CmdletBase()

protected string LogsDirectory { get; }

protected string ModuleDirectory { get; }

protected string ResolvePath(string path) => GetUnresolvedProviderPathFromPSPath(path);

protected void ThrowTerminatingError(string message, ErrorCategory category)
Expand Down
57 changes: 32 additions & 25 deletions src/JournalCli/Cmdlets/JournalCmdletBase.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.IO;
using System.IO.Abstractions;
using System.Linq;
using System.Management.Automation;
Expand All @@ -17,6 +18,7 @@ public abstract class JournalCmdletBase : CmdletBase

#if !DEBUG
private static bool _beenWarned;
private static bool _binaryMoveAttempted;
private const string MissingGitBinaryWarning = "You're missing a native binary that's required to enable git integration. " +
"Click here for more information:\r\n\r\nhttps://journalcli.me/docs/faq#i-got-a-missing-git-binary-warning-whats-that-about\r\n";
#endif
Expand Down Expand Up @@ -87,40 +89,45 @@ private protected Journal OpenJournal()

protected void Commit(GitCommitType commitType)
{
#if !DEBUG
try
{
ValidateGitRepo();
var message = GitCommitMessage.Get(commitType);
CommitCore(message);
}
catch (TypeInitializationException e) when (e.InnerException is DllNotFoundException)
{
Log.Error(e, "Error encountered during Commit()");
if (!_beenWarned)
{
WriteWarning(MissingGitBinaryWarning);
_beenWarned = true;
}
}
#endif
var message = GitCommitMessage.Get(commitType);
Commit(message);
}

protected void Commit(string message)
{
#if !DEBUG
try
void TryMovingLinuxBinaries()
{
ValidateGitRepo();
CommitCore(message);
var binaries = Directory.GetFiles(Path.Combine(ModuleDirectory, "ubuntu.18.04-x64"));
foreach (var binary in binaries)
{
var destination = Path.Combine(ModuleDirectory, "linux-x64", Path.GetFileName(binary));
File.Copy(binary, destination, true);
}
}
catch (TypeInitializationException e) when (e.InnerException is DllNotFoundException)

while (!_beenWarned || !_binaryMoveAttempted)
{
Log.Error(e, "Error encountered during Commit()");
if (!_beenWarned)
try
{
ValidateGitRepo();
CommitCore(message);
}
catch (TypeInitializationException e) when (e.InnerException is DllNotFoundException)
{
WriteWarning(MissingGitBinaryWarning);
_beenWarned = true;
Log.Error(e, $"Error encountered while executing {nameof(Commit)} method");

if (_binaryMoveAttempted)
{
if (_beenWarned) continue;
WriteWarning(MissingGitBinaryWarning);
_beenWarned = true;
}
else
{
TryMovingLinuxBinaries();
_binaryMoveAttempted = true;
}
}
}
#endif
Expand Down