Skip to content

Commit 2a587d2

Browse files
committed
azurefiles: fix hash getting erased when modtime is set
Before this change, setting an object's modtime with o.SetModTime() (without updating the file's content) would inadvertently erase its md5 hash. The documentation notes: "If this property isn't specified on the request, the property is cleared for the file. Subsequent calls to Get File Properties won't return this property, unless it's explicitly set on the file again." https://learn.microsoft.com/en-us/rest/api/storageservices/set-file-properties#common-request-headers This change fixes the issue by setting ContentMD5 (and ContentType), to the extent we have it, during SetModTime. Discovered on bisync integration tests such as TestBisyncRemoteRemote/resolve
1 parent 4b0df05 commit 2a587d2

2 files changed

Lines changed: 7 additions & 6 deletions

File tree

backend/azurefiles/azurefiles.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ func newFsFromOptions(ctx context.Context, name, root string, opt *Options) (fs.
453453
return nil, fmt.Errorf("create new shared key credential failed: %w", err)
454454
}
455455
case opt.UseAZ:
456-
var options = azidentity.AzureCLICredentialOptions{}
456+
options := azidentity.AzureCLICredentialOptions{}
457457
cred, err = azidentity.NewAzureCLICredential(&options)
458458
fmt.Println(cred)
459459
if err != nil {
@@ -550,7 +550,7 @@ func newFsFromOptions(ctx context.Context, name, root string, opt *Options) (fs.
550550
case opt.UseMSI:
551551
// Specifying a user-assigned identity. Exactly one of the above IDs must be specified.
552552
// Validate and ensure exactly one is set. (To do: better validation.)
553-
var b2i = map[bool]int{false: 0, true: 1}
553+
b2i := map[bool]int{false: 0, true: 1}
554554
set := b2i[opt.MSIClientID != ""] + b2i[opt.MSIObjectID != ""] + b2i[opt.MSIResourceID != ""]
555555
if set > 1 {
556556
return nil, errors.New("more than one user-assigned identity ID is set")
@@ -583,7 +583,6 @@ func newFsFromOptions(ctx context.Context, name, root string, opt *Options) (fs.
583583
token, err := msiCred.GetToken(context.Background(), policy.TokenRequestOptions{
584584
Scopes: []string{"api://AzureADTokenExchange"},
585585
})
586-
587586
if err != nil {
588587
return "", fmt.Errorf("failed to acquire MSI token: %w", err)
589588
}
@@ -855,7 +854,7 @@ func (f *Fs) List(ctx context.Context, dir string) (fs.DirEntries, error) {
855854
return entries, err
856855
}
857856

858-
var opt = &directory.ListFilesAndDirectoriesOptions{
857+
opt := &directory.ListFilesAndDirectoriesOptions{
859858
Include: directory.ListFilesInclude{
860859
Timestamps: true,
861860
},
@@ -1014,6 +1013,10 @@ func (o *Object) SetModTime(ctx context.Context, t time.Time) error {
10141013
SMBProperties: &file.SMBProperties{
10151014
LastWriteTime: &t,
10161015
},
1016+
HTTPHeaders: &file.HTTPHeaders{
1017+
ContentMD5: o.md5,
1018+
ContentType: &o.contentType,
1019+
},
10171020
}
10181021
_, err := o.fileClient().SetHTTPHeaders(ctx, &opt)
10191022
if err != nil {

fstest/test_all/config.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -429,8 +429,6 @@ backends:
429429
- TestMultithreadCopyAbort
430430
- backend: "azurefiles"
431431
remote: "TestAzureFiles:"
432-
ignoretests:
433-
- cmd/bisync
434432
- backend: "pcloud"
435433
remote: "TestPcloud:"
436434
fastlist: true

0 commit comments

Comments
 (0)