Skip to content
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
4 changes: 2 additions & 2 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageReadmeFile>README.md</PackageReadmeFile>
<Product>Managed Code - Storage</Product>
<Version>2.0.3</Version>
<PackageVersion>2.0.3</PackageVersion>
<Version>2.0.4</Version>
<PackageVersion>2.0.4</PackageVersion>
</PropertyGroup>
<PropertyGroup Condition="'$(GITHUB_ACTIONS)' == 'true'">
<ContinuousIntegrationBuild>true</ContinuousIntegrationBuild>
Expand Down
4 changes: 2 additions & 2 deletions ManagedCode.Storage.AspNetExtensions/StorageExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public static async Task<Result<FileResult>> DownloadAsFileResult(this IStorage

if (result.IsError)
{
return Result<FileResult>.Fail(result.Error);
return Result<FileResult>.Fail(result.Error!);
}

var fileStream = new FileStreamResult(result.Value!.FileStream, MimeHelper.GetMimeType(result.Value.FileInfo.Extension))
Expand All @@ -67,7 +67,7 @@ public static async Task<Result<FileResult>> DownloadAsFileResult(this IStorage

if (result.IsError)
{
return Result.Fail<FileResult>(result.Error);
return Result.Fail<FileResult>(result.Error!);
}

var fileStream = new FileStreamResult(result.Value!.FileStream, MimeHelper.GetMimeType(result.Value.FileInfo.Extension))
Expand Down
2 changes: 1 addition & 1 deletion ManagedCode.Storage.Aws/ManagedCode.Storage.Aws.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="ManagedCode.Communication" Version="0.0.6" />
<PackageReference Include="ManagedCode.Communication" Version="0.0.8" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
<PackageReference Include="AWSSDK.S3" Version="3.7.9.26" />
<PackageReference Include="Humanizer.Core" Version="2.14.1" />
Expand Down
27 changes: 14 additions & 13 deletions ManagedCode.Storage.Azure/AzureStorage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,20 +186,20 @@ protected override async Task<Result<BlobMetadata>> GetBlobMetadataInternalAsync
var blobClient = StorageClient.GetBlobClient(options.FullPath);
var properties = await blobClient.GetPropertiesAsync(cancellationToken: cancellationToken);

if (properties != null)
if (properties is null)
{
return Result<BlobMetadata>.Succeed(new BlobMetadata
{
Name = blobClient.Name,
Uri = blobClient.Uri,
Container = blobClient.BlobContainerName,
Length = properties.Value.ContentLength,
Metadata = properties.Value.Metadata.ToDictionary(k => k.Key, v => v.Value),
MimeType = properties.Value.ContentType
});
return Result<BlobMetadata>.Fail("Properties for file not found");
}

return Result<BlobMetadata>.Fail();
return Result<BlobMetadata>.Succeed(new BlobMetadata
{
Name = blobClient.Name,
Uri = blobClient.Uri,
Container = blobClient.BlobContainerName,
Length = properties.Value.ContentLength,
Metadata = properties.Value.Metadata.ToDictionary(k => k.Key, v => v.Value),
MimeType = properties.Value.ContentType
});
}
catch (Exception ex)
{
Expand Down Expand Up @@ -238,8 +238,9 @@ protected override async Task<Result> SetLegalHoldInternalAsync(bool hasLegalHol
{
await EnsureContainerExist();
var blobClient = StorageClient.GetBlobClient(options.FullPath);
var response = await blobClient.SetLegalHoldAsync(hasLegalHold, cancellationToken);
return response.Value.HasLegalHold ? Result.Succeed() : Result.Fail();
await blobClient.SetLegalHoldAsync(hasLegalHold, cancellationToken);

return Result.Succeed();
}
catch (Exception ex)
{
Expand Down
2 changes: 1 addition & 1 deletion ManagedCode.Storage.Azure/ManagedCode.Storage.Azure.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

<ItemGroup>
<PackageReference Include="Azure.Storage.Files.DataLake" Version="12.11.0" />
<PackageReference Include="ManagedCode.Communication" Version="0.0.6" />
<PackageReference Include="ManagedCode.Communication" Version="0.0.8" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
<PackageReference Include="Azure.Storage.Blobs" Version="12.13.0" />
<PackageReference Include="Humanizer.Core" Version="2.14.1" />
Expand Down
4 changes: 2 additions & 2 deletions ManagedCode.Storage.AzureDataLake/AzureDataLakeStorage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -245,12 +245,12 @@ protected override async Task<Result> DeleteDirectoryInternalAsync(string direct
protected override Task<Result> SetLegalHoldInternalAsync(bool hasLegalHold, LegalHoldOptions options,
CancellationToken cancellationToken = default)
{
throw new NotSupportedException("Legal hold is not supported by Data Lake Storage");
return Result.Fail(new NotSupportedException("Legal hold is not supported by Data Lake Storage")).AsTask();
}

protected override Task<Result<bool>> HasLegalHoldInternalAsync(LegalHoldOptions options, CancellationToken cancellationToken = default)
{
throw new NotSupportedException("Legal hold is not supported by Data Lake Storage");
return Result<bool>.Fail(new NotSupportedException("Legal hold is not supported by Data Lake Storage")).AsTask();
}

private DataLakeFileClient GetFileClient(BaseOptions options)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

<ItemGroup>
<PackageReference Include="Azure.Storage.Files.DataLake" Version="12.11.0" />
<PackageReference Include="ManagedCode.Communication" Version="0.0.6" />
<PackageReference Include="ManagedCode.Communication" Version="0.0.8" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
<PackageReference Include="Azure.Storage.Blobs" Version="12.13.0" />
<PackageReference Include="Humanizer.Core" Version="2.14.1" />
Expand Down
2 changes: 1 addition & 1 deletion ManagedCode.Storage.Core/ManagedCode.Storage.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="ManagedCode.Communication" Version="0.0.6" />
<PackageReference Include="ManagedCode.Communication" Version="0.0.8" />
<PackageReference Include="ManagedCode.MimeTypes" Version="1.0.0" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="6.0.0" />
Expand Down
35 changes: 16 additions & 19 deletions ManagedCode.Storage.FileSystem/FileSystemStorage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,9 @@ protected override async Task<Result<LocalFile>> DownloadInternalAsync(LocalFile

var filePath = GetPathFromOptions(options);

if (File.Exists(filePath))
{
return Result<LocalFile>.Succeed(new LocalFile(filePath));
}

return Result<LocalFile>.Fail();
return File.Exists(filePath)
? Result<LocalFile>.Succeed(new LocalFile(filePath))
: Result<LocalFile>.Fail("File not found");
}

protected override async Task<Result<bool>> DeleteInternalAsync(DeleteOptions options, CancellationToken cancellationToken = default)
Expand Down Expand Up @@ -135,20 +132,20 @@ protected override async Task<Result<BlobMetadata>> GetBlobMetadataInternalAsync
var filePath = GetPathFromOptions(options);
var fileInfo = new FileInfo(filePath);

if (fileInfo.Exists)
if (!fileInfo.Exists)
{
var result = new BlobMetadata
{
Name = fileInfo.Name,
Uri = new Uri(Path.Combine(_path, filePath)),
MimeType = MimeHelper.GetMimeType(fileInfo.Extension),
Length = fileInfo.Length
};

return Result<BlobMetadata>.Succeed(result);
return Result<BlobMetadata>.Fail("File not found");
}

return Result<BlobMetadata>.Fail();
var result = new BlobMetadata
{
Name = fileInfo.Name,
Uri = new Uri(Path.Combine(_path, filePath)),
MimeType = MimeHelper.GetMimeType(fileInfo.Extension),
Length = fileInfo.Length
};

return Result<BlobMetadata>.Succeed(result);
}

public override async IAsyncEnumerable<BlobMetadata> GetBlobMetadataListAsync(string? directory = null,
Expand Down Expand Up @@ -185,7 +182,7 @@ protected override async Task<Result> SetLegalHoldInternalAsync(bool hasLegalHol
var file = await DownloadAsync(filePath, cancellationToken);

if (file.IsError)
return Result.Fail();
return Result.Fail(file.Error);

var fileStream = File.OpenRead(file.Value!.FilePath); // Opening with FileAccess.Read only
fileStream.Lock(0, fileStream.Length); // Attempting to lock a region of the read-only file
Expand All @@ -196,7 +193,7 @@ protected override async Task<Result> SetLegalHoldInternalAsync(bool hasLegalHol
}

if (!hasLegalHold)
{
{
if (_lockedFiles.ContainsKey(filePath))
{
_lockedFiles[filePath].Unlock(0, _lockedFiles[filePath].Length);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="ManagedCode.Communication" Version="0.0.6" />
<PackageReference Include="ManagedCode.Communication" Version="0.0.8" />
<PackageReference Include="ManagedCode.MimeTypes" Version="1.0.0" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
</ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion ManagedCode.Storage.Gcp/ManagedCode.Storage.Gcp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<PackageReference Include="Google.Api.Gax" Version="4.0.0" />
<PackageReference Include="Google.Api.Gax.Rest" Version="4.0.0" />
<PackageReference Include="Google.Apis.Storage.v1" Version="1.57.0.2685" />
<PackageReference Include="ManagedCode.Communication" Version="0.0.6" />
<PackageReference Include="ManagedCode.Communication" Version="0.0.8" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
<PackageReference Include="Google.Cloud.Storage.V1" Version="4.0.0" />
<PackageReference Include="Humanizer.Core" Version="2.14.1" />
Expand Down
2 changes: 1 addition & 1 deletion ManagedCode.Storage.Tests/ManagedCode.Storage.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<PackageReference Include="Azure.Storage.Files.DataLake" Version="12.11.0" />
<PackageReference Include="CsvHelper" Version="28.0.1" />
<PackageReference Include="FluentAssertions" Version="6.7.0" />
<PackageReference Include="ManagedCode.Communication" Version="0.0.6" />
<PackageReference Include="ManagedCode.Communication" Version="0.0.8" />
<PackageReference Include="Microsoft.AspNetCore.Http" Version="2.2.2" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="6.0.0" />
Expand Down
Loading