@@ -37,7 +37,9 @@ - (instancetype)init {
3737}
3838
3939- (BOOL )removeItemAtPath : (NSString *)path {
40- [self .fileSystemDict removeObjectForKey: path];
40+ @synchronized (self) {
41+ [self .fileSystemDict removeObjectForKey: path];
42+ }
4143
4244 self.removeCount += 1 ;
4345
@@ -49,54 +51,63 @@ - (BOOL)removeItemAtPath:(NSString *)path {
4951}
5052
5153- (BOOL )fileExistsAtPath : (NSString *)path {
52- return self.fileSystemDict [path] != nil ;
54+ @synchronized (self) {
55+ return self.fileSystemDict [path] != nil ;
56+ }
5357}
5458
5559- (BOOL )createFileAtPath : (NSString *)path
5660 contents : (NSData *)data
5761 attributes : (NSDictionary <NSFileAttributeKey, id> *)attr {
58- self.fileSystemDict [path] = data;
62+ @synchronized (self) {
63+ self.fileSystemDict [path] = data;
64+ }
5965 return YES ;
6066}
6167
6268- (NSArray *)activePathContents {
63- NSMutableArray *pathsWithActive = [[NSMutableArray alloc ] init ];
64- for (NSString *path in [_fileSystemDict allKeys ]) {
65- if ([path containsString: @" v5/reports/active" ]) {
66- [pathsWithActive addObject: path];
69+ @synchronized (self) {
70+ NSMutableArray *pathsWithActive = [[NSMutableArray alloc ] init ];
71+ for (NSString *path in [_fileSystemDict allKeys ]) {
72+ if ([path containsString: @" v5/reports/active" ]) {
73+ [pathsWithActive addObject: path];
74+ }
6775 }
76+ return pathsWithActive;
6877 }
69-
70- return pathsWithActive;
7178}
7279
7380- (NSData *)dataWithContentsOfFile : (NSString *)path {
74- return self.fileSystemDict [path];
81+ @synchronized (self) {
82+ return self.fileSystemDict [path];
83+ }
7584}
7685
7786- (void )enumerateFilesInDirectory : (NSString *)directory
7887 usingBlock : (void (^)(NSString *filePath, NSString *extension))block {
79- NSArray <NSString *> *filteredPaths = [self .fileSystemDict.allKeys
80- filteredArrayUsingPredicate: [NSPredicate predicateWithBlock: ^BOOL (NSString *path,
81- NSDictionary *bindings) {
82- return [path hasPrefix: directory];
83- }]];
84-
85- for (NSString *path in filteredPaths) {
86- NSString *extension;
87- NSString *fullPath;
88-
89- // Skip files that start with a dot. This is important, because if you try to move a .DS_Store
90- // file, it will fail if the target directory also has a .DS_Store file in it. Plus, its
91- // wasteful, because we don't care about dot files.
92- if ([path hasPrefix: @" ." ]) {
93- continue ;
94- }
95-
96- extension = [path pathExtension ];
97- fullPath = [directory stringByAppendingPathComponent: path];
98- if (block) {
99- block (fullPath, extension);
88+ @synchronized (self) {
89+ NSArray <NSString *> *filteredPaths = [self .fileSystemDict.allKeys
90+ filteredArrayUsingPredicate: [NSPredicate predicateWithBlock: ^BOOL (NSString *path,
91+ NSDictionary *bindings) {
92+ return [path hasPrefix: directory];
93+ }]];
94+
95+ for (NSString *path in filteredPaths) {
96+ NSString *extension;
97+ NSString *fullPath;
98+
99+ // Skip files that start with a dot. This is important, because if you try to move a
100+ // .DS_Store file, it will fail if the target directory also has a .DS_Store file in
101+ // it. Plus, its wasteful, because we don't care about dot files.
102+ if ([path hasPrefix: @" ." ]) {
103+ continue ;
104+ }
105+
106+ extension = [path pathExtension ];
107+ fullPath = [directory stringByAppendingPathComponent: path];
108+ if (block) {
109+ block (fullPath, extension);
110+ }
100111 }
101112 }
102113}
0 commit comments