From 9be8aebffffc2cfb377ddffc8960714c8e649995 Mon Sep 17 00:00:00 2001 From: Anis Elleuch Date: Mon, 11 Jul 2016 00:36:16 +0100 Subject: [PATCH] Avoid creating session when cp detects object exists as directory (#1758) --- client-errors.go | 9 +++++++++ client-s3.go | 5 +++++ cp-main.go | 2 +- 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/client-errors.go b/client-errors.go index 6578233e..66ea6cac 100644 --- a/client-errors.go +++ b/client-errors.go @@ -74,6 +74,15 @@ func (e ObjectAlreadyExists) Error() string { return "Object ‘" + e.Object + "’ already exists." } +// ObjectAlreadyExistsAsDirectory - typed return for XMinioObjectExistsAsDirectory +type ObjectAlreadyExistsAsDirectory struct { + Object string +} + +func (e ObjectAlreadyExistsAsDirectory) Error() string { + return "Object ‘" + e.Object + "’ already exists as directory." +} + // ObjectOnGlacier - object is of storage class glacier. type ObjectOnGlacier struct { Object string diff --git a/client-s3.go b/client-s3.go index 745a4648..c8c8ffac 100644 --- a/client-s3.go +++ b/client-s3.go @@ -236,6 +236,11 @@ func (c *s3Client) Put(reader io.Reader, size int64, contentType string, progres Object: object, }) } + if errResponse.Code == "XMinioObjectExistsAsDirectory" { + return n, probe.NewError(ObjectAlreadyExistsAsDirectory{ + Object: object, + }) + } if errResponse.Code == "NoSuchBucket" { return n, probe.NewError(BucketDoesNotExist{ Bucket: bucket, diff --git a/cp-main.go b/cp-main.go index f4eff96c..c919c8fd 100644 --- a/cp-main.go +++ b/cp-main.go @@ -352,7 +352,7 @@ func doCopySession(session *sessionV7) { case BrokenSymlink, TooManyLevelsSymlink, PathNotFound, PathInsufficientPermission: continue // Handle these specifically for object storage related errors. - case BucketNameEmpty, ObjectMissing, ObjectAlreadyExists, BucketDoesNotExist, BucketInvalid, ObjectOnGlacier: + case BucketNameEmpty, ObjectMissing, ObjectAlreadyExists, ObjectAlreadyExistsAsDirectory, BucketDoesNotExist, BucketInvalid, ObjectOnGlacier: continue } // For critical errors we should exit. Session