From 2d431dacbc6dc7e13bfe8f428402a42c4fd28e40 Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Thu, 23 Jun 2016 00:28:17 -0700 Subject: [PATCH] ls/cp/mirror: Ignore objects with StorageClass GLACIER. (#1742) Fixes #1741 --- client-errors.go | 9 +++++++++ client-s3.go | 20 ++++++++++++++++++++ cp-main.go | 3 ++- difference.go | 6 ++++++ ls-main.go | 2 +- ls.go | 3 +++ mirror-main.go | 3 ++- 7 files changed, 43 insertions(+), 3 deletions(-) diff --git a/client-errors.go b/client-errors.go index 81f25de0..6578233e 100644 --- a/client-errors.go +++ b/client-errors.go @@ -74,6 +74,15 @@ func (e ObjectAlreadyExists) Error() string { return "Object ‘" + e.Object + "’ already exists." } +// ObjectOnGlacier - object is of storage class glacier. +type ObjectOnGlacier struct { + Object string +} + +func (e ObjectOnGlacier) Error() string { + return "Object ‘" + e.Object + "’ is on Glacier storage." +} + // BucketNameTopLevel - generic error type BucketNameTopLevel struct{} diff --git a/client-s3.go b/client-s3.go index 4e72ddc8..745a4648 100644 --- a/client-s3.go +++ b/client-s3.go @@ -678,6 +678,19 @@ func (c *s3Client) listInRoutine(contentCh chan *clientContent) { } } +// S3 offers a range of storage classes designed for +// different use cases, following list captures these. +const ( + // General purpose. + // s3StorageClassStandard = "STANDARD" + // Infrequent access. + // s3StorageClassInfrequent = "STANDARD_IA" + // Reduced redundancy access. + // s3StorageClassRedundancy = "REDUCED_REDUNDANCY" + // Archive access. + s3StorageClassGlacier = "GLACIER" +) + func (c *s3Client) listRecursiveInRoutine(contentCh chan *clientContent) { defer close(contentCh) // get bucket and object from URL. @@ -701,6 +714,13 @@ func (c *s3Client) listRecursiveInRoutine(contentCh chan *clientContent) { } isRecursive := true for object := range c.api.ListObjects(bucket.Name, o, isRecursive, nil) { + // Return error if we encountered glacier object and continue. + if object.StorageClass == s3StorageClassGlacier { + contentCh <- &clientContent{ + Err: probe.NewError(ObjectOnGlacier{object.Key}), + } + continue + } if object.Err != nil { contentCh <- &clientContent{ Err: probe.NewError(object.Err), diff --git a/cp-main.go b/cp-main.go index cf867c14..f4eff96c 100644 --- a/cp-main.go +++ b/cp-main.go @@ -351,7 +351,8 @@ func doCopySession(session *sessionV7) { // Handle this specifically for filesystem related errors. case BrokenSymlink, TooManyLevelsSymlink, PathNotFound, PathInsufficientPermission: continue - case BucketNameEmpty, ObjectMissing, ObjectAlreadyExists, BucketDoesNotExist, BucketInvalid: + // Handle these specifically for object storage related errors. + case BucketNameEmpty, ObjectMissing, ObjectAlreadyExists, BucketDoesNotExist, BucketInvalid, ObjectOnGlacier: continue } // For critical errors we should exit. Session diff --git a/difference.go b/difference.go index a1c6e3ea..132afbe8 100644 --- a/difference.go +++ b/difference.go @@ -86,6 +86,9 @@ func objectDifference(sourceClnt, targetClnt Client, sourceURL, targetURL string // Handle this specifically for filesystem related errors. case BrokenSymlink, TooManyLevelsSymlink, PathNotFound, PathInsufficientPermission: errorIf(srcCtnt.Err.Trace(sourceURL, targetURL), fmt.Sprintf("Failed on '%s'", sourceURL)) + // Handle these specifically for object storage related errors. + case BucketNameEmpty, ObjectMissing, ObjectAlreadyExists, BucketDoesNotExist, BucketInvalid, ObjectOnGlacier: + errorIf(srcCtnt.Err.Trace(sourceURL, targetURL), fmt.Sprintf("Failed on '%s'", sourceURL)) default: fatalIf(srcCtnt.Err.Trace(sourceURL, targetURL), fmt.Sprintf("Failed on '%s'", sourceURL)) } @@ -98,6 +101,9 @@ func objectDifference(sourceClnt, targetClnt Client, sourceURL, targetURL string // Handle this specifically for filesystem related errors. case BrokenSymlink, TooManyLevelsSymlink, PathNotFound, PathInsufficientPermission: errorIf(tgtCtnt.Err.Trace(sourceURL, targetURL), fmt.Sprintf("Failed on '%s'", targetURL)) + // Handle these specifically for object storage related errors. + case BucketNameEmpty, ObjectMissing, ObjectAlreadyExists, BucketDoesNotExist, BucketInvalid, ObjectOnGlacier: + errorIf(tgtCtnt.Err.Trace(sourceURL, targetURL), fmt.Sprintf("Failed on '%s'", targetURL)) default: fatalIf(tgtCtnt.Err.Trace(sourceURL, targetURL), fmt.Sprintf("Failed on '%s'", targetURL)) } diff --git a/ls-main.go b/ls-main.go index c31544ac..dd719662 100644 --- a/ls-main.go +++ b/ls-main.go @@ -37,7 +37,7 @@ var ( }, cli.BoolFlag{ Name: "incomplete, I", - Usage: "Remove incomplete uploads.", + Usage: "List incomplete uploads.", }, } ) diff --git a/ls.go b/ls.go index 33f607c6..fe109899 100644 --- a/ls.go +++ b/ls.go @@ -126,6 +126,9 @@ func doList(clnt Client, isRecursive, isIncomplete bool) *probe.Error { case PathInsufficientPermission: errorIf(content.Err.Trace(clnt.GetURL().String()), "Unable to list folder.") continue + case ObjectOnGlacier: + errorIf(content.Err.Trace(clnt.GetURL().String()), "") + continue } errorIf(content.Err.Trace(clnt.GetURL().String()), "Unable to list folder.") continue diff --git a/mirror-main.go b/mirror-main.go index 6b382838..6a653683 100644 --- a/mirror-main.go +++ b/mirror-main.go @@ -408,7 +408,8 @@ func doMirrorSession(session *sessionV7) { // Handle this specifically for filesystem related errors. case BrokenSymlink, TooManyLevelsSymlink, PathNotFound, PathInsufficientPermission: continue - case BucketNameEmpty, ObjectMissing, ObjectAlreadyExists, BucketDoesNotExist, BucketInvalid: + // Handle this specifically for object storage related errors. + case BucketNameEmpty, ObjectMissing, ObjectAlreadyExists, BucketDoesNotExist, BucketInvalid, ObjectOnGlacier: continue } // For critical errors we should exit. Session