Merge 6a97276c0d5becfa7f11c0ca744ac8f4f4933d87 into 431386085f193a321724e3a0eabb0584f70e6c88

This commit is contained in:
Phuong Pham 2025-02-27 01:18:01 +05:30 committed by GitHub
commit 9690edf38a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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)),