Skip to content

Commit fa6182e

Browse files
Benoit CerrinaPieter de Bie
authored andcommitted
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.
1 parent 34f72ba commit fa6182e

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

PBGitRepository.m

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,11 @@ + (NSURL*)baseDirForURL:(NSURL*)repositoryURL;
7272
return repositoryURL;
7373
}
7474

75-
- (BOOL)readFromFileWrapper:(NSFileWrapper *)fileWrapper ofType:(NSString *)typeName error:(NSError **)outError
75+
// NSFileWrapper is broken and doesn't work when called on a directory containing a large number of directories and files.
76+
//because of this it is safer to implement readFromURL than readFromFileWrapper.
77+
//Because NSFileManager does not attempt to recursively open all directories and file when fileExistsAtPath is called
78+
//this works much better.
79+
- (BOOL)readFromURL:(NSURL *)absoluteURL ofType:(NSString *)typeName error:(NSError **)outError
7680
{
7781
BOOL success = NO;
7882

@@ -85,11 +89,12 @@ - (BOOL)readFromFileWrapper:(NSFileWrapper *)fileWrapper ofType:(NSString *)type
8589
}
8690
return NO;
8791
}
88-
89-
if (![fileWrapper isDirectory]) {
92+
BOOL lIsDirectory = FALSE;
93+
[[NSFileManager defaultManager] fileExistsAtPath:[absoluteURL path] isDirectory:&lIsDirectory];
94+
if (!lIsDirectory) {
9095
if (outError) {
91-
NSDictionary* userInfo = [NSDictionary dictionaryWithObject:[NSString stringWithFormat:@"Reading files is not supported.", [fileWrapper filename]]
92-
forKey:NSLocalizedRecoverySuggestionErrorKey];
96+
NSDictionary* userInfo = [NSDictionary dictionaryWithObject:@"Reading files is not supported."
97+
forKey:NSLocalizedRecoverySuggestionErrorKey];
9398
*outError = [NSError errorWithDomain:PBGitRepositoryErrorDomain code:0 userInfo:userInfo];
9499
}
95100
} else {
@@ -98,8 +103,8 @@ - (BOOL)readFromFileWrapper:(NSFileWrapper *)fileWrapper ofType:(NSString *)type
98103
[self setFileURL:gitDirURL];
99104
success = YES;
100105
} else if (outError) {
101-
NSDictionary* userInfo = [NSDictionary dictionaryWithObject:[NSString stringWithFormat:@"%@ does not appear to be a git repository.", [fileWrapper filename]]
102-
forKey:NSLocalizedRecoverySuggestionErrorKey];
106+
NSDictionary* userInfo = [NSDictionary dictionaryWithObject:[NSString stringWithFormat:@"%@ does not appear to be a git repository.", [self fileName]]
107+
forKey:NSLocalizedRecoverySuggestionErrorKey];
103108
*outError = [NSError errorWithDomain:PBGitRepositoryErrorDomain code:0 userInfo:userInfo];
104109
}
105110

0 commit comments

Comments
 (0)