Skip to content

Commit

Permalink
Merge pull request #1394 from qdraw/feature/202402-flush-upload
Browse files Browse the repository at this point in the history
Feature/202402 flush upload
  • Loading branch information
qdraw authored Feb 18, 2024
2 parents cb3bbed + 22bd7e8 commit 6ac9d9f
Show file tree
Hide file tree
Showing 11 changed files with 67 additions and 37 deletions.
8 changes: 4 additions & 4 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,13 @@ dotnet_remove_unnecessary_suppression_exclusions = none:warning

dotnet_style_namespace_match_folder = true:suggestion

# unused usings
# unused usings (IDE0005)
dotnet_diagnostic.IDE0005.severity = warning

dotnet_diagnostic.IDE0028.severity = silent # IDE0028 = Simplify collection initialization
dotnet_diagnostic.IDE0051.severity = silent # Private member is unused

# CS4014: Because this call is not awaited, execution of the current method continues before the call is completed.
# Consider applying the 'await' operator to the result of the call.
dotnet_diagnostic.CS4014.severity = error


dotnet_diagnostic.IDE0028.severity = silent # IDE0028 = Simplify collection initialization
dotnet_diagnostic.IDE0051.severity = silent # Private member is unused
1 change: 1 addition & 0 deletions history.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ Semantic Versioning 2.0.0 is from version 0.1.6+
- [x] (Fixed) _Back-end_ Docker update base package and no recommendations install (PR #1393)
- [x] (Fixed) _Back-end_ Corrupt images where generated due import (Issue started with .NET 8) (PR
#1392)
- [x] (Fixed) _Back-end_ Flush issue with Upload (PR #1394)

## version 0.6.0-beta.0 - 2024-02-11 {#v0.6.0-beta.0}

Expand Down
4 changes: 2 additions & 2 deletions starsky/.config/dotnet-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
"isRoot": true,
"tools": {
"dotnet-sonarscanner": {
"version": "6.1.0",
"version": "6.2.0",
"commands": [
"dotnet-sonarscanner"
]
}
}
}
}
1 change: 1 addition & 0 deletions starsky/build.vstest.runsettings
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<Configuration>
<Format>opencover</Format>
<Exclude>[MySqlConnector]*,[starsky.Views]*,[*]starsky.foundation.database.Migrations.*</Exclude> <!-- [Assembly-Filter]Type-Filter -->
<ExcludeByFile>**/*.Generator.RegexGenerator/**,**/Migrations/**</ExcludeByFile>
</Configuration>
</DataCollector>
</DataCollectors>
Expand Down
6 changes: 6 additions & 0 deletions starsky/build/_build.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,10 @@
<None Remove="logs\**"/>
</ItemGroup>

<ItemGroup>
<Content Include="..\.config\dotnet-tools.json">
<Link>config\dotnet-tools.json</Link>
</Content>
</ItemGroup>

</Project>
54 changes: 27 additions & 27 deletions starsky/build/helpers/SonarQube.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public static class SonarQube
/// <summary>
/// @see: https://www.nuget.org/packages/dotnet-sonarscanner
/// </summary>
public const string SonarQubePackageVersion = "6.1.0";
public const string SonarQubePackageVersion = "6.2.0";

public const string SonarQubeDotnetSonarScannerApi =
"https://api.nuget.org/v3-flatcontainer/dotnet-sonarscanner/index.json";
Expand Down Expand Up @@ -57,7 +57,7 @@ public static void InstallSonarTool(bool noUnitTest, bool noSonar)

var toolList = DotNet($"tool list", rootDirectory, envs, null, true);
if ( toolList.Any(p => p.Text.Contains(SonarQubePackageName)
&& toolList.Any(p => p.Text.Contains(SonarQubePackageVersion))) )
&& toolList.Any(p => p.Text.Contains(SonarQubePackageVersion))) )
{
Log.Information("Next: tool restore");
DotNet($"tool restore", rootDirectory, envs, null, true);
Expand Down Expand Up @@ -92,19 +92,19 @@ static async Task CheckLatestVersionDotNetSonarScanner()
if ( result == null )
{
Log.Information($"Nuget API is not available, " +
$"so skip checking the latest version of {SonarQubePackageName}");
$"so skip checking the latest version of {SonarQubePackageName}");
return;
}

var latestVersionByApi = HttpQuery.ParseJsonVersionNumbers(result);
if ( latestVersionByApi > new Version(SonarQubePackageVersion) )
{
Log.Warning($"Please upgrade to the latest version " +
$"of dotnet-sonarscanner {latestVersionByApi} \n\n" +
"Update the following values: \n" +
$"- build/helpers/SonarQube.cs -> SonarQubePackageVersion to {latestVersionByApi} \n" +
"The _build project will auto update: \n" +
"- .config/dotnet-tools.json");
$"of dotnet-sonarscanner {latestVersionByApi} \n\n" +
"Update the following values: \n" +
$"- build/helpers/SonarQube.cs -> SonarQubePackageVersion to {latestVersionByApi} \n" +
"The _build project will auto update: \n" +
"- .config/dotnet-tools.json");
}
}

Expand Down Expand Up @@ -147,7 +147,7 @@ public static bool SonarBegin(bool noUnitTest, bool noSonar, string branchName,
}

if ( string.IsNullOrEmpty(GetSonarKey()) || string.IsNullOrEmpty(sonarToken) ||
string.IsNullOrEmpty(organisation) )
string.IsNullOrEmpty(organisation) )
{
Information(
$">> SonarQube is disabled $ key={GetSonarKey()}|token={sonarToken}|organisation={organisation}");
Expand Down Expand Up @@ -192,9 +192,9 @@ public static bool SonarBegin(bool noUnitTest, bool noSonar, string branchName,

// For Pull Requests
var isPrBuild = EnvironmentVariable("GITHUB_ACTIONS") != null &&
EnvironmentVariable("GITHUB_JOB") != null &&
EnvironmentVariable("GITHUB_BASE_REF") != null &&
!string.IsNullOrEmpty(EnvironmentVariable("PR_NUMBER_GITHUB"));
EnvironmentVariable("GITHUB_JOB") != null &&
EnvironmentVariable("GITHUB_BASE_REF") != null &&
!string.IsNullOrEmpty(EnvironmentVariable("PR_NUMBER_GITHUB"));

var githubPrNumber = EnvironmentVariable("PR_NUMBER_GITHUB");
var githubBaseBranch = EnvironmentVariable("GITHUB_BASE_REF");
Expand All @@ -218,21 +218,21 @@ public static bool SonarBegin(bool noUnitTest, bool noSonar, string branchName,
.Append($"/d:sonar.typescript.tsconfigPath={tsconfig} ")
.Append($"/d:sonar.coverageReportPaths={sonarQubeCoverageFile} ")
.Append($"/d:sonar.exclusions=**/build/*,**/build/helpers/*," +
"**/documentation/*," +
"**/Interfaces/IQuery.cs," +
$"**/setupTests.js,**/react-app-env.d.ts,**/service-worker.ts," +
$"*webhtmlcli/**/*.js,**/wwwroot/js/**/*,**/*/Migrations/*,**/*spec.tsx," +
$"**/*stories.tsx,**/*spec.ts,**/src/main.tsx,**/src/index.tsx,**/src/style/css/vendor/*,**/node_modules/*," +
$"**/prestorybook.js,**/vite.config.ts,**/.storybook/**,**/jest.setup.ts," +
$"**/_bigimages-helper.js ")
"**/documentation/*," +
"**/Interfaces/IQuery.cs," +
$"**/setupTests.js,**/react-app-env.d.ts,**/service-worker.ts," +
$"*webhtmlcli/**/*.js,**/wwwroot/js/**/*,**/*/Migrations/*,**/*spec.tsx," +
$"**/*stories.tsx,**/*spec.ts,**/src/main.tsx,**/src/index.tsx,**/src/style/css/vendor/*,**/node_modules/*," +
$"**/prestorybook.js,**/vite.config.ts,**/.storybook/**,**/jest.setup.ts," +
$"**/_bigimages-helper.js ")
.Append($"/d:sonar.coverage.exclusions=**/build/*,**/build/helpers/*," +
"**/documentation/*," +
"**/Interfaces/IQuery.cs," +
$"**/setupTests.js,**/react-app-env.d.ts,**/service-worker.ts," +
$"*webhtmlcli/**/*.js,**/wwwroot/js/**/*,**/*/Migrations/*," +
$"**/*spec.ts,**/*stories.tsx,**/*spec.tsx,**/src/main.tsx,**/src/index.tsx,**/node_modules/*," +
$"**/prestorybook.js,**/vite.config.ts,**/.storybook/**,**/jest.setup.ts," +
$"**/_bigimages-helper.js ");
"**/documentation/*," +
"**/Interfaces/IQuery.cs," +
$"**/setupTests.js,**/react-app-env.d.ts,**/service-worker.ts," +
$"*webhtmlcli/**/*.js,**/wwwroot/js/**/*,**/*/Migrations/*," +
$"**/*spec.ts,**/*stories.tsx,**/*spec.tsx,**/src/main.tsx,**/src/index.tsx,**/node_modules/*," +
$"**/prestorybook.js,**/vite.config.ts,**/.storybook/**,**/jest.setup.ts," +
$"**/_bigimages-helper.js ");

