Check the parent directory for writability too

This commit is contained in:
Zorg committed 2016-04-10 09:07:00 -04:00
1 parent cd108ef47c
commit 296154d467
5 files changed
+28 -11

No files matched your search

+3 -8
View File
@@ -440,14 +440,9 @@ static const NSTimeInterval SUDisplayProgressTimeDelay = 0.7;
return;
}
if (self.shouldShowUI) {
// Predict if an admin prompt is needed
// If it is, we should activate our app so that the auth prompt will be active
// (Note it's more efficient/simpler to predict rather than trying, seeing if we fail, notifying, and re-trying)
NSString *installationPath = [SUInstaller installationPathForHost:self.host];
if (![[NSFileManager defaultManager] isWritableFileAtPath:installationPath]) {
[[NSApplication sharedApplication] activateIgnoringOtherApps:YES];
}
if (self.shouldShowUI && [self.installer mayNeedToRequestAuthorization]) {
// We should activate our app so that the auth prompt will be active
[[NSApplication sharedApplication] activateIgnoringOtherApps:YES];
}
NSError *secondStageError = nil;
+4
View File
@@ -36,6 +36,10 @@
// Should be thread safe
- (BOOL)canInstallSilently;
// Indicates whether or not this installer may need authorization when performing the second stage of the installation
// Should be thread safe
- (BOOL)mayNeedToRequestAuthorization;
// Cleans up work done from any of the previous stages. This should be invoked after stage 3 succeeds,
// or after any one of the stages fails.
// Should be able to be called from non-main thread
+6 -1
View File
@@ -93,7 +93,12 @@
- (BOOL)canInstallSilently
{
return NO; // because of authorization
return ![self mayNeedToRequestAuthorization];
}
- (BOOL)mayNeedToRequestAuthorization
{
return YES;
}
- (void)cleanup
+5
View File
@@ -82,6 +82,11 @@ static NSString *SUOpenUtilityPath = @"/usr/bin/open";
return NO;
}
- (BOOL)mayNeedToRequestAuthorization
{
return NO;
}
- (void)cleanup
{
}
+10 -2
View File
@@ -248,8 +248,16 @@
- (BOOL)canInstallSilently
{
#warning is this test good enough or should we check parent directory too?
return [[NSFileManager defaultManager] isWritableFileAtPath:self.host.bundle.bundlePath];
return ![self mayNeedToRequestAuthorization];
}
- (BOOL)mayNeedToRequestAuthorization
{
NSFileManager *fileManager = [NSFileManager defaultManager];
NSString *bundlePath = self.host.bundle.bundlePath;
// It's very well possible to have the bundle be writable but not be able to write into the parent directory
// And if the bundle isn't writable, but we can write into the parent directory, we will still need to authorize to replace it
return ![fileManager isWritableFileAtPath:bundlePath] || ![fileManager isWritableFileAtPath:[bundlePath stringByDeletingLastPathComponent]];
}
- (void)cleanup