mirror of
https://github.com/rclone/rclone.git
synced 2025-08-10 06:09:44 +02:00
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
This commit is contained in:
@@ -453,7 +453,7 @@ func newFsFromOptions(ctx context.Context, name, root string, opt *Options) (fs.
|
|||||||
return nil, fmt.Errorf("create new shared key credential failed: %w", err)
|
return nil, fmt.Errorf("create new shared key credential failed: %w", err)
|
||||||
}
|
}
|
||||||
case opt.UseAZ:
|
case opt.UseAZ:
|
||||||
var options = azidentity.AzureCLICredentialOptions{}
|
options := azidentity.AzureCLICredentialOptions{}
|
||||||
cred, err = azidentity.NewAzureCLICredential(&options)
|
cred, err = azidentity.NewAzureCLICredential(&options)
|
||||||
fmt.Println(cred)
|
fmt.Println(cred)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -550,7 +550,7 @@ func newFsFromOptions(ctx context.Context, name, root string, opt *Options) (fs.
|
|||||||
case opt.UseMSI:
|
case opt.UseMSI:
|
||||||
// Specifying a user-assigned identity. Exactly one of the above IDs must be specified.
|
// Specifying a user-assigned identity. Exactly one of the above IDs must be specified.
|
||||||
// Validate and ensure exactly one is set. (To do: better validation.)
|
// Validate and ensure exactly one is set. (To do: better validation.)
|
||||||
var b2i = map[bool]int{false: 0, true: 1}
|
b2i := map[bool]int{false: 0, true: 1}
|
||||||
set := b2i[opt.MSIClientID != ""] + b2i[opt.MSIObjectID != ""] + b2i[opt.MSIResourceID != ""]
|
set := b2i[opt.MSIClientID != ""] + b2i[opt.MSIObjectID != ""] + b2i[opt.MSIResourceID != ""]
|
||||||
if set > 1 {
|
if set > 1 {
|
||||||
return nil, errors.New("more than one user-assigned identity ID is set")
|
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.
|
|||||||
token, err := msiCred.GetToken(context.Background(), policy.TokenRequestOptions{
|
token, err := msiCred.GetToken(context.Background(), policy.TokenRequestOptions{
|
||||||
Scopes: []string{"api://AzureADTokenExchange"},
|
Scopes: []string{"api://AzureADTokenExchange"},
|
||||||
})
|
})
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", fmt.Errorf("failed to acquire MSI token: %w", err)
|
return "", fmt.Errorf("failed to acquire MSI token: %w", err)
|
||||||
}
|
}
|
||||||
@@ -855,7 +854,7 @@ func (f *Fs) List(ctx context.Context, dir string) (fs.DirEntries, error) {
|
|||||||
return entries, err
|
return entries, err
|
||||||
}
|
}
|
||||||
|
|
||||||
var opt = &directory.ListFilesAndDirectoriesOptions{
|
opt := &directory.ListFilesAndDirectoriesOptions{
|
||||||
Include: directory.ListFilesInclude{
|
Include: directory.ListFilesInclude{
|
||||||
Timestamps: true,
|
Timestamps: true,
|
||||||
},
|
},
|
||||||
@@ -1014,6 +1013,10 @@ func (o *Object) SetModTime(ctx context.Context, t time.Time) error {
|
|||||||
SMBProperties: &file.SMBProperties{
|
SMBProperties: &file.SMBProperties{
|
||||||
LastWriteTime: &t,
|
LastWriteTime: &t,
|
||||||
},
|
},
|
||||||
|
HTTPHeaders: &file.HTTPHeaders{
|
||||||
|
ContentMD5: o.md5,
|
||||||
|
ContentType: &o.contentType,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
_, err := o.fileClient().SetHTTPHeaders(ctx, &opt)
|
_, err := o.fileClient().SetHTTPHeaders(ctx, &opt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@@ -429,8 +429,6 @@ backends:
|
|||||||
- TestMultithreadCopyAbort
|
- TestMultithreadCopyAbort
|
||||||
- backend: "azurefiles"
|
- backend: "azurefiles"
|
||||||
remote: "TestAzureFiles:"
|
remote: "TestAzureFiles:"
|
||||||
ignoretests:
|
|
||||||
- cmd/bisync
|
|
||||||
- backend: "pcloud"
|
- backend: "pcloud"
|
||||||
remote: "TestPcloud:"
|
remote: "TestPcloud:"
|
||||||
fastlist: true
|
fastlist: true
|
||||||
|
Reference in New Issue
Block a user