Skip to content

Commit

Permalink
Handle archives not packable due to oversized files
Browse files Browse the repository at this point in the history
  • Loading branch information
jtellnes committed Feb 1, 2018
1 parent 9ef50bd commit 9db9d6a
Show file tree
Hide file tree
Showing 7 changed files with 93 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/Arkivverket.Arkade.UI/Resources/MetaDataUI.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/Arkivverket.Arkade.UI/Resources/MetaDataUI.resx
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ Noark 3, Noark 4, Noark 5, Fagsystem</comment>
<value>Error: Could not create/overwrite package.</value>
</data>
<data name="PackageCreationErrorStatusMessage" xml:space="preserve">
<value>Klarte ikke opprette/overskrive pakke. Sjekk om pakkedestinasjonen er opptatt.</value>
<value>Klarte ikke opprette/overskrive pakke.</value>
</data>
<data name="Producer" xml:space="preserve">
<value>Produsent</value>
Expand Down
31 changes: 29 additions & 2 deletions src/Arkivverket.Arkade.UI/Resources/UI.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 11 additions & 2 deletions src/Arkivverket.Arkade.UI/Resources/UI.resx
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,7 @@
</data>
<data name="TestrunnerArchiveNotTestable" xml:space="preserve">
<value>Arkivuttrekket kan ikke testes: Det ble ikke funnet en gyldig spesifikasjonsfil for uttrekket.
(Se logg for detaljer {0}).
Du kan fortsatt lage en pakke av uttrekket.</value>
(Se logg for detaljer {0}).</value>
</data>
<data name="TestrunnerFinishedOperationMessage" xml:space="preserve">
<value>Testingen er fullført</value>
Expand Down Expand Up @@ -286,4 +285,14 @@ Du kan fortsatt lage en pakke av uttrekket.</value>
<data name="UnsavedTestResultsOnExitWarning" xml:space="preserve">
<value>Hvis du avslutter nå vil resultater fra testkjøringen gå tapt. Ønsker du likevel å avslutte?</value>
</data>
<data name="TestrunnerArchiveNotPackable" xml:space="preserve">
<value>Det kan ikke lages en pakke av uttrekket: Uttrekket inneholder for store enkeltfiler.
(Se logg for detaljer {0}).</value>
</data>
<data name="TestrunnerArchivePackability" xml:space="preserve">
<value>Pakkbarhet</value>
</data>
<data name="TestrunnerArchiveTestability" xml:space="preserve">
<value>Testbarhet</value>
</data>
</root>
15 changes: 13 additions & 2 deletions src/Arkivverket.Arkade.UI/ViewModels/TestRunnerViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ private bool CanStartTestRun()

private bool CanCreatePackage()
{
return !_isRunningTests;
return _testSession != null && _testSession.IsPackableArchive() && !_isRunningTests;
}

private bool IsFinishedRunningTests()
Expand All @@ -211,13 +211,24 @@ public void OnNavigatedTo(NavigationContext context)
if (!_testSession.IsTestableArchive())
{
_statusEventHandler.RaiseEventOperationMessage(
null,
Resources.UI.TestrunnerArchiveTestability,
string.Format(Resources.UI.TestrunnerArchiveNotTestable, ArkadeProcessingArea.LogsDirectory),
OperationMessageStatus.Warning
);
}

StartTestingCommand.RaiseCanExecuteChanged(); // testSession has been updated, reevaluate command

if (!_testSession.IsPackableArchive())
{
_statusEventHandler.RaiseEventOperationMessage(
Resources.UI.TestrunnerArchivePackability,
string.Format(Resources.UI.TestrunnerArchiveNotPackable, ArkadeProcessingArea.LogsDirectory),
OperationMessageStatus.Warning
);
}

NavigateToCreatePackageCommand.RaiseCanExecuteChanged();
}
catch (Exception e)
{
Expand Down
8 changes: 8 additions & 0 deletions src/Arkivverket.Arkade/Core/InformationPackageCreator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,14 @@ private void AddFilesInDirectory(Archive archive, DirectoryInfo directory, Direc

foreach (FileInfo file in directory.GetFiles())
{
if (file.Length >= 8589934592) // 8 GB
{
throw new IOException(
"Cannot create tar entry from file with size of 8 GB. or more"
+ " The file " + file.Name + " has a size of: " + file.Length + " B."
);
}

if (file.Name == archive.GetInformationPackageFileName()) // don't try to add the tar file into the tar file...
{
continue;
Expand Down
30 changes: 30 additions & 0 deletions src/Arkivverket.Arkade/Core/TestSession.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Serilog;
using Arkivverket.Arkade.Core.Addml.Definitions;

namespace Arkivverket.Arkade.Core
{
public class TestSession
{
private readonly List<LogEntry> LogEntries = new List<LogEntry>();
private static readonly ILogger Log = Serilog.Log.ForContext<TestSession>();

public Archive Archive { get; }

Expand All @@ -21,10 +24,13 @@ public class TestSession

public DateTime DateOfTesting { get; }

private readonly bool _archiveHasOversizedFiles;

public TestSession(Archive archive)
{
Archive = archive;
DateOfTesting = DateTime.Now;
_archiveHasOversizedFiles = ArchiveHasOversizedFiles();
}

public void AddLogEntry(string message)
Expand All @@ -46,5 +52,29 @@ public bool IsTestableArchive()
{
return AddmlDefinition != null || Archive.ArchiveType == ArchiveType.Noark5;
}

public bool IsPackableArchive()
{
return !_archiveHasOversizedFiles;
}

private bool ArchiveHasOversizedFiles()
{
IEnumerable<FileInfo> contentDirectoryFiles =
Archive.WorkingDirectory.Content().DirectoryInfo().EnumerateFiles(".", SearchOption.AllDirectories);

const long singleFileSizeLimit = 8589934592; // 8 GB

IEnumerable<FileInfo> overSizedFiles =
contentDirectoryFiles.Where(file => file.Length > singleFileSizeLimit).ToArray();

const string message =
"Un-packable file found: {0}. The file size {1} B. is more than the current single file size limit of 8 GB.";

foreach (FileInfo file in overSizedFiles)
Log.Warning(string.Format(message, file.Name, file.Length));

return overSizedFiles.Any();
}
}
}

0 comments on commit 9db9d6a

Please sign in to comment.