]> git.saurik.com Git - uikittools.git/blob - libuicache.mm
Isolate stash directory from codesign validation.
[uikittools.git] / libuicache.mm
1 #include <objc/runtime.h>
2 #include <Foundation/Foundation.h>
3
4 @interface MIFileManager
5 + (MIFileManager *) defaultManager;
6 - (NSURL *) destinationOfSymbolicLinkAtURL:(NSURL *)url error:(NSError *)error;
7 @end
8
9 static Class $MIFileManager;
10
11 static NSArray *(*_MIFileManager$urlsForItemsInDirectoryAtURL$ignoringSymlinks$error$)(MIFileManager *self, SEL _cmd, NSURL *url, BOOL ignoring, NSError *error);
12
13 static NSArray *$MIFileManager$urlsForItemsInDirectoryAtURL$ignoringSymlinks$error$(MIFileManager *self, SEL _cmd, NSURL *url, BOOL ignoring, NSError *error) {
14 MIFileManager *manager(reinterpret_cast<MIFileManager *>([$MIFileManager defaultManager]));
15 NSURL *destiny([manager destinationOfSymbolicLinkAtURL:url error:NULL]);
16 if (destiny == nil)
17 return _MIFileManager$urlsForItemsInDirectoryAtURL$ignoringSymlinks$error$(self, _cmd, url, YES, error);
18
19 NSArray *prefix([url pathComponents]);
20 size_t skip([[destiny pathComponents] count]);
21 NSMutableArray *items([NSMutableArray array]);
22 for (NSURL *item in _MIFileManager$urlsForItemsInDirectoryAtURL$ignoringSymlinks$error$(self, _cmd, destiny, YES, error)) {
23 NSArray *components([item pathComponents]);
24 [items addObject:[NSURL fileURLWithPathComponents:[prefix arrayByAddingObjectsFromArray:[components subarrayWithRange:NSMakeRange(skip, [components count] - skip)]]]];
25 }
26
27 return items;
28 }
29
30 __attribute__((__constructor__))
31 static void initialize() {
32 $MIFileManager = objc_getClass("MIFileManager");
33 SEL sel(@selector(urlsForItemsInDirectoryAtURL:ignoringSymlinks:error:));
34 Method method(class_getInstanceMethod($MIFileManager, sel));
35 _MIFileManager$urlsForItemsInDirectoryAtURL$ignoringSymlinks$error$ = reinterpret_cast<NSArray *(*)(MIFileManager *, SEL, NSURL *, BOOL, NSError *)>(method_getImplementation(method));
36 method_setImplementation(method, reinterpret_cast<IMP>(&$MIFileManager$urlsForItemsInDirectoryAtURL$ignoringSymlinks$error$));
37 }