Skip to content

Commit 0888361

Browse files
committed
Merge pull request #490 from joshrencher/patch-1
make deleteWithObjects() work with empty containers
2 parents 6069cb6 + 0bb1e63 commit 0888361

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

lib/OpenCloud/ObjectStore/Resource/Container.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -179,13 +179,16 @@ public function delete($deleteObjects = false)
179179

180180
public function deleteWithObjects($secondsToWait = null)
181181
{
182-
// If timeout (seconds to wait) is not specified by caller, try to
183-
// estimate it based on number of objects in container
182+
// If container is empty, just delete it
183+
$numObjects = $this->getObjectCount();
184+
if ($numObjects === 0) {
185+
return $this->delete();
186+
}
187+
// If timeout ($secondsToWait) is not specified by caller,
188+
// try to estimate it based on number of objects in container
184189
if (null === $secondsToWait) {
185-
$numObjects = (int) $this->retrieveMetadata()->getProperty('Object-Count');
186190
$secondsToWait = round($numObjects / 2);
187-
}
188-
191+
}
189192
// Attempt to delete all objects and container
190193
$endTime = time() + $secondsToWait;
191194
$containerDeleted = false;
@@ -206,7 +209,7 @@ public function deleteWithObjects($secondsToWait = null)
206209
}
207210
}
208211
if (!$containerDeleted) {
209-
throw new ContainerException('Container and all its objects cound not be deleted');
212+
throw new ContainerException('Container could not be deleted.');
210213
}
211214
return $response;
212215
}

0 commit comments

Comments
 (0)