1
0
mirror of https://github.com/minio/mc.git synced 2025-11-10 13:42:32 +03:00

cp: Fix url check not considering version-id in some cases (#3401)

cp checks the existance of the source object in Type A and Type B, but
forgets to pass version-id as well. Fix this behavior.
This commit is contained in:
Anis Elleuch
2020-09-08 15:08:35 +01:00
committed by GitHub
parent af6cff00a5
commit 8f2ffbfa86

View File

@@ -92,9 +92,17 @@ func checkCopySyntax(ctx context.Context, cliCtx *cli.Context, encKeyDB map[stri
switch copyURLsType { switch copyURLsType {
case copyURLsTypeA: // File -> File. case copyURLsTypeA: // File -> File.
checkCopySyntaxTypeA(ctx, srcURLs, tgtURL, encKeyDB, isMvCmd, timeRef) // Check source.
if len(srcURLs) != 1 {
fatalIf(errInvalidArgument().Trace(), "Invalid number of source arguments.")
}
checkCopySyntaxTypeA(ctx, srcURLs[0], versionID, tgtURL, encKeyDB, isMvCmd, timeRef)
case copyURLsTypeB: // File -> Folder. case copyURLsTypeB: // File -> Folder.
checkCopySyntaxTypeB(ctx, srcURLs, tgtURL, encKeyDB, isMvCmd, timeRef) // Check source.
if len(srcURLs) != 1 {
fatalIf(errInvalidArgument().Trace(), "Invalid number of source arguments.")
}
checkCopySyntaxTypeB(ctx, srcURLs[0], versionID, tgtURL, encKeyDB, isMvCmd, timeRef)
case copyURLsTypeC: // Folder... -> Folder. case copyURLsTypeC: // Folder... -> Folder.
checkCopySyntaxTypeC(ctx, srcURLs, tgtURL, isRecursive, encKeyDB, isMvCmd, timeRef) checkCopySyntaxTypeC(ctx, srcURLs, tgtURL, isRecursive, encKeyDB, isMvCmd, timeRef)
case copyURLsTypeD: // File1...FileN -> Folder. case copyURLsTypeD: // File1...FileN -> Folder.
@@ -110,13 +118,8 @@ func checkCopySyntax(ctx context.Context, cliCtx *cli.Context, encKeyDB map[stri
} }
// checkCopySyntaxTypeA verifies if the source and target are valid file arguments. // checkCopySyntaxTypeA verifies if the source and target are valid file arguments.
func checkCopySyntaxTypeA(ctx context.Context, srcURLs []string, tgtURL string, keys map[string][]prefixSSEPair, isMvCmd bool, timeRef time.Time) { func checkCopySyntaxTypeA(ctx context.Context, srcURL, versionID string, tgtURL string, keys map[string][]prefixSSEPair, isMvCmd bool, timeRef time.Time) {
// Check source. _, srcContent, err := url2Stat(ctx, srcURL, versionID, false, keys, timeRef)
if len(srcURLs) != 1 {
fatalIf(errInvalidArgument().Trace(), "Invalid number of source arguments.")
}
srcURL := srcURLs[0]
_, srcContent, err := url2Stat(ctx, srcURL, "", false, keys, timeRef)
fatalIf(err.Trace(srcURL), "Unable to stat source `"+srcURL+"`.") fatalIf(err.Trace(srcURL), "Unable to stat source `"+srcURL+"`.")
if !srcContent.Type.IsRegular() { if !srcContent.Type.IsRegular() {
@@ -125,13 +128,8 @@ func checkCopySyntaxTypeA(ctx context.Context, srcURLs []string, tgtURL string,
} }
// checkCopySyntaxTypeB verifies if the source is a valid file and target is a valid folder. // checkCopySyntaxTypeB verifies if the source is a valid file and target is a valid folder.
func checkCopySyntaxTypeB(ctx context.Context, srcURLs []string, tgtURL string, keys map[string][]prefixSSEPair, isMvCmd bool, timeRef time.Time) { func checkCopySyntaxTypeB(ctx context.Context, srcURL, versionID string, tgtURL string, keys map[string][]prefixSSEPair, isMvCmd bool, timeRef time.Time) {
// Check source. _, srcContent, err := url2Stat(ctx, srcURL, versionID, false, keys, timeRef)
if len(srcURLs) != 1 {
fatalIf(errInvalidArgument().Trace(), "Invalid number of source arguments.")
}
srcURL := srcURLs[0]
_, srcContent, err := url2Stat(ctx, srcURL, "", false, keys, timeRef)
fatalIf(err.Trace(srcURL), "Unable to stat source `"+srcURL+"`.") fatalIf(err.Trace(srcURL), "Unable to stat source `"+srcURL+"`.")
if !srcContent.Type.IsRegular() { if !srcContent.Type.IsRegular() {