From c44c164affb070786e8006fd4e76fc680fcc3547 Mon Sep 17 00:00:00 2001 From: Zorg Date: Sat, 24 Apr 2021 19:29:10 -0700 Subject: [PATCH] Clean up empty / temporary progress agent tool directory immediately --- .../InstallerProgressAppController.m | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/Sparkle/InstallerProgress/InstallerProgressAppController.m b/Sparkle/InstallerProgress/InstallerProgressAppController.m index 4bba0dc2..e3313442 100644 --- a/Sparkle/InstallerProgress/InstallerProgressAppController.m +++ b/Sparkle/InstallerProgress/InstallerProgressAppController.m @@ -193,8 +193,21 @@ static const NSTimeInterval SUTerminationTimeDelay = 0.3; // Remove the agent bundle; it is assumed this bundle is in a temporary/cache/support directory NSError *theError = nil; - if (![[NSFileManager defaultManager] removeItemAtPath:[[NSBundle mainBundle] bundlePath] error:&theError]) { + NSString *bundlePath = [[NSBundle mainBundle] bundlePath]; + + if (![[NSFileManager defaultManager] removeItemAtPath:bundlePath error:&theError]) { SULog(SULogLevelError, @"Couldn't remove agent bundle: %@.", theError); + } else { + // There should be nothing else in the parent temporary directory given to us, + // so let us try to remove it. Note rmdir() will fail if there are unexpectably other + // items present + NSString *parentDirectory = bundlePath.stringByDeletingLastPathComponent; + const char *fileSystemRepresentation = parentDirectory.fileSystemRepresentation; + if (fileSystemRepresentation != NULL) { + if (rmdir(fileSystemRepresentation) != 0) { + SULog(SULogLevelError, @"Failed to remove parent agent bundle directory: %@: %d", parentDirectory, errno); + } + } } exit(status);