From 9ce9b7bf4696323019812f4288751d36429ae545 Mon Sep 17 00:00:00 2001
From: tedbow <tedbow@240860.no-reply.drupal.org>
Date: Tue, 5 Apr 2022 12:19:19 +0000
Subject: [PATCH] Issue #3273006 by tedbow: Uninstalling package_manager with
 drush gives a warning if no staging directory exists

---
 package_manager/src/Stage.php | 26 +++++++++++++++-----------
 1 file changed, 15 insertions(+), 11 deletions(-)

diff --git a/package_manager/src/Stage.php b/package_manager/src/Stage.php
index 810806fe74..229d2eb882 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));
   }
-- 
GitLab