Fix removeTree not working for symbolic links and added tests

I accidently broke this a few commits ago where I inserted a return value for it
This commit is contained in:
Zorg
2015-04-17 02:28:03 -04:00
parent 8a4f4677bd
commit 285cd3063f
2 changed files with 35 additions and 1 deletions
+5 -1
View File
@@ -195,7 +195,11 @@ extern NSString *hashOfTree(NSString *path)
BOOL removeTree(NSString *path)
{
NSFileManager *fileManager = [NSFileManager defaultManager];
return ![fileManager fileExistsAtPath:path] ? YES : [fileManager removeItemAtPath:path error:nil];
// Don't use fileExistsForPath: because it will try to follow symbolic links
if (![fileManager attributesOfItemAtPath:path error:nil]) {
return YES;
}
return [fileManager removeItemAtPath:path error:nil];
}
BOOL copyTree(NSString *source, NSString *dest)
+30
View File
@@ -434,6 +434,36 @@ typedef void (^SUDeltaHandler)(NSFileManager *fileManager, NSString *sourceDirec
}];
}
- (void)testRemovingSymlink
{
[self createAndApplyPatchWithHandler:^(NSFileManager *fileManager, NSString *sourceDirectory, NSString *destinationDirectory) {
NSString *sourceFile = [sourceDirectory stringByAppendingPathComponent:@"A"];
NSError *error = nil;
if (![fileManager createSymbolicLinkAtPath:sourceFile withDestinationPath:@"B" error:&error]) {
NSLog(@"Error in creating symlink: %@", error);
XCTFail(@"Failed to create symlink");
}
XCTAssertFalse([self testDirectoryHashEqualityWithSource:sourceDirectory destination:destinationDirectory]);
}];
}
- (void)testAddingSymlink
{
[self createAndApplyPatchWithHandler:^(NSFileManager *fileManager, NSString *sourceDirectory, NSString *destinationDirectory) {
NSString *destinationFile = [destinationDirectory stringByAppendingPathComponent:@"A"];
NSError *error = nil;
if (![fileManager createSymbolicLinkAtPath:destinationFile withDestinationPath:@"B" error:&error]) {
NSLog(@"Error in creating symlink: %@", error);
XCTFail(@"Failed to create symlink");
}
XCTAssertFalse([self testDirectoryHashEqualityWithSource:sourceDirectory destination:destinationDirectory]);
}];
}
- (void)testSmallFilePermissionChangeWithNoContentChange
{
[self createAndApplyPatchWithHandler:^(NSFileManager *fileManager, NSString *sourceDirectory, NSString *destinationDirectory) {