diff --git a/lib/OpenCloud/ObjectStore/Resource/Container.php b/lib/OpenCloud/ObjectStore/Resource/Container.php index 112141202..bc7951c15 100644 --- a/lib/OpenCloud/ObjectStore/Resource/Container.php +++ b/lib/OpenCloud/ObjectStore/Resource/Container.php @@ -180,15 +180,17 @@ 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, // 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.'); + throw new ContainerException('Container and all its objects could not be deleted.'); } + return $response; }