// Normal build
if ( !isPrBuild )
Expand All @@ -246,7 +246,7 @@ public static bool SonarBegin(bool noUnitTest, bool noSonar, string branchName,
if ( isPrBuild )
{
Information($">> PR Build isPRBuild={true} githubPrNumber " +
$"{githubPrNumber} githubBaseBranch {githubBaseBranch} githubRepoSlug {githubRepoSlug}");
$"{githubPrNumber} githubBaseBranch {githubBaseBranch} githubRepoSlug {githubRepoSlug}");

sonarArguments
.Append($"/d:sonar.pullrequest.key={githubPrNumber} ")
Expand Down
9 changes: 9 additions & 0 deletions starsky/nuget.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<clear/>
<!-- Default nuget feed -->
<add key="nuget" value="https://api.nuget.org/v3/index.json"/>
<!-- Add all other needed feed -->
</packageSources>
</configuration>
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,7 @@ private static byte[] ReadBuffer(Stream stream, int size)

/// <summary>
/// Get the format of the image by looking the first bytes
/// Stream is Flushed / Disposed afterwards
/// </summary>
/// <param name="stream">stream</param>
/// <returns>ImageFormat enum</returns>
Expand Down
15 changes: 14 additions & 1 deletion starsky/starsky.foundation.storage/Interfaces/IStorage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,24 @@ public interface IStorage
/// <returns>Stream with data (non-disposed)</returns>
Stream ReadStream(string path, int maxRead = -1);

/// <summary>
/// Write and Dispose / Flush afterwards
/// </summary>
/// <param name="stream">stream</param>
/// <param name="path">where to write to</param>
/// <returns>is Success</returns>
bool WriteStream(Stream stream, string path);

/// <summary>
/// Append To Open Stream
/// </summary>
/// <param name="stream">what to append</param>
/// <param name="path">location</param>
/// <returns></returns>
bool WriteStreamOpenOrCreate(Stream stream, string path);

/// <summary>
/// Write and dispose afterwards
/// Write and Dispose / Flush afterwards
/// </summary>
/// <param name="stream">stream</param>
/// <param name="path">where to write to</param>
Expand Down
2 changes: 1 addition & 1 deletion starsky/starsky.foundation.writemeta/Helpers/ExifTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ public async Task<bool> WriteTagsThumbnailAsync(string fileHash, string command)
var inputStream = _thumbnailStorage.ReadStream(fileHash);
var runner = new StreamToStreamRunner(_appSettings, inputStream, _logger);
var stream = await runner.RunProcessAsync(command);
// Need to Dispose for Windows
// Need to Close/Dispose for Windows and needs before WriteStreamAsync
inputStream.Close();
return await _thumbnailStorage.WriteStreamAsync(stream, fileHash);
}
Expand Down
3 changes: 1 addition & 2 deletions starsky/starsky/Controllers/UploadController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,7 @@ public async Task<IActionResult> UploadToFolder()

var writeStatus =
await _iStorage.WriteStreamAsync(tempFileStream, subPath + ".tmp");
await tempFileStream.FlushAsync();
await tempFileStream.DisposeAsync(); // also flush
// Is already flushed / disposed when the stream is written

// to avoid partly written stream to be read by an other application
_iStorage.FileDelete(subPath);
Expand Down

0 comments on commit 6ac9d9f

Please sign in to comment.