From cb19fe8864a7fc5ddabf01227fec9aa5232e0df7 Mon Sep 17 00:00:00 2001 From: "C.W. Betts" Date: Fri, 18 Jul 2014 13:28:20 -0600 Subject: [PATCH] Use some 10.10-specific APIs to remove the quarantine attribute. --- Sparkle/SUPlainInstallerInternals.m | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/Sparkle/SUPlainInstallerInternals.m b/Sparkle/SUPlainInstallerInternals.m index 62ac5015..c929d36b 100644 --- a/Sparkle/SUPlainInstallerInternals.m +++ b/Sparkle/SUPlainInstallerInternals.m @@ -564,6 +564,28 @@ static BOOL AuthorizationExecuteWithPrivilegesAndWait(AuthorizationRef authoriza { // *** MUST BE SAFE TO CALL ON NON-MAIN THREAD! + NSFileManager *manager = [NSFileManager defaultManager]; +#if __MAC_OS_X_VERSION_MAX_ALLOWED > __MAC_10_9 + if (&NSURLQuarantinePropertiesKey) { + 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 = [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 enumeratorAtURL:rootURL includingPropertiesForKeys:nil options:(NSDirectoryEnumerationOptions)0 errorHandler:nil]; + + for (NSURL *file in directoryEnumerator) { + [file setResourceValue:[NSNull null] forKey:NSURLQuarantinePropertiesKey error:NULL]; + } + } + } else { +#endif NSString *const quarantineAttribute = (NSString*)kLSItemQuarantineProperties; const int removeXAttrOptions = XATTR_NOFOLLOW; @@ -573,13 +595,13 @@ static BOOL AuthorizationExecuteWithPrivilegesAndWait(AuthorizationRef authoriza // 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]; + NSDirectoryEnumerator *directoryEnumerator = [manager enumeratorAtPath:root]; NSString *file = nil; while ((file = [directoryEnumerator nextObject])) { [self removeXAttr:quarantineAttribute @@ -587,6 +609,9 @@ static BOOL AuthorizationExecuteWithPrivilegesAndWait(AuthorizationRef authoriza options:removeXAttrOptions]; } } +#if __MAC_OS_X_VERSION_MAX_ALLOWED > __MAC_10_9 +} +#endif } @end