mirror of
https://github.com/sparkle-project/Sparkle
synced 2026-11-24 04:38:16 +00:00
Compute app path normalization in progress agent
Compute path instead of having installer pass over arbitrary path to agent.
This commit is contained in:
1 parent
25001d83ee
commit
414c8affc5
8 files changed
+88
-39
No files matched your search
@@ -573,17 +573,8 @@ static const NSTimeInterval SUDisplayProgressTimeDelay = 0.7;
|
||||
[self.communicator handleMessageWithIdentifier:SPUInstallationFinishedStage3 data:[NSData data]];
|
||||
|
||||
if (self.shouldRelaunch) {
|
||||
NSString *pathToRelaunch = nil;
|
||||
// If the relaunch path is the same as the host bundle path, use the installation path from the installer which may be normalized
|
||||
// Otherwise use the requested relaunch path in all other cases
|
||||
if ([self.relaunchPath.pathComponents isEqualToArray:self.host.bundlePath.pathComponents]) {
|
||||
pathToRelaunch = installationPath;
|
||||
} else {
|
||||
pathToRelaunch = self.relaunchPath;
|
||||
}
|
||||
|
||||
// This will also signal to the agent that it will terminate soon
|
||||
[self.agentConnection.agent relaunchPath:pathToRelaunch];
|
||||
[self.agentConnection.agent relaunchApplication];
|
||||
}
|
||||
|
||||
[self.installer performCleanup];
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#import "SULog.h"
|
||||
#import "SUErrors.h"
|
||||
#import "SPUInstallationType.h"
|
||||
#import "SUNormalization.h"
|
||||
|
||||
|
||||
#include "AppKitPrevention.h"
|
||||
@@ -152,11 +153,12 @@
|
||||
} else {
|
||||
NSString *normalizedInstallationPath = nil;
|
||||
if (SPARKLE_NORMALIZE_INSTALLED_APPLICATION_NAME) {
|
||||
normalizedInstallationPath = [self normalizedInstallationPathForHost:host];
|
||||
normalizedInstallationPath = SUNormalizedInstallationPath(host);
|
||||
}
|
||||
|
||||
// If we have a normalized path, we'll install to "#{CFBundleName}.app", but only if that path doesn't already exist. If we're "Foo 4.2.app," and there's a "Foo.app" in this directory, we don't want to overwrite it! But if there's no "Foo.app," we'll take that name.
|
||||
// Otherwise if there's no normalized path (the more likely case), we'll just use the host bundle's path
|
||||
// Check progress agent app which computes normalized path too according to these rules
|
||||
NSString *installationPath;
|
||||
if (normalizedInstallationPath != nil && ![[NSFileManager defaultManager] fileExistsAtPath:normalizedInstallationPath]) {
|
||||
installationPath = normalizedInstallationPath;
|
||||
@@ -171,22 +173,4 @@
|
||||
return installer;
|
||||
}
|
||||
|
||||
+ (NSString *)normalizedInstallationPathForHost:(SUHost *)host
|
||||
{
|
||||
NSBundle *bundle = host.bundle;
|
||||
assert(bundle != nil);
|
||||
|
||||
NSString * baseBundleName = [host objectForInfoDictionaryKey:@"SUBundleName"];
|
||||
|
||||
if (baseBundleName == nil) {
|
||||
baseBundleName = [host objectForInfoDictionaryKey:(__bridge NSString *)kCFBundleNameKey];
|
||||
}
|
||||
|
||||
NSString *normalizedAppPath = [[[bundle bundlePath] stringByDeletingLastPathComponent] stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.%@", baseBundleName, [[bundle bundlePath] pathExtension]]];
|
||||
|
||||
// Roundtrip string through fileSystemRepresentation to ensure it uses filesystem's Unicode normalization
|
||||
// rather than arbitrary Unicode form from Info.plist - #1017
|
||||
return [NSString stringWithUTF8String:[normalizedAppPath fileSystemRepresentation]];
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -10,7 +10,9 @@ SPARKLE_AUTOMATED_DOWNGRADES = 0
|
||||
|
||||
// If your app file on disk is named "MyApp 1.1b4", Sparkle usually updates it
|
||||
// in place, giving you an app named 1.1b4 that is actually 1.2. Turn the
|
||||
// following on to always reset the name back to "MyApp":
|
||||
// following on to always reset the name back to "MyApp"
|
||||
// If you are using this option to change the name of your app, you should
|
||||
// disable the option again when you no longer need it
|
||||
SPARKLE_NORMALIZE_INSTALLED_APPLICATION_NAME = 0
|
||||
|
||||
SPARKLE_ICON_NAME = AppIcon
|
||||
|
||||
@@ -168,6 +168,8 @@
|
||||
7229E1BA1C97CC4D00CB50D0 /* SPUScheduledUpdateDriver.m in Sources */ = {isa = PBXBuildFile; fileRef = 7229E1B81C97CC4D00CB50D0 /* SPUScheduledUpdateDriver.m */; };
|
||||
7229E1BD1C98EFF200CB50D0 /* SPUDownloadDriver.h in Headers */ = {isa = PBXBuildFile; fileRef = 7229E1BB1C98EFF200CB50D0 /* SPUDownloadDriver.h */; };
|
||||
7229E1BE1C98EFF200CB50D0 /* SPUDownloadDriver.m in Sources */ = {isa = PBXBuildFile; fileRef = 7229E1BC1C98EFF200CB50D0 /* SPUDownloadDriver.m */; };
|
||||
722FB7E5260EE53F00EB571C /* SUNormalization.m in Sources */ = {isa = PBXBuildFile; fileRef = 722FB7E4260EE53F00EB571C /* SUNormalization.m */; };
|
||||
722FB7E6260EE53F00EB571C /* SUNormalization.m in Sources */ = {isa = PBXBuildFile; fileRef = 722FB7E4260EE53F00EB571C /* SUNormalization.m */; };
|
||||
72316BD31E0DA8430039EFD9 /* SUUnarchiverNotifier.m in Sources */ = {isa = PBXBuildFile; fileRef = 72316BD21E0DA8430039EFD9 /* SUUnarchiverNotifier.m */; };
|
||||
72316BD41E0DB37E0039EFD9 /* SUUnarchiverNotifier.m in Sources */ = {isa = PBXBuildFile; fileRef = 72316BD21E0DA8430039EFD9 /* SUUnarchiverNotifier.m */; };
|
||||
723ABD38259A9BA500BDB4FA /* SUUpdateAlert.xib in Resources */ = {isa = PBXBuildFile; fileRef = 723ABD36259A9BA500BDB4FA /* SUUpdateAlert.xib */; };
|
||||
@@ -1059,6 +1061,8 @@
|
||||
7229E1BB1C98EFF200CB50D0 /* SPUDownloadDriver.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SPUDownloadDriver.h; sourceTree = "<group>"; };
|
||||
7229E1BC1C98EFF200CB50D0 /* SPUDownloadDriver.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SPUDownloadDriver.m; sourceTree = "<group>"; };
|
||||
722FB7CA1DD69897001D40CE /* ConfigSwift.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = ConfigSwift.xcconfig; sourceTree = "<group>"; };
|
||||
722FB7E3260EE53F00EB571C /* SUNormalization.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SUNormalization.h; sourceTree = "<group>"; };
|
||||
722FB7E4260EE53F00EB571C /* SUNormalization.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SUNormalization.m; sourceTree = "<group>"; };
|
||||
72316BD11E0DA8430039EFD9 /* SUUnarchiverNotifier.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SUUnarchiverNotifier.h; path = Autoupdate/SUUnarchiverNotifier.h; sourceTree = SOURCE_ROOT; };
|
||||
72316BD21E0DA8430039EFD9 /* SUUnarchiverNotifier.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SUUnarchiverNotifier.m; path = Autoupdate/SUUnarchiverNotifier.m; sourceTree = SOURCE_ROOT; };
|
||||
723ABCD7259A9A9D00BDB4FA /* Base */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = Base; path = Base.lproj/Sparkle.strings; sourceTree = "<group>"; };
|
||||
@@ -1924,6 +1928,8 @@
|
||||
7267E5BB1D3D8B2700D1BF90 /* SUGuidedPackageInstaller.m */,
|
||||
7267E5BC1D3D8B2700D1BF90 /* SUInstaller.h */,
|
||||
7267E5BD1D3D8B2700D1BF90 /* SUInstaller.m */,
|
||||
722FB7E3260EE53F00EB571C /* SUNormalization.h */,
|
||||
722FB7E4260EE53F00EB571C /* SUNormalization.m */,
|
||||
7267E5B91D3D8B0B00D1BF90 /* SUInstallerProtocol.h */,
|
||||
7267E5BE1D3D8B2700D1BF90 /* SUPackageInstaller.h */,
|
||||
7267E5BF1D3D8B2700D1BF90 /* SUPackageInstaller.m */,
|
||||
@@ -3400,6 +3406,7 @@
|
||||
7267E5FA1D3DAC3600D1BF90 /* StatusInfo.m in Sources */,
|
||||
720595EF1D700568000572E8 /* SUApplicationInfo.m in Sources */,
|
||||
7214B8831D456C2400CB5CED /* SUBundleIcon.m in Sources */,
|
||||
722FB7E6260EE53F00EB571C /* SUNormalization.m in Sources */,
|
||||
721C245E1CB757DE005440CB /* SUConstants.m in Sources */,
|
||||
7267E5EB1D3D90C200D1BF90 /* SUFileManager.m in Sources */,
|
||||
721C24611CB75C5D005440CB /* SUHost.m in Sources */,
|
||||
@@ -3578,6 +3585,7 @@
|
||||
72316BD31E0DA8430039EFD9 /* SUUnarchiverNotifier.m in Sources */,
|
||||
729924941DF4A45000DBCDF5 /* SUUpdateValidator.m in Sources */,
|
||||
7267E5AB1D3D8AA800D1BF90 /* TerminationListener.m in Sources */,
|
||||
722FB7E5260EE53F00EB571C /* SUNormalization.m in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
||||
+21
-8
@@ -17,6 +17,7 @@
|
||||
#import "StatusInfo.h"
|
||||
#import "SUHost.h"
|
||||
#import "SUErrors.h"
|
||||
#import "SUNormalization.h"
|
||||
|
||||
/*!
|
||||
* Terminate the application after a delay from launching the new update to avoid OS activation issues
|
||||
@@ -38,6 +39,7 @@ static const NSTimeInterval SUTerminationTimeDelay = 0.3;
|
||||
@property (nonatomic) BOOL willTerminate;
|
||||
@property (nonatomic) BOOL applicationInitiallyAlive;
|
||||
@property (nonatomic) NSBundle *applicationBundle;
|
||||
@property (nonatomic) NSString *normalizedPath;
|
||||
|
||||
@end
|
||||
|
||||
@@ -56,6 +58,7 @@ static const NSTimeInterval SUTerminationTimeDelay = 0.3;
|
||||
@synthesize willTerminate = _willTerminate;
|
||||
@synthesize applicationInitiallyAlive = _applicationInitiallyAlive;
|
||||
@synthesize applicationBundle = _applicationBundle;
|
||||
@synthesize normalizedPath = _normalizedPath;
|
||||
|
||||
- (instancetype)initWithApplication:(NSApplication *)application arguments:(NSArray<NSString *> *)arguments delegate:(id<InstallerProgressDelegate>)delegate
|
||||
{
|
||||
@@ -215,6 +218,20 @@ static const NSTimeInterval SUTerminationTimeDelay = 0.3;
|
||||
[self cleanupAndExitWithStatus:EXIT_FAILURE error:[NSError errorWithDomain:SUSparkleErrorDomain code:SUAgentInvalidationError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Error: Encountered invalid path for waiting termination: %@", applicationBundlePath] }]];
|
||||
}
|
||||
|
||||
// Compute normalized path that we may use later for relaunching the application
|
||||
// We compute normalized path from progress agent instead of trusting or having the installer
|
||||
// pass it to us
|
||||
if (SPARKLE_NORMALIZE_INSTALLED_APPLICATION_NAME) {
|
||||
SUHost *applicationHost = [[SUHost alloc] initWithBundle:applicationBundle];
|
||||
|
||||
NSString *normalizedPath = SUNormalizedInstallationPath(applicationHost);
|
||||
// We only use normalized path if it doesn't already exist
|
||||
// Check the installer which has the same logic
|
||||
if (![[NSFileManager defaultManager] fileExistsAtPath:normalizedPath]) {
|
||||
self.normalizedPath = SUNormalizedInstallationPath(applicationHost);
|
||||
}
|
||||
}
|
||||
|
||||
NSArray<NSRunningApplication *> *runningApplications = [self runningApplicationsWithBundle:applicationBundle];
|
||||
|
||||
// We're just picking the first running application to send..
|
||||
@@ -256,27 +273,23 @@ static const NSTimeInterval SUTerminationTimeDelay = 0.3;
|
||||
});
|
||||
}
|
||||
|
||||
- (void)relaunchPath:(NSString *)requestedPathToRelaunch
|
||||
- (void)relaunchApplication
|
||||
{
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
if (!self.willTerminate && self.applicationBundle != nil && self.applicationInitiallyAlive) {
|
||||
// If the normalized setting is not enabled, we shouldn't trust the relaunch path input that is being passed to us
|
||||
// because we already have the application path to relaunch, and we verified that it was running before
|
||||
NSString *pathToRelaunch;
|
||||
if (SPARKLE_NORMALIZE_INSTALLED_APPLICATION_NAME) {
|
||||
pathToRelaunch = requestedPathToRelaunch;
|
||||
if (self.normalizedPath != nil) {
|
||||
pathToRelaunch = self.normalizedPath;
|
||||
} else {
|
||||
pathToRelaunch = self.applicationBundle.bundlePath;
|
||||
}
|
||||
|
||||
// We should at least make sure we're opening a bundle however
|
||||
// We should at least make sure we're opening a bundle
|
||||
NSBundle *relaunchBundle = [NSBundle bundleWithPath:pathToRelaunch];
|
||||
if (relaunchBundle == nil) {
|
||||
[self cleanupAndExitWithStatus:EXIT_FAILURE error:[NSError errorWithDomain:SUSparkleErrorDomain code:SUAgentInvalidationError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Error: Encountered invalid path to relaunch: %@", pathToRelaunch] }]];
|
||||
}
|
||||
|
||||
// We only launch applications, but I'm not sure how reliable -launchApplicationAtURL:options:config: is so we're not using it
|
||||
// Eg: http://www.openradar.me/10952677
|
||||
if (![[NSWorkspace sharedWorkspace] openFile:pathToRelaunch]) {
|
||||
SULog(SULogLevelError, @"Error: Failed to relaunch bundle at %@", pathToRelaunch);
|
||||
}
|
||||
|
||||
+1
-1
@@ -22,7 +22,7 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
- (void)stopProgress;
|
||||
|
||||
- (void)relaunchPath:(NSString *)pathToRelaunch;
|
||||
- (void)relaunchApplication;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
Vendored
+16
@@ -0,0 +1,16 @@
|
||||
//
|
||||
// SUNormalization.h
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Mayur Pawashe on 3/26/21.
|
||||
// Copyright © 2021 Sparkle Project. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "SUHost.h"
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
NSString *SUNormalizedInstallationPath(SUHost *host);
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
Vendored
+35
@@ -0,0 +1,35 @@
|
||||
//
|
||||
// SUNormalization.m
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Mayur Pawashe on 3/26/21.
|
||||
// Copyright © 2021 Sparkle Project. All rights reserved.
|
||||
//
|
||||
|
||||
#import "SUNormalization.h"
|
||||
|
||||
|
||||
#include "AppKitPrevention.h"
|
||||
|
||||
NSString *SUNormalizedInstallationPath(SUHost *host)
|
||||
{
|
||||
NSBundle *bundle = host.bundle;
|
||||
assert(bundle != nil);
|
||||
|
||||
NSString * baseBundleName = [host objectForInfoDictionaryKey:@"SUBundleName"];
|
||||
|
||||
if (baseBundleName == nil) {
|
||||
baseBundleName = [host objectForInfoDictionaryKey:(__bridge NSString *)kCFBundleNameKey];
|
||||
}
|
||||
|
||||
NSString *normalizedAppPath = [[[bundle bundlePath] stringByDeletingLastPathComponent] stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.%@", baseBundleName, [[bundle bundlePath] pathExtension]]];
|
||||
|
||||
// Roundtrip string through fileSystemRepresentation to ensure it uses filesystem's Unicode normalization
|
||||
// rather than arbitrary Unicode form from Info.plist - #1017
|
||||
NSString *unicodeNormalizedPath = [NSString stringWithUTF8String:[normalizedAppPath fileSystemRepresentation]];
|
||||
if (unicodeNormalizedPath != nil) {
|
||||
return unicodeNormalizedPath;
|
||||
} else {
|
||||
return normalizedAppPath;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user