mirror of
https://github.com/rclone/rclone.git
synced 2025-04-24 13:14:13 +08:00
Merge 6a97276c0d5becfa7f11c0ca744ac8f4f4933d87 into 431386085f193a321724e3a0eabb0584f70e6c88
This commit is contained in:
commit
9690edf38a
@ -19,6 +19,7 @@ import (
|
||||
"net/url"
|
||||
"os"
|
||||
"path"
|
||||
"regexp"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
@ -1115,6 +1116,37 @@ func (o *Object) updateMetadataWithModTime(modTime time.Time) {
|
||||
o.meta[modTimeKey] = modTime.Format(timeFormatOut)
|
||||
}
|
||||
|
||||
// update meta data
|
||||
func (o *Object) updateMetadata(ctx context.Context, src fs.ObjectInfo, options []fs.OpenOption) (ui uploadInfo, err error) {
|
||||
metadataMu.Lock()
|
||||
defer metadataMu.Unlock()
|
||||
|
||||
// Make sure o.meta is not nil
|
||||
if o.meta == nil {
|
||||
o.meta = make(map[string]string, 1)
|
||||
}
|
||||
|
||||
meta, err := fs.GetMetadataOptions(ctx, o.fs, src, options)
|
||||
if err != nil {
|
||||
return ui, fmt.Errorf("failed to read metadata from source object: %w", err)
|
||||
}
|
||||
|
||||
for k, v := range meta {
|
||||
// Azure does not allow special characters in key, so we replace all of them by empty string
|
||||
var fixedKey = RemoveUnwantedChars(k, "a-zA-Z0-9")
|
||||
o.meta[fixedKey] = v
|
||||
}
|
||||
|
||||
return ui, nil
|
||||
}
|
||||
|
||||
// Remove unwanted characters
|
||||
func RemoveUnwantedChars(input string, allowedChars string) string {
|
||||
pattern := fmt.Sprintf("[^%s]", allowedChars)
|
||||
re := regexp.MustCompile(pattern)
|
||||
return re.ReplaceAllString(input, "")
|
||||
}
|
||||
|
||||
// Returns whether file is a directory marker or not
|
||||
func isDirectoryMarker(size int64, metadata map[string]*string, remote string) bool {
|
||||
// Directory markers are 0 length
|
||||
@ -2871,6 +2903,12 @@ func (o *Object) prepareUpload(ctx context.Context, src fs.ObjectInfo, options [
|
||||
return ui, err
|
||||
}
|
||||
|
||||
// Update other metadata
|
||||
ui, err = o.updateMetadata(ctx, src, options)
|
||||
if err != nil {
|
||||
return ui, err
|
||||
}
|
||||
|
||||
// Create the HTTP headers for the upload
|
||||
ui.httpHeaders = blob.HTTPHeaders{
|
||||
BlobContentType: pString(fs.MimeType(ctx, src)),
|
||||
|
Loading…
x
Reference in New Issue
Block a user