Skip to content

Commit

Permalink
Fix ignoring of S3 Glacier type errors bug (Azure#2834)
Browse files Browse the repository at this point in the history
  • Loading branch information
momodedev committed Oct 29, 2024
1 parent aaf35cf commit 4db688e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
27 changes: 27 additions & 0 deletions cmd/zc_traverser_s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,28 @@ func (t *s3Traverser) Traverse(preprocessor objectMorpher, processor objectProce
return strings.HasSuffix(objectKey, ".") ||
strings.Contains(objectKey, "./")
}

const (
storageClassKey = "X-Amz-Storage-Class"
deepArchiveClass = "DEEP_ARCHIVE"
)

invalidAwsStorageClass := func(minioObject minio.ObjectInfo) bool {
/* S3 object's storage class "DEEP_ARCHIVE" is invalid.
Because S3 Glacier Archive objects cannot be copied to Azure Storage.
*/
storageClasses, ok := minioObject.Metadata[storageClassKey]
if !ok || len(storageClasses) == 0 {
return false
}

storageClass := storageClasses[0]

return storageClass == deepArchiveClass
}

invalidNameErrorMsg := "Skipping S3 object %s, as it is not a valid Blob name. Rename the object and retry the transfer"
invalidAwsStorageClassMsg := "Skipping S3 object %s, as it is not a valid AWS storage class: %s"
// Check if resource is a single object.
if t.s3URLParts.IsObjectSyntactically() && !t.s3URLParts.IsDirectorySyntactically() && !t.s3URLParts.IsBucketSyntactically() {
objectPath := strings.Split(t.s3URLParts.ObjectKey, "/")
Expand All @@ -84,6 +105,12 @@ func (t *s3Traverser) Traverse(preprocessor objectMorpher, processor objectProce
return common.EAzError.InvalidBlobName()
}

if invalidAwsStorageClass(oi) {

WarnStdoutAndScanningLog(fmt.Sprintf(invalidAwsStorageClassMsg, t.s3URLParts.ObjectKey, deepArchiveClass))
return common.EAzError.InvalidAWSStorageClass()
}

// If we actually got object properties, process them.
// Otherwise, treat it as a directory.
// According to IsDirectorySyntactically, objects and folders can share names
Expand Down
5 changes: 4 additions & 1 deletion common/azError.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ func (err AzError) Error() string {

var EAzError AzError

func (err AzError) InvalidAWSStorageClass() AzError {
return AzError{uint64(2), "Invalid AWS Storage Class: ", "DEEP_ARCHIVE"}
}
func (err AzError) LoginCredMissing() AzError {
return AzError{uint64(1), "Login Credentials missing. ", ""}
}
Expand All @@ -67,4 +70,4 @@ func (err AzError) InvalidServiceClient() AzError {

func ErrInvalidClient(msg string) AzError {
return NewAzError(EAzError.InvalidServiceClient(), fmt.Sprintf("Expecting %s client", msg))
}
}

0 comments on commit 4db688e

Please sign in to comment.