Skip to content

Commit

Permalink
Just skip if we have issues initializing backup repo
Browse files Browse the repository at this point in the history
closes #469
  • Loading branch information
Noggog committed Nov 22, 2024
1 parent 67bbf95 commit 3d82586
Showing 1 changed file with 42 additions and 6 deletions.
48 changes: 42 additions & 6 deletions Synthesis.Bethesda.GUI/Settings/BackupSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,55 @@ public BackupSettings(

public void Start()
{
_initRepository.Init(RepoDirectory);
CreateGitIgnore();
using var repo = _repositoryCheckouts.Get(RepoDirectory);
StageIfExists(GitIgnorePath, repo.Repository);
StageIfExists(PipelineSettings, repo.Repository);
StageIfExists(GuiSettings, repo.Repository);
try
{
_initRepository.Init(RepoDirectory);
}
catch (LibGit2SharpException e)
{
_logger.Warning(e, "Could not initiate backup repository.");
return;
}
try
{
CreateGitIgnore();
using var repo = _repositoryCheckouts.Get(RepoDirectory);
StageIfExists(GitIgnorePath, repo.Repository);
StageIfExists(PipelineSettings, repo.Repository);
StageIfExists(GuiSettings, repo.Repository);
repo.Repository.Commit("Settings changed");
}
catch (EmptyCommitException)
{
}
catch (Exception ex)
{
HandleException(ex);
}
}

private void HandleException(Exception? ex)
{
switch (ex)
{
case LibGit2SharpException:
case NullReferenceException:
WipeBackup(ex);
break;
case AggregateException agg:
HandleException(agg.InnerException);
break;
case null:
return;
default:
throw ex;
}
}

private void WipeBackup(Exception ex)
{
_logger.Warning(ex, "Wiping backup settings.");
_fileSystem.Directory.DeleteEntireFolder(RepoDirectory);
}

private void CreateGitIgnore()
Expand Down

0 comments on commit 3d82586

Please sign in to comment.