From c00d933355ac99754a0492e124e7fa49b4539e46 Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Tue, 9 Dec 2014 19:12:15 +0530 Subject: [PATCH 1/3] Checking for the latest object count, not a possibly stale one. --- lib/OpenCloud/ObjectStore/Resource/Container.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/OpenCloud/ObjectStore/Resource/Container.php b/lib/OpenCloud/ObjectStore/Resource/Container.php index 112141202..b5558d20f 100644 --- a/lib/OpenCloud/ObjectStore/Resource/Container.php +++ b/lib/OpenCloud/ObjectStore/Resource/Container.php @@ -180,8 +180,8 @@ public function delete($deleteObjects = false) public function deleteWithObjects($secondsToWait = null) { // If container is empty, just delete it - $numObjects = $this->getObjectCount(); - if ($numObjects === 0) { + $numObjects = (int) $this->retrieveMetadata()->getProperty('Object-Count'); + if (0 === $numObjects) { return $this->delete(); } // If timeout ($secondsToWait) is not specified by caller, From 418f343dda9025978b199f434bfde033056bd0c0 Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Tue, 9 Dec 2014 19:16:14 +0530 Subject: [PATCH 2/3] Whitespace fixes to appease the linter and my OCD. --- lib/OpenCloud/ObjectStore/Resource/Container.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/OpenCloud/ObjectStore/Resource/Container.php b/lib/OpenCloud/ObjectStore/Resource/Container.php index b5558d20f..56702a913 100644 --- a/lib/OpenCloud/ObjectStore/Resource/Container.php +++ b/lib/OpenCloud/ObjectStore/Resource/Container.php @@ -184,11 +184,13 @@ public function deleteWithObjects($secondsToWait = null) if (0 === $numObjects) { return $this->delete(); } + // If timeout ($secondsToWait) is not specified by caller, // try to estimate it based on number of objects in container if (null === $secondsToWait) { $secondsToWait = round($numObjects / 2); - } + } + // Attempt to delete all objects and container $endTime = time() + $secondsToWait; $containerDeleted = false; @@ -208,9 +210,11 @@ public function deleteWithObjects($secondsToWait = null) } } } + if (!$containerDeleted) { throw new ContainerException('Container could not be deleted.'); } + return $response; } From 01f91734faa9515e98d76ebbd9f65960bd57c380 Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Tue, 9 Dec 2014 19:16:41 +0530 Subject: [PATCH 3/3] Fixing exception message. --- lib/OpenCloud/ObjectStore/Resource/Container.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/OpenCloud/ObjectStore/Resource/Container.php b/lib/OpenCloud/ObjectStore/Resource/Container.php index 56702a913..bc7951c15 100644 --- a/lib/OpenCloud/ObjectStore/Resource/Container.php +++ b/lib/OpenCloud/ObjectStore/Resource/Container.php @@ -212,7 +212,7 @@ public function deleteWithObjects($secondsToWait = null) } if (!$containerDeleted) { - throw new ContainerException('Container could not be deleted.'); + throw new ContainerException('Container and all its objects could not be deleted.'); } return $response;