Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

adds a hook in IRDataStore’s file operations to allow magic number de…

…tection against files without extensions from application subclass
  • Loading branch information...
commit 2207cbe9226250cfde48bfdd3f7c39e4d179dabf 1 parent 7e0e173
Evadne Wu authored
View
5 IRFoundations/IRDataStore+FileOperations.h
@@ -40,4 +40,9 @@
- (BOOL) updateObject:(NSManagedObject *)anObject inContext:(NSManagedObjectContext *)aContext takingBlobFromTemporaryFile:(NSString *)aPath usingResourceType:(NSString *)utiType forKeyPath:(NSString *)fileKeyPath matchingURL:(NSURL *)anURL forKeyPath:(NSString *)urlKeyPath error:(NSError **)outError;
+
+// Hook for MagicKit integration thru custom application subclass
+
+- (NSString *) pathExtensionForFileAtPath:(NSString *)aPath;
+
@end
View
39 IRFoundations/IRDataStore+FileOperations.m
@@ -208,24 +208,31 @@ - (BOOL) updateObject:(NSManagedObject *)anObject inContext:(NSManagedObjectCont
if (utiType)
preferredExtension = (__bridge_transfer NSString *)(UTTypeCopyPreferredTagWithClass((__bridge CFStringRef)utiType, kUTTagClassFilenameExtension));
+ if (!preferredExtension)
+ preferredExtension = [self pathExtensionForFileAtPath:[fileURL path]];
+
if (preferredExtension) {
NSURL *newFileURL = [NSURL fileURLWithPath:[[[fileURL path] stringByDeletingPathExtension] stringByAppendingPathExtension:preferredExtension]];
- NSError *movingError = nil;
- BOOL didMove = [[NSFileManager defaultManager] moveItemAtURL:fileURL toURL:newFileURL error:&movingError];
- if (!didMove) {
-
- if (outError)
- *outError = [NSError errorWithDomain:@"com.iridia.dataStore" code:0 userInfo:[NSDictionary dictionaryWithObjectsAndKeys:
- @"Could not rename the underlying persistent file", NSLocalizedDescriptionKey,
- nil]];
-
- return NO;
-
+ if (![fileURL isEqual:newFileURL]) {
+
+ NSError *movingError = nil;
+ BOOL didMove = [[NSFileManager defaultManager] moveItemAtURL:fileURL toURL:newFileURL error:&movingError];
+ if (!didMove) {
+
+ if (outError)
+ *outError = [NSError errorWithDomain:@"com.iridia.dataStore" code:0 userInfo:[NSDictionary dictionaryWithObjectsAndKeys:
+ @"Could not rename the underlying persistent file", NSLocalizedDescriptionKey,
+ nil]];
+
+ return NO;
+
+ }
+
+ fileURL = newFileURL;
+
}
-
- fileURL = newFileURL;
}
@@ -235,4 +242,10 @@ - (BOOL) updateObject:(NSManagedObject *)anObject inContext:(NSManagedObjectCont
}
+- (NSString *) pathExtensionForFileAtPath:(NSString *)aPath {
+
+ return [aPath pathExtension];
+
+}
+
@end
Please sign in to comment.
Something went wrong with that request. Please try again.