diff --git a/Configurations/ConfigFramework.xcconfig b/Configurations/ConfigFramework.xcconfig index cedad035..a0528768 100644 --- a/Configurations/ConfigFramework.xcconfig +++ b/Configurations/ConfigFramework.xcconfig @@ -9,3 +9,4 @@ FRAMEWORK_VERSION = A INFOPLIST_FILE = Sparkle/Sparkle-Info.plist GCC_PREFIX_HEADER = Sparkle/Sparkle.pch SKIP_INSTALL = YES +OTHER_LDFLAGS = -Wl,-U,_NSURLQuarantinePropertiesKey diff --git a/Configurations/ConfigRelaunch.xcconfig b/Configurations/ConfigRelaunch.xcconfig index 22507036..ee339f01 100644 --- a/Configurations/ConfigRelaunch.xcconfig +++ b/Configurations/ConfigRelaunch.xcconfig @@ -5,3 +5,4 @@ PRODUCT_NAME = $(FINISH_INSTALL_TOOL_NAME) SKIP_INSTALL = YES GCC_PREFIX_HEADER = Sparkle/Autoupdate/Autoupdate.pch ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon +OTHER_LDFLAGS = -Wl,-U,_NSURLQuarantinePropertiesKey diff --git a/Sparkle/SUPlainInstallerInternals.m b/Sparkle/SUPlainInstallerInternals.m index 09504b17..072b64b7 100644 --- a/Sparkle/SUPlainInstallerInternals.m +++ b/Sparkle/SUPlainInstallerInternals.m @@ -23,6 +23,10 @@ #include #include +#if __MAC_OS_X_VERSION_MAX_ALLOWED < 101000 +extern NSString *const NSURLQuarantinePropertiesKey WEAK_IMPORT_ATTRIBUTE; +#endif + static inline void PerformOnMainThreadSync(dispatch_block_t theBlock) { if ([NSThread isMainThread]) { @@ -537,13 +541,14 @@ static BOOL AuthorizationExecuteWithPrivilegesAndWait(AuthorizationRef authoriza @implementation SUPlainInstaller (MMExtendedAttributes) -+ (int)removeXAttr:(const char *)name ++ (int)removeXAttr:(NSString *)name fromFile:(NSString *)file options:(int)options { // *** MUST BE SAFE TO CALL ON NON-MAIN THREAD! const char *path = NULL; + const char *attr = [name cStringUsingEncoding:NSASCIIStringEncoding]; @try { path = [file fileSystemRepresentation]; } @@ -556,34 +561,57 @@ static BOOL AuthorizationExecuteWithPrivilegesAndWait(AuthorizationRef authoriza return -1; } - return removexattr(path, name, options); + return removexattr(path, attr, options); } + (void)releaseFromQuarantine:(NSString *)root { // *** MUST BE SAFE TO CALL ON NON-MAIN THREAD! - const char *quarantineAttribute = "com.apple.quarantine"; - const int removeXAttrOptions = XATTR_NOFOLLOW; + NSFileManager *manager = [NSFileManager defaultManager]; +#if __MAC_OS_X_VERSION_MIN_REQUIRED < 101000 + if (!&NSURLQuarantinePropertiesKey) { + NSString *const quarantineAttribute = (NSString*)kLSItemQuarantineProperties; + const int removeXAttrOptions = XATTR_NOFOLLOW; - [self removeXAttr:quarantineAttribute - fromFile:root - options:removeXAttrOptions]; + [self removeXAttr:quarantineAttribute + fromFile:root + options:removeXAttrOptions]; + // Only recurse if it's actually a directory. Don't recurse into a + // root-level symbolic link. + NSDictionary *rootAttributes = [manager attributesOfItemAtPath:root error:nil]; + NSString *rootType = rootAttributes[NSFileType]; + + if (rootType == NSFileTypeDirectory) { + // The NSDirectoryEnumerator will avoid recursing into any contained + // symbolic links, so no further type checks are needed. + NSDirectoryEnumerator *directoryEnumerator = [manager enumeratorAtPath:root]; + NSString *file = nil; + while ((file = [directoryEnumerator nextObject])) { + [self removeXAttr:quarantineAttribute + fromFile:[root stringByAppendingPathComponent:file] + options:removeXAttrOptions]; + } + } + return; + } +#endif + NSURL *rootURL = [NSURL fileURLWithPath:root]; + [rootURL setResourceValue:[NSNull null] forKey:NSURLQuarantinePropertiesKey error:NULL]; + // Only recurse if it's actually a directory. Don't recurse into a // root-level symbolic link. - NSDictionary *rootAttributes = [[NSFileManager defaultManager] attributesOfItemAtPath:root error:nil]; + NSDictionary *rootAttributes = [manager attributesOfItemAtPath:root error:nil]; NSString *rootType = rootAttributes[NSFileType]; if (rootType == NSFileTypeDirectory) { // The NSDirectoryEnumerator will avoid recursing into any contained // symbolic links, so no further type checks are needed. - NSDirectoryEnumerator *directoryEnumerator = [[NSFileManager defaultManager] enumeratorAtPath:root]; - NSString *file = nil; - while ((file = [directoryEnumerator nextObject])) { - [self removeXAttr:quarantineAttribute - fromFile:[root stringByAppendingPathComponent:file] - options:removeXAttrOptions]; + NSDirectoryEnumerator *directoryEnumerator = [manager enumeratorAtURL:rootURL includingPropertiesForKeys:nil options:(NSDirectoryEnumerationOptions)0 errorHandler:nil]; + + for (NSURL *file in directoryEnumerator) { + [file setResourceValue:[NSNull null] forKey:NSURLQuarantinePropertiesKey error:NULL]; } } }