mirror of https://github.com/rclone/rclone.git
fix code
This commit is contained in:
parent
cdfd748241
commit
90289401fa
|
@ -19,6 +19,7 @@ import (
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
|
"regexp"
|
||||||
"sort"
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -1099,6 +1100,37 @@ func (o *Object) updateMetadataWithModTime(modTime time.Time) {
|
||||||
o.meta[modTimeKey] = modTime.Format(timeFormatOut)
|
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
|
// Returns whether file is a directory marker or not
|
||||||
func isDirectoryMarker(size int64, metadata map[string]*string, remote string) bool {
|
func isDirectoryMarker(size int64, metadata map[string]*string, remote string) bool {
|
||||||
// Directory markers are 0 length
|
// Directory markers are 0 length
|
||||||
|
@ -2851,6 +2883,12 @@ func (o *Object) prepareUpload(ctx context.Context, src fs.ObjectInfo, options [
|
||||||
return ui, err
|
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
|
// Create the HTTP headers for the upload
|
||||||
ui.httpHeaders = blob.HTTPHeaders{
|
ui.httpHeaders = blob.HTTPHeaders{
|
||||||
BlobContentType: pString(fs.MimeType(ctx, src)),
|
BlobContentType: pString(fs.MimeType(ctx, src)),
|
||||||
|
|
Loading…
Reference in New Issue