From 5457476e4a3ee0f81f804ed33da1570863affa59 Mon Sep 17 00:00:00 2001 From: Andy Matuschak Date: Thu, 27 Oct 2011 21:59:45 -0700 Subject: [PATCH] Fixes #109: Error extracting dmg archives --- SUDiskImageUnarchiver.m | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/SUDiskImageUnarchiver.m b/SUDiskImageUnarchiver.m index 80c83d29..063624da 100644 --- a/SUDiskImageUnarchiver.m +++ b/SUDiskImageUnarchiver.m @@ -67,10 +67,28 @@ // Now that we've mounted it, we need to copy out its contents. if (floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_5) { // On 10.6 and later we don't want to use the File Manager API and instead want to use NSFileManager (fixes #827357). - NSFileManager *manager = [[NSFileManager alloc] init]; - if (![manager copyItemAtPath:mountPoint toPath:[archivePath stringByDeletingLastPathComponent] error:NULL]) { - goto reportError; - } + NSFileManager *manager = [[[NSFileManager alloc] init] autorelease]; + NSError *error = nil; + NSArray *contents = [manager contentsOfDirectoryAtPath:mountPoint error:&error]; + if (error) + { + SULog(@"Couldn't enumerate contents of archive mounted at %@: %@", mountPoint, error); + goto reportError; + } + + for (NSString *fileItem in contents) + { + NSString *fromPath = [mountPoint stringByAppendingPathComponent:fileItem]; + NSString *toPath = [[archivePath stringByDeletingLastPathComponent] stringByAppendingPathComponent:fileItem]; + + SULog(@"copyItemAtPath:%@ toPath:%@", fromPath, toPath); + + if (![manager copyItemAtPath:fromPath toPath:toPath error:&error]) + { + SULog(@"Couldn't copy item: %@", error); + goto reportError; + } + } } else { FSRef srcRef, dstRef;