Skip to content

Commit

Permalink
Merge pull request #1707 from qdraw/feature/202409_code_smells_10a
Browse files Browse the repository at this point in the history
fix code smells
  • Loading branch information
qdraw authored Sep 11, 2024
2 parents 8cd6bff + 05b0088 commit 0f76a68
Show file tree
Hide file tree
Showing 35 changed files with 3,273 additions and 2,921 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -191,12 +191,12 @@ private static async Task<List<string>> ReadCommand(MySqlCommand command)
{
if ( command.Connection?.State != ConnectionState.Open )
{
return new List<string>();
return [];
}

var tableNames = new List<string>();
await using var reader = await command.ExecuteReaderAsync();
while ( reader.Read() )
while ( await reader.ReadAsync() )
{
// at least two columns
tableNames.Add(reader.GetString(0) + "," + reader.GetString(1));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace starsky.foundation.platform.JsonConverter;

/// <summary>
/// Enum converter for Lists with Enum into Json
/// Enum converter for Lists with Enum into Json
/// </summary>
/// <typeparam name="T">Enum</typeparam>
[SuppressMessage("ReSharper", "S6966: Await ReadAsync instead.",
Justification = "There is no Async jet")]
public class EnumListConverter<T> : JsonConverter<List<T>> where T : struct, Enum
{
public override List<T> Read(ref Utf8JsonReader reader, Type typeToConvert,
Expand Down
16 changes: 13 additions & 3 deletions starsky/starsky.foundation.storage/ArchiveFormats/TarBal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,18 @@ public async Task ExtractTar(Stream stream, string outputDir,
}
}

private static async Task<string> CreateLongFileName(long size, Stream stream,
private async Task<string> CreateLongFileName(long size, Stream stream,
CancellationToken cancellationToken)
{
//If Type Tag is 'L' we have a filename that is longer than the 100 bytes reserved for it in the header.
//We read it here and save it temporarily as it will be the file name of the next block where the actual data is
var buf = new byte[size];
await stream.ReadAsync(buf, 0, buf.Length, cancellationToken);
var actualSize = await stream.ReadAsync(buf, 0, buf.Length, cancellationToken);
if ( actualSize != size )
{
_logger.LogError("[CreateLongFileName] less than {size} bytes read", size);
}

return Encoding.ASCII.GetString(buf).Trim('\0');
}

Expand All @@ -147,7 +152,12 @@ private async Task CreateFileOrDirectory(string outputDir, string name, long siz
{
var str = new MemoryStream();
var buf = new byte[size];
await stream.ReadAsync(buf, 0, buf.Length, cancellationToken);
var actualSize = await stream.ReadAsync(buf, 0, buf.Length, cancellationToken);
if ( actualSize != size )
{
_logger.LogError("[CreateFileOrDirectory] less than {size} bytes read", size);
}

await str.WriteAsync(buf, 0, buf.Length, cancellationToken);
_storage.WriteStreamOpenOrCreate(str, output);
}
Expand Down
Loading

0 comments on commit 0f76a68

Please sign in to comment.