From 54b10f335193563c023fcc68dff3794fbffb606c Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Wed, 8 Oct 2025 21:32:54 -0700 Subject: [PATCH] Address Gemini Code Assist review comments Fixed three issues identified by Gemini Code Assist: 1. HIGH: ReadFile now uses blob.CountToEnd when size is 0 - Old SDK: size=0 meant "read to end" - New SDK: size=0 means "read 0 bytes" - Fix: Use blob.CountToEnd (-1) to read entire blob from offset 2. MEDIUM: Use to.Ptr() instead of slice trick for DeleteSnapshots - Replaced &[]Type{value}[0] with to.Ptr(value) - Cleaner, more idiomatic Azure SDK pattern - Applied to both azure_storage_client.go and azure_sink.go 3. Added missing imports: - github.com/Azure/azure-sdk-for-go/sdk/azcore/to These changes improve code clarity and correctness while following Azure SDK best practices. --- weed/remote_storage/azure/azure_storage_client.go | 6 +++++- weed/replication/sink/azuresink/azure_sink.go | 3 ++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/weed/remote_storage/azure/azure_storage_client.go b/weed/remote_storage/azure/azure_storage_client.go index df5df86ff..4fa3a8388 100644 --- a/weed/remote_storage/azure/azure_storage_client.go +++ b/weed/remote_storage/azure/azure_storage_client.go @@ -8,6 +8,7 @@ import ( "reflect" "strings" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/to" "github.com/Azure/azure-sdk-for-go/sdk/storage/azblob" "github.com/Azure/azure-sdk-for-go/sdk/storage/azblob/blob" "github.com/Azure/azure-sdk-for-go/sdk/storage/azblob/blockblob" @@ -121,6 +122,9 @@ func (az *azureRemoteStorageClient) ReadFile(loc *remote_pb.RemoteStorageLocatio blobClient := az.client.ServiceClient().NewContainerClient(loc.Bucket).NewBlockBlobClient(key) count := size + if count == 0 { + count = blob.CountToEnd + } downloadResp, err := blobClient.DownloadStream(context.Background(), &blob.DownloadStreamOptions{ Range: blob.HTTPRange{ Offset: offset, @@ -231,7 +235,7 @@ func (az *azureRemoteStorageClient) DeleteFile(loc *remote_pb.RemoteStorageLocat blobClient := az.client.ServiceClient().NewContainerClient(loc.Bucket).NewBlobClient(key) _, err = blobClient.Delete(context.Background(), &blob.DeleteOptions{ - DeleteSnapshots: &[]blob.DeleteSnapshotsOptionType{blob.DeleteSnapshotsOptionTypeInclude}[0], + DeleteSnapshots: to.Ptr(blob.DeleteSnapshotsOptionTypeInclude), }) if err != nil { return fmt.Errorf("azure delete %s%s: %v", loc.Bucket, loc.Path, err) diff --git a/weed/replication/sink/azuresink/azure_sink.go b/weed/replication/sink/azuresink/azure_sink.go index 90aca701f..c75b4a9c1 100644 --- a/weed/replication/sink/azuresink/azure_sink.go +++ b/weed/replication/sink/azuresink/azure_sink.go @@ -11,6 +11,7 @@ import ( "github.com/Azure/azure-sdk-for-go/sdk/azcore" "github.com/Azure/azure-sdk-for-go/sdk/azcore/streaming" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/to" "github.com/Azure/azure-sdk-for-go/sdk/storage/azblob" "github.com/Azure/azure-sdk-for-go/sdk/storage/azblob/appendblob" "github.com/Azure/azure-sdk-for-go/sdk/storage/azblob/blob" @@ -92,7 +93,7 @@ func (g *AzureSink) DeleteEntry(key string, isDirectory, deleteIncludeChunks boo blobClient := g.client.ServiceClient().NewContainerClient(g.container).NewBlobClient(key) _, err := blobClient.Delete(context.Background(), &blob.DeleteOptions{ - DeleteSnapshots: &[]blob.DeleteSnapshotsOptionType{blob.DeleteSnapshotsOptionTypeInclude}[0], + DeleteSnapshots: to.Ptr(blob.DeleteSnapshotsOptionTypeInclude), }) if err != nil { return fmt.Errorf("azure delete %s/%s: %v", g.container, key, err)