From 20480f15620b8a7653f85fdc061609156119580c Mon Sep 17 00:00:00 2001 From: Hannes Juutilainen Date: Fri, 13 Dec 2013 13:44:12 +0200 Subject: [PATCH] Re-indent and whitespace fixes --- .../FileCopyOperation.m | 25 +- .../NSOperation Subclasses/ManifestScanner.m | 8 +- .../NSOperation Subclasses/MunkiOperation.m | 14 +- .../NSOperation Subclasses/PkginfoScanner.m | 226 +++++++++--------- .../RelationshipScanner.m | 66 ++--- .../Singletons/MunkiRepositoryManager.m | 8 +- 6 files changed, 166 insertions(+), 181 deletions(-) diff --git a/MunkiAdmin/NSOperation Subclasses/FileCopyOperation.m b/MunkiAdmin/NSOperation Subclasses/FileCopyOperation.m index 4e37e9b..6b2efbb 100644 --- a/MunkiAdmin/NSOperation Subclasses/FileCopyOperation.m +++ b/MunkiAdmin/NSOperation Subclasses/FileCopyOperation.m @@ -37,19 +37,18 @@ - (id)initWithSourceURL:(NSURL *)src targetURL:(NSURL *)target { -(void)main { @try { @autoreleasepool { - NSFileManager *fm = [NSFileManager defaultManager]; - //NSFileManager *fm = [[NSFileManager alloc] init]; - [fm setDelegate:self]; - NSError *copyError = nil; - - if ([self.defaults boolForKey:@"debug"]) NSLog(@"Copying %@ to %@", self.fileName, [self.targetURL relativePath]); - - if ([fm copyItemAtURL:self.sourceURL toURL:self.targetURL error:©Error]) { - if ([self.defaults boolForKey:@"debug"]) NSLog(@"Done copying"); - } else { - if ([self.defaults boolForKey:@"debug"]) NSLog(@"Copy failed with error: %@",[copyError description]); - } - + NSFileManager *fm = [NSFileManager defaultManager]; + [fm setDelegate:self]; + NSError *copyError = nil; + + if ([self.defaults boolForKey:@"debug"]) NSLog(@"Copying %@ to %@", self.fileName, [self.targetURL relativePath]); + + if ([fm copyItemAtURL:self.sourceURL toURL:self.targetURL error:©Error]) { + if ([self.defaults boolForKey:@"debug"]) NSLog(@"Done copying"); + } else { + if ([self.defaults boolForKey:@"debug"]) NSLog(@"Copy failed with error: %@",[copyError description]); + } + } } @catch(...) { diff --git a/MunkiAdmin/NSOperation Subclasses/ManifestScanner.m b/MunkiAdmin/NSOperation Subclasses/ManifestScanner.m index bc60974..d34d443 100644 --- a/MunkiAdmin/NSOperation Subclasses/ManifestScanner.m +++ b/MunkiAdmin/NSOperation Subclasses/ManifestScanner.m @@ -29,10 +29,10 @@ - (id)initWithURL:(NSURL *)src { } -- (void)contextDidSave:(NSNotification*)notification +- (void)contextDidSave:(NSNotification*)notification { - [[self delegate] performSelectorOnMainThread:@selector(mergeChanges:) - withObject:notification + [[self delegate] performSelectorOnMainThread:@selector(mergeChanges:) + withObject:notification waitUntilDone:YES]; } @@ -339,7 +339,7 @@ -(void)main { } if ([self.delegate respondsToSelector:@selector(scannerDidProcessPkginfo)]) { - [self.delegate performSelectorOnMainThread:@selector(scannerDidProcessPkginfo) + [self.delegate performSelectorOnMainThread:@selector(scannerDidProcessPkginfo) withObject:nil waitUntilDone:YES]; } diff --git a/MunkiAdmin/NSOperation Subclasses/MunkiOperation.m b/MunkiAdmin/NSOperation Subclasses/MunkiOperation.m index 96afdfe..9b9a9d4 100644 --- a/MunkiAdmin/NSOperation Subclasses/MunkiOperation.m +++ b/MunkiAdmin/NSOperation Subclasses/MunkiOperation.m @@ -133,19 +133,19 @@ - (NSDictionary *)makepkginfo -(void)main { @try { @autoreleasepool { - + if ([self.command isEqualToString:@"makecatalogs"]) { NSString *results = [self makeCatalogs]; - if ([self.defaults boolForKey:@"debug"]) NSLog(@"MunkiOperation:makecatalogs"); + if ([self.defaults boolForKey:@"debug"]) NSLog(@"MunkiOperation:makecatalogs"); if ([self.defaults boolForKey:@"debugLogAllProperties"]) NSLog(@"MunkiOperation:makecatalogs:results: %@", results); } else if ([self.command isEqualToString:@"makepkginfo"]) { NSDictionary *pkginfo = [self makepkginfo]; - if ([self.defaults boolForKey:@"debug"]) NSLog(@"MunkiOperation:makepkginfo"); + if ([self.defaults boolForKey:@"debug"]) NSLog(@"MunkiOperation:makepkginfo"); if ([self.defaults boolForKey:@"debugLogAllProperties"]) NSLog(@"MunkiOperation:makepkginfo:results: %@", pkginfo); if ([self.delegate respondsToSelector:@selector(makepkginfoDidFinish:)]) { - [self.delegate performSelectorOnMainThread:@selector(makepkginfoDidFinish:) + [self.delegate performSelectorOnMainThread:@selector(makepkginfoDidFinish:) withObject:pkginfo waitUntilDone:YES]; } @@ -153,10 +153,10 @@ -(void)main { else if ([self.command isEqualToString:@"installsitem"]) { NSDictionary *pkginfo = [self makepkginfo]; - if ([self.defaults boolForKey:@"debug"]) NSLog(@"MunkiOperation:installsitem"); + if ([self.defaults boolForKey:@"debug"]) NSLog(@"MunkiOperation:installsitem"); if ([self.defaults boolForKey:@"debugLogAllProperties"]) NSLog(@"MunkiOperation:makepkginfo:results: %@", pkginfo); if ([self.delegate respondsToSelector:@selector(installsItemDidFinish:)]) { - [self.delegate performSelectorOnMainThread:@selector(installsItemDidFinish:) + [self.delegate performSelectorOnMainThread:@selector(installsItemDidFinish:) withObject:pkginfo waitUntilDone:YES]; } @@ -165,7 +165,7 @@ -(void)main { else { NSLog(@"Command not recognized: %@", self.command); } - + } } @catch(...) { diff --git a/MunkiAdmin/NSOperation Subclasses/PkginfoScanner.m b/MunkiAdmin/NSOperation Subclasses/PkginfoScanner.m index 65dea10..b246a87 100644 --- a/MunkiAdmin/NSOperation Subclasses/PkginfoScanner.m +++ b/MunkiAdmin/NSOperation Subclasses/PkginfoScanner.m @@ -53,10 +53,10 @@ - (id)initWithURL:(NSURL *)src } -- (void)contextDidSave:(NSNotification*)notification +- (void)contextDidSave:(NSNotification*)notification { - [[self delegate] performSelectorOnMainThread:@selector(mergeChanges:) - withObject:notification + [[self delegate] performSelectorOnMainThread:@selector(mergeChanges:) + withObject:notification waitUntilDone:YES]; } @@ -65,13 +65,13 @@ -(void)main { @try { @autoreleasepool { - + MunkiRepositoryManager *repoManager = [MunkiRepositoryManager sharedManager]; - MACoreDataManager *coreDataManager = [MACoreDataManager sharedManager]; - + MACoreDataManager *coreDataManager = [MACoreDataManager sharedManager]; + NSManagedObjectContext *moc = [[NSManagedObjectContext alloc] init]; - [moc setUndoManager:nil]; - [moc setMergePolicy:NSMergeByPropertyObjectTrumpMergePolicy]; + [moc setUndoManager:nil]; + [moc setMergePolicy:NSMergeByPropertyObjectTrumpMergePolicy]; [moc setPersistentStoreCoordinator:[[self delegate] persistentStoreCoordinator]]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(contextDidSave:) @@ -83,15 +83,15 @@ -(void)main if (self.sourceURL != nil) { - self.currentJobDescription = [NSString stringWithFormat:@"Reading file %@", self.fileName]; - if ([self.defaults boolForKey:@"debug"]) NSLog(@"Reading file %@", [self.sourceURL relativePath]); - self.sourceDict = [[NSDictionary alloc] initWithContentsOfURL:self.sourceURL]; + self.currentJobDescription = [NSString stringWithFormat:@"Reading file %@", self.fileName]; + if ([self.defaults boolForKey:@"debug"]) NSLog(@"Reading file %@", [self.sourceURL relativePath]); + self.sourceDict = [[NSDictionary alloc] initWithContentsOfURL:self.sourceURL]; } if (self.sourceDict != nil) { PackageMO *aNewPackage = [[PackageMO alloc] initWithEntity:packageEntityDescr insertIntoManagedObjectContext:moc]; - + aNewPackage.originalPkginfo = self.sourceDict; // ================================= @@ -108,88 +108,88 @@ -(void)main if ([self.defaults boolForKey:@"debugLogAllProperties"]) NSLog(@"%@ --> %@: nil (skipped)", self.fileName, key); } }]; - - // ================================================== - // Additional steps for deprecated forced_install - // ================================================== - if ((aNewPackage.munki_forced_install != nil) && (aNewPackage.munki_unattended_install != nil)) { - // pkginfo has both forced_install and unattended_install defined - if (aNewPackage.munki_forced_installValue != aNewPackage.munki_unattended_installValue) { - if ([self.defaults boolForKey:@"debug"]) NSLog(@"%@ has both forced_install and unattended_install defined with differing values. Favoring unattended_install", self.fileName); - aNewPackage.munki_forced_install = aNewPackage.munki_unattended_install; + + // ================================================== + // Additional steps for deprecated forced_install + // ================================================== + if ((aNewPackage.munki_forced_install != nil) && (aNewPackage.munki_unattended_install != nil)) { + // pkginfo has both forced_install and unattended_install defined + if (aNewPackage.munki_forced_installValue != aNewPackage.munki_unattended_installValue) { + if ([self.defaults boolForKey:@"debug"]) NSLog(@"%@ has both forced_install and unattended_install defined with differing values. Favoring unattended_install", self.fileName); + aNewPackage.munki_forced_install = aNewPackage.munki_unattended_install; + } } - } - else if ((aNewPackage.munki_forced_install != nil) && (aNewPackage.munki_unattended_install == nil)) { - // pkginfo has only forced_install defined - if ([self.defaults boolForKey:@"debug"]) NSLog(@"%@ has only forced_install defined. Migrating to unattended_install", self.fileName); - aNewPackage.munki_unattended_install = aNewPackage.munki_forced_install; - } - - // ================================================== - // Additional steps for deprecated forced_uninstall - // ================================================== - if ((aNewPackage.munki_forced_uninstall != nil) && (aNewPackage.munki_unattended_uninstall != nil)) { - // pkginfo has both values defined - if (aNewPackage.munki_forced_uninstallValue != aNewPackage.munki_unattended_uninstallValue) { - if ([self.defaults boolForKey:@"debug"]) NSLog(@"%@ has both forced_uninstall and unattended_uninstall defined with differing values. Favoring unattended_uninstall", self.fileName); - aNewPackage.munki_forced_uninstall = aNewPackage.munki_unattended_uninstall; + else if ((aNewPackage.munki_forced_install != nil) && (aNewPackage.munki_unattended_install == nil)) { + // pkginfo has only forced_install defined + if ([self.defaults boolForKey:@"debug"]) NSLog(@"%@ has only forced_install defined. Migrating to unattended_install", self.fileName); + aNewPackage.munki_unattended_install = aNewPackage.munki_forced_install; } - } - else if ((aNewPackage.munki_forced_uninstall != nil) && (aNewPackage.munki_unattended_uninstall == nil)) { - // pkginfo has only forced_uninstall defined - if ([self.defaults boolForKey:@"debug"]) NSLog(@"%@ has only forced_uninstall defined. Migrating to unattended_uninstall", self.fileName); - aNewPackage.munki_unattended_uninstall = aNewPackage.munki_forced_uninstall; - } - - - // Check if we have installer_item_location and expand it to absolute URL - if (aNewPackage.munki_installer_item_location != nil) { - aNewPackage.packageURL = [[[NSApp delegate] pkgsURL] URLByAppendingPathComponent:aNewPackage.munki_installer_item_location]; - } - - if (self.sourceURL != nil) { - aNewPackage.packageInfoURL = self.sourceURL; - NSDate *pkginfoDateCreated; - [aNewPackage.packageInfoURL getResourceValue:&pkginfoDateCreated forKey:NSURLCreationDateKey error:nil]; - aNewPackage.packageInfoDateCreated = pkginfoDateCreated; + // ================================================== + // Additional steps for deprecated forced_uninstall + // ================================================== + if ((aNewPackage.munki_forced_uninstall != nil) && (aNewPackage.munki_unattended_uninstall != nil)) { + // pkginfo has both values defined + if (aNewPackage.munki_forced_uninstallValue != aNewPackage.munki_unattended_uninstallValue) { + if ([self.defaults boolForKey:@"debug"]) NSLog(@"%@ has both forced_uninstall and unattended_uninstall defined with differing values. Favoring unattended_uninstall", self.fileName); + aNewPackage.munki_forced_uninstall = aNewPackage.munki_unattended_uninstall; + } + } + else if ((aNewPackage.munki_forced_uninstall != nil) && (aNewPackage.munki_unattended_uninstall == nil)) { + // pkginfo has only forced_uninstall defined + if ([self.defaults boolForKey:@"debug"]) NSLog(@"%@ has only forced_uninstall defined. Migrating to unattended_uninstall", self.fileName); + aNewPackage.munki_unattended_uninstall = aNewPackage.munki_forced_uninstall; + } - NSDate *pkginfoDateLastOpened; - [aNewPackage.packageInfoURL getResourceValue:&pkginfoDateLastOpened forKey:NSURLContentAccessDateKey error:nil]; - aNewPackage.packageInfoDateLastOpened = pkginfoDateLastOpened; - NSDate *pkginfoDateModified; - [aNewPackage.packageInfoURL getResourceValue:&pkginfoDateModified forKey:NSURLContentModificationDateKey error:nil]; - aNewPackage.packageInfoDateModified = pkginfoDateModified; + // Check if we have installer_item_location and expand it to absolute URL + if (aNewPackage.munki_installer_item_location != nil) { + aNewPackage.packageURL = [[[NSApp delegate] pkgsURL] URLByAppendingPathComponent:aNewPackage.munki_installer_item_location]; + } + if (self.sourceURL != nil) { + aNewPackage.packageInfoURL = self.sourceURL; + + NSDate *pkginfoDateCreated; + [aNewPackage.packageInfoURL getResourceValue:&pkginfoDateCreated forKey:NSURLCreationDateKey error:nil]; + aNewPackage.packageInfoDateCreated = pkginfoDateCreated; + + NSDate *pkginfoDateLastOpened; + [aNewPackage.packageInfoURL getResourceValue:&pkginfoDateLastOpened forKey:NSURLContentAccessDateKey error:nil]; + aNewPackage.packageInfoDateLastOpened = pkginfoDateLastOpened; + + NSDate *pkginfoDateModified; + [aNewPackage.packageInfoURL getResourceValue:&pkginfoDateModified forKey:NSURLContentModificationDateKey error:nil]; + aNewPackage.packageInfoDateModified = pkginfoDateModified; + } else { - NSString *newBaseName = [aNewPackage.munki_name stringByReplacingOccurrencesOfString:@" " withString:@"-"]; - NSString *newNameAndVersion = [NSString stringWithFormat:@"%@-%@", newBaseName, aNewPackage.munki_version]; - NSURL *newPkginfoURL = [[[NSApp delegate] pkgsInfoURL] URLByAppendingPathComponent:newNameAndVersion]; + NSString *newBaseName = [aNewPackage.munki_name stringByReplacingOccurrencesOfString:@" " withString:@"-"]; + NSString *newNameAndVersion = [NSString stringWithFormat:@"%@-%@", newBaseName, aNewPackage.munki_version]; + NSURL *newPkginfoURL = [[[NSApp delegate] pkgsInfoURL] URLByAppendingPathComponent:newNameAndVersion]; newPkginfoURL = [newPkginfoURL URLByAppendingPathExtension:@"plist"]; aNewPackage.packageInfoURL = newPkginfoURL; - - aNewPackage.packageInfoDateCreated = [NSDate date]; - aNewPackage.packageInfoDateModified = [NSDate date]; - aNewPackage.packageInfoDateLastOpened = [NSDate date]; + + aNewPackage.packageInfoDateCreated = [NSDate date]; + aNewPackage.packageInfoDateModified = [NSDate date]; + aNewPackage.packageInfoDateLastOpened = [NSDate date]; } - - if (aNewPackage.packageURL != nil) { - NSFileManager *fm = [NSFileManager defaultManager]; - if ([fm fileExistsAtPath:[aNewPackage.packageURL relativePath]]) { - NSDate *packageDateCreated; - [aNewPackage.packageURL getResourceValue:&packageDateCreated forKey:NSURLCreationDateKey error:nil]; - aNewPackage.packageDateCreated = packageDateCreated; - NSDate *packageDateLastOpened; - [aNewPackage.packageURL getResourceValue:&packageDateLastOpened forKey:NSURLContentAccessDateKey error:nil]; - aNewPackage.packageDateLastOpened = packageDateLastOpened; - - NSDate *packageDateModified; - [aNewPackage.packageURL getResourceValue:&packageDateModified forKey:NSURLContentModificationDateKey error:nil]; - aNewPackage.packageDateModified = packageDateModified; + if (aNewPackage.packageURL != nil) { + NSFileManager *fm = [NSFileManager defaultManager]; + if ([fm fileExistsAtPath:[aNewPackage.packageURL relativePath]]) { + NSDate *packageDateCreated; + [aNewPackage.packageURL getResourceValue:&packageDateCreated forKey:NSURLCreationDateKey error:nil]; + aNewPackage.packageDateCreated = packageDateCreated; + + NSDate *packageDateLastOpened; + [aNewPackage.packageURL getResourceValue:&packageDateLastOpened forKey:NSURLContentAccessDateKey error:nil]; + aNewPackage.packageDateLastOpened = packageDateLastOpened; + + NSDate *packageDateModified; + [aNewPackage.packageURL getResourceValue:&packageDateModified forKey:NSURLContentModificationDateKey error:nil]; + aNewPackage.packageDateModified = packageDateModified; + } } - } // ================================= // Get "receipts" items @@ -198,7 +198,7 @@ -(void)main [itemReceipts enumerateObjectsWithOptions:0 usingBlock:^(id aReceipt, NSUInteger idx, BOOL *stop) { ReceiptMO *aNewReceipt = [NSEntityDescription insertNewObjectForEntityForName:@"Receipt" inManagedObjectContext:moc]; aNewReceipt.package = aNewPackage; - aNewReceipt.originalIndexValue = idx; + aNewReceipt.originalIndexValue = idx; [repoManager.receiptKeyMappings enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) { id value = [aReceipt objectForKey:obj]; if (value != nil) { @@ -215,9 +215,9 @@ -(void)main // ================================= NSArray *installItems = [self.sourceDict objectForKey:@"installs"]; [installItems enumerateObjectsWithOptions:0 usingBlock:^(id anInstall, NSUInteger idx, BOOL *stop) { - InstallsItemMO *aNewInstallsItem = [coreDataManager createInstallsItemFromDictionary:anInstall inManagedObjectContext:moc]; - [aNewInstallsItem addPackagesObject:aNewPackage]; - aNewInstallsItem.originalIndexValue = idx; + InstallsItemMO *aNewInstallsItem = [coreDataManager createInstallsItemFromDictionary:anInstall inManagedObjectContext:moc]; + [aNewInstallsItem addPackagesObject:aNewPackage]; + aNewInstallsItem.originalIndexValue = idx; }]; // ================================= @@ -227,7 +227,7 @@ -(void)main [itemsToCopy enumerateObjectsWithOptions:0 usingBlock:^(id anItemToCopy, NSUInteger idx, BOOL *stop) { ItemToCopyMO *aNewItemToCopy = [NSEntityDescription insertNewObjectForEntityForName:@"ItemToCopy" inManagedObjectContext:moc]; aNewItemToCopy.package = aNewPackage; - aNewItemToCopy.originalIndexValue = idx; + aNewItemToCopy.originalIndexValue = idx; [repoManager.itemsToCopyKeyMappings enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) { id value = [anItemToCopy objectForKey:obj]; if (value != nil) { @@ -243,15 +243,15 @@ -(void)main aNewItemToCopy.munki_mode = [self.defaults stringForKey:@"items_to_copyMode"]; } }]; - - // ================================= + + // ================================= // Get "installer_choices_xml" items // ================================= NSArray *installerChoices = [self.sourceDict objectForKey:@"installer_choices_xml"]; [installerChoices enumerateObjectsWithOptions:0 usingBlock:^(id aChoice, NSUInteger idx, BOOL *stop) { InstallerChoicesItemMO *aNewInstallerChoice = [NSEntityDescription insertNewObjectForEntityForName:@"InstallerChoicesItem" inManagedObjectContext:moc]; aNewInstallerChoice.package = aNewPackage; - aNewInstallerChoice.originalIndexValue = idx; + aNewInstallerChoice.originalIndexValue = idx; [repoManager.installerChoicesKeyMappings enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) { id value = [aChoice objectForKey:obj]; if (value != nil) { @@ -267,10 +267,10 @@ -(void)main // ================================= // Get "catalogs" items // ================================= - self.currentJobDescription = [NSString stringWithFormat:@"Parsing catalogs for %@", self.fileName]; + self.currentJobDescription = [NSString stringWithFormat:@"Parsing catalogs for %@", self.fileName]; NSArray *catalogs = [self.sourceDict objectForKey:@"catalogs"]; [catalogs enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { - if ([self.defaults boolForKey:@"debug"]) NSLog(@"%@ catalogs item %lu --> Name: %@", self.fileName, (unsigned long)idx, obj); + if ([self.defaults boolForKey:@"debug"]) NSLog(@"%@ catalogs item %lu --> Name: %@", self.fileName, (unsigned long)idx, obj); NSFetchRequest *fetchForCatalogs = [[NSFetchRequest alloc] init]; [fetchForCatalogs setEntity:catalogEntityDescr]; NSPredicate *catalogTitlePredicate = [NSPredicate predicateWithFormat:@"title == %@", obj]; @@ -307,18 +307,18 @@ -(void)main newRequiredPkgInfo.originalIndexValue = idx; [aNewPackage addUpdateForObject:newRequiredPkgInfo]; }]; - - // ================================= + + // ================================= // Get "blocking_applications" items // ================================= NSArray *blocking_applications = [self.sourceDict objectForKey:@"blocking_applications"]; - if (!blocking_applications) { - aNewPackage.hasEmptyBlockingApplicationsValue = NO; - } else if ([blocking_applications count] == 0) { - aNewPackage.hasEmptyBlockingApplicationsValue = YES; - } else { - aNewPackage.hasEmptyBlockingApplicationsValue = NO; - } + if (!blocking_applications) { + aNewPackage.hasEmptyBlockingApplicationsValue = NO; + } else if ([blocking_applications count] == 0) { + aNewPackage.hasEmptyBlockingApplicationsValue = YES; + } else { + aNewPackage.hasEmptyBlockingApplicationsValue = NO; + } [blocking_applications enumerateObjectsWithOptions:0 usingBlock:^(id obj, NSUInteger idx, BOOL *stop) { if ([self.defaults boolForKey:@"debug"]) NSLog(@"%@ blocking_applications item %lu --> Name: %@", self.fileName, (unsigned long)idx, obj); StringObjectMO *newBlockingApplication = [NSEntityDescription insertNewObjectForEntityForName:@"StringObject" inManagedObjectContext:moc]; @@ -327,7 +327,7 @@ -(void)main newBlockingApplication.originalIndexValue = idx; [aNewPackage addBlockingApplicationsObject:newBlockingApplication]; }]; - + // ===================================== // Get "supported_architectures" items // ===================================== @@ -342,24 +342,24 @@ -(void)main }]; // ===================================== - // Get "installer_environment" items + // Get "installer_environment" items // ===================================== NSDictionary *installer_environment = [self.sourceDict objectForKey:@"installer_environment"]; - [installer_environment enumerateKeysAndObjectsWithOptions:0 usingBlock:^(id key, id obj, BOOL *stop) { - if ([self.defaults boolForKey:@"debug"]) NSLog(@"%@ installer_environment key: %@, value: %@", self.fileName, key, obj); - InstallerEnvironmentVariableMO *newInstallerEnvironmentVariable = [NSEntityDescription insertNewObjectForEntityForName:@"InstallerEnvironmentVariable" inManagedObjectContext:moc]; + [installer_environment enumerateKeysAndObjectsWithOptions:0 usingBlock:^(id key, id obj, BOOL *stop) { + if ([self.defaults boolForKey:@"debug"]) NSLog(@"%@ installer_environment key: %@, value: %@", self.fileName, key, obj); + InstallerEnvironmentVariableMO *newInstallerEnvironmentVariable = [NSEntityDescription insertNewObjectForEntityForName:@"InstallerEnvironmentVariable" inManagedObjectContext:moc]; newInstallerEnvironmentVariable.munki_installer_environment_key = key; - newInstallerEnvironmentVariable.munki_installer_environment_value = obj; + newInstallerEnvironmentVariable.munki_installer_environment_value = obj; [aNewPackage addInstallerEnvironmentVariablesObject:newInstallerEnvironmentVariable]; - }]; - + }]; + // ===================================== // Assimilate with existing // This is done only when adding new items to repo // ===================================== /* - Assimilator functions moved to class MunkiRepositoryManager - */ + Assimilator functions moved to class MunkiRepositoryManager + */ // ===================================== // Group packages by "name" property @@ -391,7 +391,7 @@ -(void)main } else { NSLog(@"Can't read pkginfo file %@", [self.sourceURL relativePath]); } - + // Save the context, this causes main app delegate to merge new items NSError *error = nil; if (![moc save:&error]) { @@ -408,7 +408,7 @@ -(void)main name:NSManagedObjectContextDidSaveNotification object:moc]; - moc = nil; + moc = nil; } } @catch(...) { diff --git a/MunkiAdmin/NSOperation Subclasses/RelationshipScanner.m b/MunkiAdmin/NSOperation Subclasses/RelationshipScanner.m index 7f11a03..15483e8 100644 --- a/MunkiAdmin/NSOperation Subclasses/RelationshipScanner.m +++ b/MunkiAdmin/NSOperation Subclasses/RelationshipScanner.m @@ -37,10 +37,10 @@ - (id)initWithMode:(NSInteger)mode { } -- (void)contextDidSave:(NSNotification*)notification +- (void)contextDidSave:(NSNotification*)notification { - [[self delegate] performSelectorOnMainThread:@selector(mergeChanges:) - withObject:notification + [[self delegate] performSelectorOnMainThread:@selector(mergeChanges:) + withObject:notification waitUntilDone:YES]; } @@ -100,15 +100,15 @@ - (void)scanManifests NSFetchRequest *getManifests = [[NSFetchRequest alloc] init]; [getManifests setEntity:manifestEntityDescr]; self.allManifests = [moc executeFetchRequest:getManifests error:nil]; - + NSFetchRequest *getApplications = [[NSFetchRequest alloc] init]; [getApplications setEntity:applicationEntityDescr]; self.allApplications = [moc executeFetchRequest:getApplications error:nil]; - + NSFetchRequest *getAllCatalogs = [[NSFetchRequest alloc] init]; [getAllCatalogs setEntity:catalogEntityDescr]; self.allCatalogs = [moc executeFetchRequest:getAllCatalogs error:nil]; - + NSFetchRequest *getPackages = [[NSFetchRequest alloc] init]; [getPackages setEntity:packageEntityDescr]; self.allPackages = [moc executeFetchRequest:getPackages error:nil]; @@ -209,7 +209,7 @@ - (void)scanManifests } if ([self.delegate respondsToSelector:@selector(relationshipScannerDidFinish:)]) { - [self.delegate performSelectorOnMainThread:@selector(relationshipScannerDidFinish:) + [self.delegate performSelectorOnMainThread:@selector(relationshipScannerDidFinish:) withObject:@"manifests" waitUntilDone:YES]; } @@ -244,7 +244,7 @@ - (void)scanPkginfos [getPackages setEntity:packageEntityDescr]; [getPackages setRelationshipKeyPathsForPrefetching:[NSArray arrayWithObjects:@"packageInfos", nil]]; self.allPackages = [moc executeFetchRequest:getPackages error:nil]; - + NSFetchRequest *getAllCatalogs = [[NSFetchRequest alloc] init]; [getAllCatalogs setEntity:catalogEntityDescr]; [getPackages setRelationshipKeyPathsForPrefetching:[NSArray arrayWithObjects:@"packageInfos", @"catalogInfos", @"packages", nil]]; @@ -271,27 +271,13 @@ - (void)scanPkginfos NSArray *catalogsFromPkginfo = [originalPkginfo objectForKey:@"catalogs"]; // Link to DirectoryMO object - /* - NSFetchRequest *request = [[NSFetchRequest alloc] init]; - [request setEntity:[NSEntityDescription entityForName:@"Directory" inManagedObjectContext:moc]]; - NSPredicate *parentPredicate = [NSPredicate predicateWithFormat:@"originalURL == %@", [currentPackage.packageInfoURL URLByDeletingLastPathComponent]]; - [request setPredicate:parentPredicate]; - NSUInteger foundItems = [moc countForFetchRequest:request error:nil]; - if (foundItems > 0) { - DirectoryMO *aDir = [[moc executeFetchRequest:request error:nil] objectAtIndex:0]; - //currentPackage.directory = aDir; - [currentPackage addSourceListItemsObject:aDir]; - [currentPackage addSourceListItemsObject:basePkginfoDirectory]; - } - [request release]; - */ DirectoryMO *aDir = [[MACoreDataManager sharedManager] directoryWithURL:[currentPackage.packageInfoURL URLByDeletingLastPathComponent] managedObjectContext:moc]; [currentPackage addSourceListItemsObject:aDir]; [currentPackage addSourceListItemsObject:allPackagesSmartDirectory]; - + // Loop through the catalog objects we already know about - + for (CatalogMO *aCatalog in self.allCatalogs) { if (![existingCatalogTitles containsObject:aCatalog.title]) { CatalogInfoMO *newCatalogInfo = [NSEntityDescription insertNewObjectForEntityForName:@"CatalogInfo" inManagedObjectContext:moc]; @@ -318,10 +304,10 @@ - (void)scanPkginfos } } - + // Loop through the "catalogs" key in the original pkginfo // and create new catalog objects if necessary - + [catalogsFromPkginfo enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { NSFetchRequest *fetchForCatalogs = [[NSFetchRequest alloc] init]; @@ -332,11 +318,11 @@ - (void)scanPkginfos NSUInteger numFoundCatalogs = [moc countForFetchRequest:fetchForCatalogs error:nil]; - + // There is an item in catalogs array which does not // yet have it's own CatalogMO object. // Create it and add dependencies for it - + if (numFoundCatalogs == 0) { CatalogMO *aNewCatalog = [NSEntityDescription insertNewObjectForEntityForName:@"Catalog" inManagedObjectContext:moc]; aNewCatalog.title = obj; @@ -388,7 +374,7 @@ - (void)scanPkginfos } if ([self.delegate respondsToSelector:@selector(relationshipScannerDidFinish:)]) { - [self.delegate performSelectorOnMainThread:@selector(relationshipScannerDidFinish:) + [self.delegate performSelectorOnMainThread:@selector(relationshipScannerDidFinish:) withObject:@"pkgs" waitUntilDone:YES]; } @@ -403,17 +389,17 @@ - (void)scanPkginfos -(void)main { @try { @autoreleasepool { - - switch (self.operationMode) { - case 0: - [self scanPkginfos]; - break; - case 1: - [self scanManifests]; - default: - break; - } - + + switch (self.operationMode) { + case 0: + [self scanPkginfos]; + break; + case 1: + [self scanManifests]; + default: + break; + } + } } @catch(...) { diff --git a/MunkiAdmin/Singletons/MunkiRepositoryManager.m b/MunkiAdmin/Singletons/MunkiRepositoryManager.m index 4677e81..1b21fc9 100644 --- a/MunkiAdmin/Singletons/MunkiRepositoryManager.m +++ b/MunkiAdmin/Singletons/MunkiRepositoryManager.m @@ -470,7 +470,7 @@ - (NSArray *)referencingPackageStringObjectsWithTitle:(NSString *)title } - (NSDictionary *)referencingItemsForPackage:(PackageMO *)aPackage -{ +{ NSString *packageName = aPackage.munki_name; NSString *packageNameWithVersion = aPackage.titleWithVersion; @@ -738,7 +738,7 @@ - (void)renamePackage:(PackageMO *)aPackage newName:(NSString *)newName cascade: // Get the packages parent application which represents a group of // packageinfos with the same name ApplicationMO *packageGroup = aPackage.parentApplication; - + if (shouldCascade) { // Check for existing ApplicationMO with the new name @@ -1635,8 +1635,8 @@ - (BOOL)canImportURL:(NSURL *)fileURL error:(NSError **)error recoverySuggestion, NSLocalizedRecoverySuggestionErrorKey, nil]; *error = [[NSError alloc] initWithDomain:@"MunkiAdmin Import Error Domain" - code:errorCode - userInfo:errorDictionary]; + code:errorCode + userInfo:errorDictionary]; } return NO; }