diff --git a/package_manager/src/Stage.php b/package_manager/src/Stage.php index 810806fe743ab728d415df8b7a9befd36c4b2ce1..229d2eb882a16a4f88f2da47234c1b88de906b9f 100644 --- a/package_manager/src/Stage.php +++ b/package_manager/src/Stage.php @@ -364,18 +364,22 @@ class Stage { } $this->dispatch(new PreDestroyEvent($this)); - // Delete the staging root and everything in it. - try { - $this->fileSystem->deleteRecursive($this->getStagingRoot(), function (string $path): void { - $this->fileSystem->chmod($path, 0777); - }); - } - catch (FileException $e) { - // Deliberately swallow the exception so that the stage will be marked - // as available and the post-destroy event will be fired, even if the - // staging area can't actually be deleted. The file system service logs - // the exception, so we don't need to do anything else here. + $staging_root = $this->getStagingRoot(); + // If the staging root exists, delete it and everything in it. + if (file_exists($staging_root)) { + try { + $this->fileSystem->deleteRecursive($staging_root, function (string $path): void { + $this->fileSystem->chmod($path, 0777); + }); + } + catch (FileException $e) { + // Deliberately swallow the exception so that the stage will be marked + // as available and the post-destroy event will be fired, even if the + // staging area can't actually be deleted. The file system service logs + // the exception, so we don't need to do anything else here. + } } + $this->markAsAvailable(); $this->dispatch(new PostDestroyEvent($this)); }