@@ -27,9 +27,9 @@ - (BOOL)readFromURL:(NSURL *)absoluteURL ofType:(NSString *)typeName error:(NSEr
27
27
return PBReturnError (outError, @" Unable to find git" , [PBGitBinary notFoundError ], nil );
28
28
}
29
29
30
- BOOL isDirectory = FALSE ;
31
- [[ NSFileManager defaultManager ] fileExistsAtPath: [absoluteURL path ] isDirectory: &isDirectory];
32
- if (!isDirectory) {
30
+ NSNumber * isDirectory;
31
+
32
+ if (![absoluteURL getResourceValue: & isDirectory forKey: NSURLIsDirectoryKey error: outError] || ![isDirectory boolValue ] ) {
33
33
return PBReturnError (outError, @" Unable to read files" , @" Reading files is not supported" , nil );
34
34
}
35
35
@@ -52,6 +52,8 @@ - (BOOL)readFromURL:(NSURL *)absoluteURL ofType:(NSString *)typeName error:(NSEr
52
52
}
53
53
54
54
55
+ [NSFileCoordinator addFilePresenter: self ];
56
+
55
57
return YES ;
56
58
}
57
59
@@ -60,6 +62,8 @@ - (void)close
60
62
/* FIXME: Check that this deallocs the repo */
61
63
// [revisionList cleanup];
62
64
65
+ [NSFileCoordinator removeFilePresenter: self ];
66
+
63
67
[super close ];
64
68
}
65
69
@@ -223,4 +227,28 @@ - (void)findInModeScriptCommand:(NSScriptCommand *)command
223
227
}
224
228
}
225
229
230
+ #pragma mark - NSFilePresenter
231
+
232
+ - (void )accommodatePresentedItemDeletionWithCompletionHandler : (void (^)(NSError *errorOrNil))completionHandler
233
+ {
234
+ // The repository was deleted, close the document
235
+ dispatch_async (dispatch_get_main_queue (), ^{
236
+ [self close ];
237
+
238
+ if (completionHandler) {
239
+ completionHandler (nil );
240
+ }
241
+ });
242
+ }
243
+
244
+ - (void )presentedItemDidMoveToURL : (NSURL *)newURL
245
+ {
246
+ // Close the document if the repository gets moved
247
+ // It would be better to automatically update the document, but that's a bit tricky with the current architecture
248
+ // If PBGitRepositoryDocument and PBGitRepository get unified then it would make this much easier
249
+ dispatch_async (dispatch_get_main_queue (), ^{
250
+ [self close ];
251
+ });
252
+ }
253
+
226
254
@end
0 commit comments