fix: cp preserve ownership issue (#3202)

This commit is contained in:
ebozduman
2020-05-07 09:00:48 -07:00
committed by GitHub
parent 4e3b501528
commit a75dca16bd
2 changed files with 8 additions and 7 deletions
+6 -5
View File
@@ -51,6 +51,7 @@ type fsClient struct {
const (
partSuffix = ".part.minio"
slashSeperator = "/"
metaDataKey = "X-Amz-Meta-Mc-Attrs"
)
var ( // GOOS specific ignore list.
@@ -302,8 +303,8 @@ func (f *fsClient) put(reader io.Reader, size int64, metadata map[string][]strin
}
attr := make(map[string]string)
if len(metadata["mc-attrs"]) != 0 {
attr, e = parseAttribute(metadata["mc-attrs"][0])
if len(metadata[metaDataKey]) != 0 {
attr, e = parseAttribute(metadata[metaDataKey][0])
if e != nil {
return 0, probe.NewError(e)
}
@@ -409,9 +410,9 @@ func (f *fsClient) put(reader io.Reader, size int64, metadata map[string][]strin
// Put - create a new file with metadata.
func (f *fsClient) Put(ctx context.Context, reader io.Reader, size int64, metadata map[string]string, progress io.Reader, sse encrypt.ServerSide, md5, disableMultipart bool) (int64, *probe.Error) {
if metadata["mc-attrs"] != "" {
if metadata[metaDataKey] != "" {
meta := make(map[string][]string)
meta["mc-attrs"] = append(meta["mc-attrs"], metadata["mc-attrs"])
meta[metaDataKey] = append(meta[metaDataKey], metadata[metaDataKey])
return f.put(reader, size, meta, progress)
}
return f.put(reader, size, nil, progress)
@@ -1057,7 +1058,7 @@ func (f *fsClient) Stat(isIncomplete, isPreserve bool, sse encrypt.ServerSide) (
if err != nil {
return content, nil
}
content.Metadata["mc-attrs"] = fileAttr
content.Metadata[metaDataKey] = fileAttr
}
return content, nil
+2 -2
View File
@@ -678,12 +678,12 @@ function test_cat_object_with_sse_error()
log_success "$start_time" "${FUNCNAME[0]}"
}
# Test mc cp command with preserve file system attributes
# Test "mc cp -a" command to see if it preserves file system attributes
function test_copy_object_preserve_filesystem_attr()
{
show "${FUNCNAME[0]}"
assert_success "$start_time" "${FUNCNAME[0]}" mc_cmd cp -a "${FILE_1_MB}" "${SERVER_ALIAS}/${BUCKET_NAME}/${object_name}"
diff -bB <("${MC_CMD[@]}" --json stat "${FILE_1_MB}" | jq -r '.metadata."mc-attrs"') >/dev/null 2>&1 <("${MC_CMD[@]}" --json stat "${SERVER_ALIAS}/${BUCKET_NAME}/${object_name}" | jq -r '.metadata."X-Amz-Meta-Mc-Attrs"') >/dev/null 2>&1
diff -bB <("${MC_CMD[@]}" --json stat "${FILE_1_MB}" | jq -r '.metadata."X-Amz-Meta-Mc-Attrs"') >/dev/null 2>&1 <("${MC_CMD[@]}" --json stat "${SERVER_ALIAS}/${BUCKET_NAME}/${object_name}" | jq -r '.metadata."X-Amz-Meta-Mc-Attrs"') >/dev/null 2>&1
assert_success "$start_time" "${FUNCNAME[0]}" show_on_failure $? "unable to put object with file system attribute"
assert_success "$start_time" "${FUNCNAME[0]}" mc_cmd rm "${SERVER_ALIAS}/${BUCKET_NAME}/${object_name}"
log_success "$start_time" "${FUNCNAME[0]}"