Skip to content

Commit

Permalink
Merge pull request #353 from fiskaltrust/Release1.3.64
Browse files Browse the repository at this point in the history
Release 1.3.64
  • Loading branch information
forsthug authored Oct 3, 2024
2 parents c47d0e6 + cb32b6e commit a4fc546
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ public class ExportStateData
public Exception Error { get; set; } = null;
public ExportState State { get; set; }
public bool EraseEnabled { get; set; } = false;
public string ExportPath { get; set; }
}
}
27 changes: 13 additions & 14 deletions scu-de/src/fiskaltrust.Middleware.SCU.DE.Swissbit/SwissbitSCU.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
Expand Down Expand Up @@ -739,7 +738,8 @@ public async Task<StartExportSessionResponse> StartExportSessionAsync(StartExpor
}

await UpdateTimeAsync(GetProxy());
SetExportState(exportId, ExportState.Running);
var path = GetTempExportFilePath(exportId.ToString());
SetExportState(exportId, ExportState.Running, null, path);

CacheExportAsync(exportId, request.ClientId, request.Erase).FireAndForget();

Expand Down Expand Up @@ -772,8 +772,8 @@ await _lockingHelper.PerformWithLock(_hwLock, async () =>
await GetProxy().UserLoginAsync(WormUserId.WORM_USER_ADMIN, Encoding.ASCII.GetBytes(_configuration.AdminPin));
SetEraseEnabledForExportState(exportId, ExportState.Running);
}
using (var tempStream = File.Open(GetTempExportFilePath(exportId.ToString()), FileMode.OpenOrCreate, FileAccess.Write, FileShare.Read))
_readStreamPointer.TryGetValue(exportId.ToString(), out var exportStateData);
using (var tempStream = File.Open(exportStateData.ExportPath, FileMode.OpenOrCreate, FileAccess.Write, FileShare.Write))
{
await GetProxy().ExportTarAsync(tempStream);
}
Expand Down Expand Up @@ -825,12 +825,13 @@ private void SetEraseEnabledForExportState(Guid tokenId, ExportState exportState
});
}

private void SetExportState(Guid tokenId, ExportState exportState, Exception error = null)
private void SetExportState(Guid tokenId, ExportState exportState, Exception error = null, string path = null)
{
_readStreamPointer.AddOrUpdate(tokenId.ToString(), new ExportStateData
{
ReadPointer = 0,
State = exportState
State = exportState,
ExportPath = path
}, (key, value) =>
{
value.State = exportState;
Expand Down Expand Up @@ -869,7 +870,6 @@ public async Task<ExportDataResponse> ExportDataAsync(ExportDataRequest request)
TarFileEndOfFile = true
};
}
var tempFileName = GetTempExportFilePath(request.TokenId);
if (!_readStreamPointer.ContainsKey(request.TokenId))
{
throw new SwissbitException("The export failed to start. It needs to be retriggered");
Expand All @@ -879,7 +879,7 @@ public async Task<ExportDataResponse> ExportDataAsync(ExportDataRequest request)
throw exportStateData.Error;
}

if (exportStateData.State != ExportState.Succeeded || !File.Exists(tempFileName))
if (exportStateData.State != ExportState.Succeeded || !File.Exists(exportStateData.ExportPath))
{
return new ExportDataResponse
{
Expand All @@ -896,7 +896,7 @@ public async Task<ExportDataResponse> ExportDataAsync(ExportDataRequest request)
if (request.MaxChunkSize > 0)
{
var chunkSize = request.MaxChunkSize;
using (var tempStream = File.OpenRead(tempFileName))
using (var tempStream = File.OpenRead(exportStateData.ExportPath))
{
tempStream.Seek(exportStateData.ReadPointer, SeekOrigin.Begin);

Expand All @@ -910,7 +910,7 @@ public async Task<ExportDataResponse> ExportDataAsync(ExportDataRequest request)
exportStateData.ReadPointer += len;
}
}
exportDataResponse.TotalTarFileSize = new FileInfo(tempFileName).Length;
exportDataResponse.TotalTarFileSize = new FileInfo(exportStateData.ExportPath).Length;
exportDataResponse.TotalTarFileSizeAvailable = exportDataResponse.TotalTarFileSize >= 0;
exportDataResponse.TarFileEndOfFile = exportStateData.ReadPointer == exportDataResponse.TotalTarFileSize;
return exportDataResponse;
Expand Down Expand Up @@ -946,7 +946,6 @@ public async Task<EndExportSessionResponse> EndExportSessionAsync(EndExportSessi
throw exportStateData.Error;
}

var tempFileName = GetTempExportFilePath(request.TokenId);
return await _lockingHelper.PerformWithLock(_hwLock, async () =>
{
try
Expand All @@ -955,7 +954,7 @@ public async Task<EndExportSessionResponse> EndExportSessionAsync(EndExportSessi
{
TokenId = request.TokenId
};
using (var tempStream = File.Open(tempFileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
using (var tempStream = File.Open(exportStateData.ExportPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
{
var sha256 = SHA256.Create().ComputeHash(tempStream);
if (tempStream.Position != exportStateData.ReadPointer)
Expand Down Expand Up @@ -988,9 +987,9 @@ public async Task<EndExportSessionResponse> EndExportSessionAsync(EndExportSessi
}
try
{
if (File.Exists(tempFileName) && !_configuration.StoreTemporaryExportFiles)
if (File.Exists(exportStateData.ExportPath) && !_configuration.StoreTemporaryExportFiles)
{
File.Delete(tempFileName);
File.Delete(exportStateData.ExportPath);
}
}
catch { }
Expand Down

0 comments on commit a4fc546

Please sign in to comment.