Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Extensions.PersistentStorage] Fix analysis warnings #958

Merged
merged 2 commits into from
Feb 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ OpenTelemetry.Extensions.PersistentStorage.FileBlob.FileBlob(string fullPath) ->
OpenTelemetry.Extensions.PersistentStorage.FileBlob.FullPath.get -> string
OpenTelemetry.Extensions.PersistentStorage.FileBlobProvider
OpenTelemetry.Extensions.PersistentStorage.FileBlobProvider.Dispose() -> void
OpenTelemetry.Extensions.PersistentStorage.FileBlobProvider.Dispose(bool disposing) -> void
OpenTelemetry.Extensions.PersistentStorage.FileBlobProvider.FileBlobProvider(string path, long maxSizeInBytes = 52428800, int maintenancePeriodInMilliseconds = 120000, long retentionPeriodInMilliseconds = 172800000, int writeTimeoutInMilliseconds = 60000) -> void
override OpenTelemetry.Extensions.PersistentStorage.FileBlob.OnTryDelete() -> bool
override OpenTelemetry.Extensions.PersistentStorage.FileBlob.OnTryLease(int leasePeriodMilliseconds) -> bool
Expand All @@ -12,4 +11,5 @@ override OpenTelemetry.Extensions.PersistentStorage.FileBlob.OnTryWrite(byte[] b
override OpenTelemetry.Extensions.PersistentStorage.FileBlobProvider.OnGetBlobs() -> System.Collections.Generic.IEnumerable<OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlob>
override OpenTelemetry.Extensions.PersistentStorage.FileBlobProvider.OnTryCreateBlob(byte[] buffer, int leasePeriodMilliseconds, out OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlob blob) -> bool
override OpenTelemetry.Extensions.PersistentStorage.FileBlobProvider.OnTryCreateBlob(byte[] buffer, out OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlob blob) -> bool
override OpenTelemetry.Extensions.PersistentStorage.FileBlobProvider.OnTryGetBlob(out OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlob blob) -> bool
override OpenTelemetry.Extensions.PersistentStorage.FileBlobProvider.OnTryGetBlob(out OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlob blob) -> bool
virtual OpenTelemetry.Extensions.PersistentStorage.FileBlobProvider.Dispose(bool disposing) -> void
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ OpenTelemetry.Extensions.PersistentStorage.FileBlob.FileBlob(string fullPath) ->
OpenTelemetry.Extensions.PersistentStorage.FileBlob.FullPath.get -> string
OpenTelemetry.Extensions.PersistentStorage.FileBlobProvider
OpenTelemetry.Extensions.PersistentStorage.FileBlobProvider.Dispose() -> void
OpenTelemetry.Extensions.PersistentStorage.FileBlobProvider.Dispose(bool disposing) -> void
OpenTelemetry.Extensions.PersistentStorage.FileBlobProvider.FileBlobProvider(string path, long maxSizeInBytes = 52428800, int maintenancePeriodInMilliseconds = 120000, long retentionPeriodInMilliseconds = 172800000, int writeTimeoutInMilliseconds = 60000) -> void
override OpenTelemetry.Extensions.PersistentStorage.FileBlob.OnTryDelete() -> bool
override OpenTelemetry.Extensions.PersistentStorage.FileBlob.OnTryLease(int leasePeriodMilliseconds) -> bool
Expand All @@ -12,4 +11,5 @@ override OpenTelemetry.Extensions.PersistentStorage.FileBlob.OnTryWrite(byte[] b
override OpenTelemetry.Extensions.PersistentStorage.FileBlobProvider.OnGetBlobs() -> System.Collections.Generic.IEnumerable<OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlob>
override OpenTelemetry.Extensions.PersistentStorage.FileBlobProvider.OnTryCreateBlob(byte[] buffer, int leasePeriodMilliseconds, out OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlob blob) -> bool
override OpenTelemetry.Extensions.PersistentStorage.FileBlobProvider.OnTryCreateBlob(byte[] buffer, out OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlob blob) -> bool
override OpenTelemetry.Extensions.PersistentStorage.FileBlobProvider.OnTryGetBlob(out OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlob blob) -> bool
override OpenTelemetry.Extensions.PersistentStorage.FileBlobProvider.OnTryGetBlob(out OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlob blob) -> bool
virtual OpenTelemetry.Extensions.PersistentStorage.FileBlobProvider.Dispose(bool disposing) -> void
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ OpenTelemetry.Extensions.PersistentStorage.FileBlob.FileBlob(string fullPath) ->
OpenTelemetry.Extensions.PersistentStorage.FileBlob.FullPath.get -> string
OpenTelemetry.Extensions.PersistentStorage.FileBlobProvider
OpenTelemetry.Extensions.PersistentStorage.FileBlobProvider.Dispose() -> void
OpenTelemetry.Extensions.PersistentStorage.FileBlobProvider.Dispose(bool disposing) -> void
OpenTelemetry.Extensions.PersistentStorage.FileBlobProvider.FileBlobProvider(string path, long maxSizeInBytes = 52428800, int maintenancePeriodInMilliseconds = 120000, long retentionPeriodInMilliseconds = 172800000, int writeTimeoutInMilliseconds = 60000) -> void
override OpenTelemetry.Extensions.PersistentStorage.FileBlob.OnTryDelete() -> bool
override OpenTelemetry.Extensions.PersistentStorage.FileBlob.OnTryLease(int leasePeriodMilliseconds) -> bool
Expand All @@ -12,4 +11,5 @@ override OpenTelemetry.Extensions.PersistentStorage.FileBlob.OnTryWrite(byte[] b
override OpenTelemetry.Extensions.PersistentStorage.FileBlobProvider.OnGetBlobs() -> System.Collections.Generic.IEnumerable<OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlob>
override OpenTelemetry.Extensions.PersistentStorage.FileBlobProvider.OnTryCreateBlob(byte[] buffer, int leasePeriodMilliseconds, out OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlob blob) -> bool
override OpenTelemetry.Extensions.PersistentStorage.FileBlobProvider.OnTryCreateBlob(byte[] buffer, out OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlob blob) -> bool
override OpenTelemetry.Extensions.PersistentStorage.FileBlobProvider.OnTryGetBlob(out OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlob blob) -> bool
override OpenTelemetry.Extensions.PersistentStorage.FileBlobProvider.OnTryGetBlob(out OpenTelemetry.Extensions.PersistentStorage.Abstractions.PersistentBlob blob) -> bool
virtual OpenTelemetry.Extensions.PersistentStorage.FileBlobProvider.Dispose(bool disposing) -> void
3 changes: 3 additions & 0 deletions src/OpenTelemetry.Extensions.PersistentStorage/FileBlob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
using System.Diagnostics.CodeAnalysis;
using System.IO;
using OpenTelemetry.Extensions.PersistentStorage.Abstractions;
using OpenTelemetry.Internal;

namespace OpenTelemetry.Extensions.PersistentStorage;

Expand Down Expand Up @@ -57,6 +58,8 @@ protected override bool OnTryRead([NotNullWhen(true)] out byte[] buffer)

protected override bool OnTryWrite(byte[] buffer, int leasePeriodMilliseconds = 0)
{
Guard.ThrowIfNull(buffer);

string path = this.FullPath + ".tmp";

try
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public void Dispose()
GC.SuppressFinalize(this);
}

public void Dispose(bool disposing)
protected virtual void Dispose(bool disposing)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

{
if (!this.disposedValue)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,14 @@ internal static DateTime GetDateTimeFromLeaseName(string filePath)

internal static string GetSHA256Hash(string input)
{
var hashString = new StringBuilder();

byte[] inputBits = Encoding.Unicode.GetBytes(input);

#if NET6_0_OR_GREATER
#pragma warning disable CA1308 // Normalize strings to uppercase
return Convert.ToHexString(SHA256.HashData(inputBits)).ToLowerInvariant();
#pragma warning restore CA1308 // Normalize strings to uppercase
#else
var hashString = new StringBuilder();
using (var sha256 = SHA256.Create())
{
byte[] hashBits = sha256.ComputeHash(inputBits);
Expand All @@ -217,6 +222,7 @@ internal static string GetSHA256Hash(string input)
}

return hashString.ToString();
#endif
}

private static long CalculateFolderSize(string path)
Expand Down