Skip to content

Commit

Permalink
Merge pull request #498 from ycombinator/pr490-tweaks
Browse files Browse the repository at this point in the history
Tweaks to PR 490
  • Loading branch information
Jamie Hannaford committed Dec 9, 2014
2 parents 0888361 + 01f9173 commit 5228802
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions lib/OpenCloud/ObjectStore/Resource/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}

Expand Down

0 comments on commit 5228802

Please sign in to comment.