adium 4130:ab4789e8a4e7: Quarantine all files Adium creates by d...

commits at adium.im commits at adium.im
Tue Aug 9 19:43:41 UTC 2011


details:	http://hg.adium.im/adium/rev/ab4789e8a4e7
revision:	4130:ab4789e8a4e7
branch:		(none)
author:		Thijs Alkemade <thijsalkemade at gmail.com>
date:		Tue Aug 09 21:43:12 2011 +0200

Quarantine all files Adium creates by default. For xtras, the type is a "web download", with the source URL included.

Fix quarantining file transfers:
 * Only apply to incoming transfers.
 * Add properties to the existing quarantine dictionary, don't replace everything.

diffs (180 lines):

diff -r 05eb176d9276 -r ab4789e8a4e7 Frameworks/Adium Framework/Source/ESFileTransfer.m
--- a/Frameworks/Adium Framework/Source/ESFileTransfer.m	Sun Aug 07 23:32:20 2011 +0200
+++ b/Frameworks/Adium Framework/Source/ESFileTransfer.m	Tue Aug 09 21:43:12 2011 +0200
@@ -259,20 +259,54 @@
 		if (percentDone >= 1.0) {
 			[self setStatus:Complete_FileTransfer];
 			
-			[[NSDistributedNotificationCenter defaultCenter] postNotificationName:@"com.apple.DownloadFileFinished"
-																		   object:localFilename];
-			
-			FSRef fsRef;
-			
-			if (FSPathMakeRef((const UInt8 *)[localFilename fileSystemRepresentation], &fsRef, NULL) == noErr) {
+			if (type == Incoming_FileTransfer) {
+				[[NSDistributedNotificationCenter defaultCenter] postNotificationName:@"com.apple.DownloadFileFinished"
+																			   object:localFilename];
 				
-				NSDictionary *quarantineProperties = [NSDictionary dictionaryWithObject:(NSString *)kLSQuarantineTypeInstantMessageAttachment
-																				 forKey:(NSString *)kLSQuarantineTypeKey];
+				FSRef fsRef;
+				OSErr err;
 				
-				LSSetItemAttribute(&fsRef, kLSRolesAll, kLSItemQuarantineProperties, quarantineProperties);
-				
-			} else {
-				AILogWithSignature(@"Danger! Could not find file to quarantine: %@!", localFilename);
+				if (FSPathMakeRef((const UInt8 *)[localFilename fileSystemRepresentation], &fsRef, NULL) == noErr) {
+					
+					NSMutableDictionary *quarantineProperties = nil;
+					CFTypeRef cfOldQuarantineProperties = NULL;
+					
+					err = LSCopyItemAttribute(&fsRef, kLSRolesAll, kLSItemQuarantineProperties, &cfOldQuarantineProperties);
+					
+					if (err == noErr) {
+						
+						if (CFGetTypeID(cfOldQuarantineProperties) == CFDictionaryGetTypeID()) {
+							quarantineProperties = [[(NSDictionary *)cfOldQuarantineProperties mutableCopy] autorelease];
+						} else {
+							AILogWithSignature(@"Getting quarantine data failed for %@ (%@)", self, localFilename);
+							return;
+						}
+						
+						CFRelease(cfOldQuarantineProperties);
+						
+						if (!quarantineProperties) {
+							return;
+						}
+						
+					} else if (err == kLSAttributeNotFoundErr) {
+						quarantineProperties = [NSMutableDictionary dictionaryWithCapacity:2];
+					}
+					
+					[quarantineProperties setObject:(NSString *)kLSQuarantineTypeInstantMessageAttachment
+											 forKey:(NSString *)kLSQuarantineTypeKey];
+					// TODO Figure out the file URL to the transcript
+//					[quarantineProperties setObject:[NSURL URLWithString:@"file:///dev/null"]
+//											 forKey:(NSString *)kLSQuarantineOriginURLKey];
+					
+					if (LSSetItemAttribute(&fsRef, kLSRolesAll, kLSItemQuarantineProperties, quarantineProperties) != noErr) {
+						AILogWithSignature(@"Danger! Quarantining file %@ failed!", localFilename);
+					}
+					
+					AILogWithSignature(@"Quarantined %@ with %@", localFilename, quarantineProperties);
+					
+				} else {
+					AILogWithSignature(@"Danger! Could not find file to quarantine: %@!", localFilename);
+				}
 			}
 			
 		} else if ((percentDone != 0) && (status != In_Progress_FileTransfer)) {
diff -r 05eb176d9276 -r ab4789e8a4e7 Plists/Info.plist
--- a/Plists/Info.plist	Sun Aug 07 23:32:20 2011 +0200
+++ b/Plists/Info.plist	Tue Aug 09 21:43:12 2011 +0200
@@ -472,6 +472,8 @@
 	<string>1.5hg</string>
 	<key>LSApplicationCategoryType</key>
 	<string>public.app-category.social-networking</string>
+	<key>LSFileQuarantineEnabled</key>
+	<true/>
 	<key>LSMinimumSystemVersion</key>
 	<string>10.6.0</string>
 	<key>LSRequiresNativeExecution</key>
diff -r 05eb176d9276 -r ab4789e8a4e7 Source/XtrasInstaller.m
--- a/Source/XtrasInstaller.m	Sun Aug 07 23:32:20 2011 +0200
+++ b/Source/XtrasInstaller.m	Tue Aug 09 21:43:12 2011 +0200
@@ -166,7 +166,33 @@
 					 NULL, @selector(sheetDidDismiss:returnCode:contextInfo:), nil, errorMsg);
 }
 
