Skip to content

Commit

Permalink
eliminate Xcode 4.6.1 build analyze warning.
Browse files Browse the repository at this point in the history
  • Loading branch information
n-miyo committed Apr 12, 2013
1 parent 9731b2e commit 1fec82a
Showing 1 changed file with 39 additions and 23 deletions.
62 changes: 39 additions & 23 deletions TPMigrationManager/TPMigrationManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ - (NSManagedObjectModel *)modelFromMetadata:(NSDictionary *)metadata
mergedModelFromBundles:bundlesForModel
forStoreMetadata:metadata];

if (model == nil) {
if (model == nil && error) {
*error =
[NSError errorWithDomain:NSCocoaErrorDomain
code:NSMigrationMissingSourceModelError
Expand All @@ -556,7 +556,9 @@ - (NSMappingModel *)mappingModelWithSourceModel:(NSManagedObjectModel *)sourceMo
{
NSMappingModel *mappingModel = nil;
if (inferMapping) {
*error = nil;
if (error) {
*error = nil;
}
mappingModel =
[NSMappingModel
inferredMappingModelForSourceModel:sourceModel
Expand All @@ -569,7 +571,7 @@ - (NSMappingModel *)mappingModelWithSourceModel:(NSManagedObjectModel *)sourceMo
mappingModelFromBundles:bundlesForMappingModel
forSourceModel:sourceModel
destinationModel:destinationModel];
if (mappingModel == nil) {
if (mappingModel == nil && error) {
*error =
[NSError errorWithDomain:NSCocoaErrorDomain
code:NSMigrationMissingMappingModelError
Expand All @@ -579,24 +581,27 @@ - (NSMappingModel *)mappingModelWithSourceModel:(NSManagedObjectModel *)sourceMo
return mappingModel;
}

- (void)eliminateWorkingStoreWithError:(NSError **)error
- (BOOL)eliminateWorkingStoreWithError:(NSError **)error
{
BOOL r = YES;
NSURL *destinationStoreURL = self.workingStoreURL;
BOOL exist =
[destinationStoreURL checkResourceIsReachableAndReturnError:nil];
if (exist) {
// eliminate old WORKING file.
[[NSFileManager defaultManager]
removeItemAtURL:destinationStoreURL
error:error];
r = [[NSFileManager defaultManager]
removeItemAtURL:destinationStoreURL
error:error];
}
return r;
}

- (void)replaceItemAtPath:(NSString *)srcPath
- (BOOL)replaceItemAtPath:(NSString *)srcPath
toPath:(NSString *)dstPath
backupExtension:(NSString *)extension
error:(NSError **)error
{
NSError *e;
NSFileManager *man = [NSFileManager defaultManager];
NSString *srcBackupPath =
[NSString stringWithFormat:@"%@%@", srcPath, extension];
Expand All @@ -605,33 +610,44 @@ - (void)replaceItemAtPath:(NSString *)srcPath
eliminatePath = srcBackupPath;
}
if ([man fileExistsAtPath:eliminatePath]) {
*error = nil;
[man removeItemAtPath:eliminatePath error:error];
if (*error) {
return;
e = nil;
[man removeItemAtPath:eliminatePath error:&e];
if (e) {
if (error) {
*error = e;
}
return NO;
}
}
if (extension) {
*error = nil;
[man moveItemAtPath:srcPath toPath:srcBackupPath error:error];
if (*error) {
return;
e = nil;
[man moveItemAtPath:srcPath toPath:srcBackupPath error:&e];
if (e) {
if (error) {
*error = e;
}
return NO;
}
}
*error = nil;
[man moveItemAtPath:dstPath toPath:srcPath error:error];
if (error) {
*error = nil;
}
return [man moveItemAtPath:dstPath toPath:srcPath error:error];
}

- (BOOL)eliminateExistFileURL:(NSURL *)fileURL error:(NSError **)error
{
*error = nil;
BOOL exist = [fileURL checkResourceIsReachableAndReturnError:error];
NSError *e = nil;
BOOL exist = [fileURL checkResourceIsReachableAndReturnError:&e];
if (!exist) {
return YES; // no need to do.
}
*error = nil;
[[NSFileManager defaultManager] removeItemAtURL:fileURL error:error];
if (error) {
e = nil;
[[NSFileManager defaultManager] removeItemAtURL:fileURL error:&e];
if (e) {
if (error) {
*error = e;
}
return NO;
}
return YES;
Expand Down

0 comments on commit 1fec82a

Please sign in to comment.