Skip to content

Commit 3a3468a

Browse files
committed
improve
1 parent 3b49d30 commit 3a3468a

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

modules/storage/azureblob.go

+8-3
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ func (a *AzureBlobStorage) getObjectNameFromPath(path string) string {
173173

174174
// Open opens a file
175175
func (a *AzureBlobStorage) Open(path string) (Object, error) {
176-
blobClient := a.client.ServiceClient().NewContainerClient(a.container).NewBlobClient(a.buildAzureBlobPath(path))
176+
blobClient := a.getBlobClient(path)
177177
res, err := blobClient.GetProperties(a.ctx, &blob.GetPropertiesOptions{})
178178
if err != nil {
179179
return nil, convertAzureBlobErr(err)
@@ -234,7 +234,7 @@ func (a azureBlobFileInfo) Sys() interface{} {
234234

235235
// Stat returns the stat information of the object
236236
func (a *AzureBlobStorage) Stat(path string) (os.FileInfo, error) {
237-
blobClient := a.client.ServiceClient().NewContainerClient(a.container).NewBlobClient(a.buildAzureBlobPath(path))
237+
blobClient := a.getBlobClient(path)
238238
res, err := blobClient.GetProperties(a.ctx, &blob.GetPropertiesOptions{})
239239
if err != nil {
240240
return nil, convertAzureBlobErr(err)
@@ -249,7 +249,7 @@ func (a *AzureBlobStorage) Stat(path string) (os.FileInfo, error) {
249249

250250
// Delete delete a file
251251
func (a *AzureBlobStorage) Delete(path string) error {
252-
blobClient := a.client.ServiceClient().NewContainerClient(a.container).NewBlobClient(a.buildAzureBlobPath(path))
252+
blobClient := a.getBlobClient(path)
253253
_, err := blobClient.Delete(a.ctx, &blob.DeleteOptions{})
254254
return convertAzureBlobErr(err)
255255
}
@@ -302,6 +302,11 @@ func (a *AzureBlobStorage) IterateObjects(dirName string, fn func(path string, o
302302
return nil
303303
}
304304

305+
// Delete delete a file
306+
func (a *AzureBlobStorage) getBlobClient(path string) *blob.Client {
307+
return a.client.ServiceClient().NewContainerClient(a.container).NewBlobClient(a.buildAzureBlobPath(path))
308+
}
309+
305310
func init() {
306311
RegisterStorageType(setting.AzureBlobStorageType, NewAzureBlobStorage)
307312
}

0 commit comments

Comments
 (0)