-- (void)downloadDidFinish:(NSURLDownload *)download {
+- (void)setQuarantineProperties:(NSDictionary *)dict forDirectory:(FSRef *)dir
+{
+	FSIterator iterator;
+	
+	if (FSOpenIterator(dir, kFSIterateFlat, &iterator) != noErr) {
+		AILogWithSignature(@"Error quarantining %p", dir);
+	}
+	
+	FSRef ref;
+	ItemCount num;
+	
+	while (FSGetCatalogInfoBulk(iterator, 1, &num, NULL, kFSCatInfoNone, NULL, &ref, NULL, NULL) == noErr)
+	{
+		LSSetItemAttribute(&ref, kLSRolesAll, kLSItemQuarantineProperties, dict);
+		
+		FSCatalogInfo catinfo;
+		FSGetCatalogInfo(&ref, kFSCatInfoNodeFlags, &catinfo, NULL, NULL, NULL);
+		
+		if(catinfo.nodeFlags & kFSNodeIsDirectoryMask) {
+			[self setQuarantineProperties:dict forDirectory:&ref];
+		}
+	}
+	
+	FSCloseIterator(iterator);
+}
+
+- (void)downloadDidFinish:(NSURLDownload *)inDownload {
 	NSString		*lastPathComponent = [dest lastPathComponent];
 	NSString		*pathExtension = [[lastPathComponent pathExtension] lowercaseString];
 	BOOL			decompressionSuccess = YES, success = NO;
@@ -259,6 +285,51 @@
 	
 	dest = [dest stringByDeletingLastPathComponent];
 	
+	FSRef fsRef;
+	OSStatus err;
+	
+	if (FSPathMakeRef((const UInt8 *)[dest fileSystemRepresentation], &fsRef, NULL) == noErr) {
+		
+		NSMutableDictionary *quarantineProperties = nil;
+		CFTypeRef cfOldQuarantineProperties = NULL;
+		
+		err = LSCopyItemAttribute(&fsRef, kLSRolesAll, kLSItemQuarantineProperties, &cfOldQuarantineProperties);
+		
+		if (err == noErr) {
+			
+			if (CFGetTypeID(cfOldQuarantineProperties) == CFDictionaryGetTypeID()) {
+				quarantineProperties = [[(NSDictionary *)cfOldQuarantineProperties mutableCopy] autorelease];
+			} else {
+				AILogWithSignature(@"Getting quarantine data failed for %@ (%@)", self, dest);
+				return;
+			}
+			
+			CFRelease(cfOldQuarantineProperties);
+			
+			if (!quarantineProperties) {
+				return;
+			}
+			
+			AILogWithSignature(@"Old quarantine data: %@", quarantineProperties);
+			
+		} else if (err == kLSAttributeNotFoundErr) {
+			quarantineProperties = [NSMutableDictionary dictionaryWithCapacity:2];
+		}
+		
+		[quarantineProperties setObject:(NSString *)kLSQuarantineTypeWebDownload
+								 forKey:(NSString *)kLSQuarantineTypeKey];
+		
+		[quarantineProperties setObject:[[download request] URL]
+								 forKey:(NSString *)kLSQuarantineDataURLKey];
+		
+		[self setQuarantineProperties:quarantineProperties forDirectory:&fsRef];
+		
+		AILogWithSignature(@"Quarantined %@ with %@", dest, quarantineProperties);
+		
+	} else {
+		AILogWithSignature(@"Danger! Could not find file to quarantine: %@!", dest);
+	}
+	
 	//the remaining files in the directory should be the contents of the xtra
 	fileEnumerator = [fileManager enumeratorAtPath:dest];
 
@@ -266,6 +337,7 @@
 		NSSet			*supportedDocumentExtensions = [[NSBundle mainBundle] supportedDocumentExtensions];
 
 		for (NSString *nextFile in fileEnumerator) {
+			
 			/* Ignore hidden files and the __MACOSX folder which some compression engines stick into the archive but
 			 * /usr/bin/unzip doesn't handle properly.
 			 */




More information about the commits mailing list