PBGitRepository: Fix opening of large directories due to bug in NSFileWrapper.

This commit changes  readFromFileWrapper:ofType:error: to readFromURL:ofType:error:.

The default implementation of readFromURL calls readFromFileWrapper, but a bug
in NSFileWrapper makes this fail with repositories with a large number of files
(not sure if the fact that those files were in subdirectories matter or not).

So instead we skip the whole FileWrapper thing, which we don't really use anyway,
and just use the URL.
This commit is contained in:
Benoit Cerrina
2009-06-20 16:02:03 -04:00
committed by Pieter de Bie
parent 34f72ba27a
commit fa6182e2a4
+12 -7
View File
@@ -72,7 +72,11 @@ NSString* PBGitRepositoryErrorDomain = @"GitXErrorDomain";
return repositoryURL;
}
- (BOOL)readFromFileWrapper:(NSFileWrapper *)fileWrapper ofType:(NSString *)typeName error:(NSError **)outError
// NSFileWrapper is broken and doesn't work when called on a directory containing a large number of directories and files.
//because of this it is safer to implement readFromURL than readFromFileWrapper.
//Because NSFileManager does not attempt to recursively open all directories and file when fileExistsAtPath is called
//this works much better.
- (BOOL)readFromURL:(NSURL *)absoluteURL ofType:(NSString *)typeName error:(NSError **)outError
{
BOOL success = NO;
@@ -85,11 +89,12 @@ NSString* PBGitRepositoryErrorDomain = @"GitXErrorDomain";
}
return NO;
}
if (![fileWrapper isDirectory]) {
BOOL lIsDirectory = FALSE;
[[NSFileManager defaultManager] fileExistsAtPath:[absoluteURL path] isDirectory:&lIsDirectory];
if (!lIsDirectory) {
if (outError) {
NSDictionary* userInfo = [NSDictionary dictionaryWithObject:[NSString stringWithFormat:@"Reading files is not supported.", [fileWrapper filename]]
forKey:NSLocalizedRecoverySuggestionErrorKey];
NSDictionary* userInfo = [NSDictionary dictionaryWithObject:@"Reading files is not supported."
forKey:NSLocalizedRecoverySuggestionErrorKey];
*outError = [NSError errorWithDomain:PBGitRepositoryErrorDomain code:0 userInfo:userInfo];
}
} else {
@@ -98,8 +103,8 @@ NSString* PBGitRepositoryErrorDomain = @"GitXErrorDomain";
[self setFileURL:gitDirURL];
success = YES;
} else if (outError) {
NSDictionary* userInfo = [NSDictionary dictionaryWithObject:[NSString stringWithFormat:@"%@ does not appear to be a git repository.", [fileWrapper filename]]
forKey:NSLocalizedRecoverySuggestionErrorKey];
NSDictionary* userInfo = [NSDictionary dictionaryWithObject:[NSString stringWithFormat:@"%@ does not appear to be a git repository.", [self fileName]]
forKey:NSLocalizedRecoverySuggestionErrorKey];
*outError = [NSError errorWithDomain:PBGitRepositoryErrorDomain code:0 userInfo:userInfo];
}