1414
1515#import " Crashlytics/UnitTests/Mocks/FIRCLSMockFileManager.h"
1616
17+ NSNotificationName const FIRCLSMockFileManagerDidRemoveItemNotification =
18+ @" FIRCLSMockFileManagerDidRemoveItemNotification" ;
19+
1720@interface FIRCLSMockFileManager ()
1821
1922@property (nonatomic ) NSMutableDictionary <NSString *, NSData *> *fileSystemDict;
@@ -34,68 +37,82 @@ - (instancetype)init {
3437}
3538
3639- (BOOL )removeItemAtPath : (NSString *)path {
37- [self .fileSystemDict removeObjectForKey: path];
38-
39- self.removeCount += 1 ;
40-
41- // If we set up the expectation, and we went over the expected count or removes, fulfill the
42- // expectation
43- if (self.removeExpectation && self.removeCount >= self.expectedRemoveCount ) {
44- [self .removeExpectation fulfill ];
40+ @synchronized (self) {
41+ [self .fileSystemDict removeObjectForKey: path];
42+ self.removeCount += 1 ;
43+
44+ // If we set up the expectation, and we went over the expected count or removes, fulfill the
45+ // expectation
46+ if (self.removeExpectation && self.removeCount >= self.expectedRemoveCount ) {
47+ [self .removeExpectation fulfill ];
48+ }
4549 }
4650
51+ [[NSNotificationCenter defaultCenter ]
52+ postNotificationName: FIRCLSMockFileManagerDidRemoveItemNotification
53+ object: self ];
54+
4755 return YES ;
4856}
4957
5058- (BOOL )fileExistsAtPath : (NSString *)path {
51- return self.fileSystemDict [path] != nil ;
59+ @synchronized (self) {
60+ return self.fileSystemDict [path] != nil ;
61+ }
5262}
5363
5464- (BOOL )createFileAtPath : (NSString *)path
5565 contents : (NSData *)data
5666 attributes : (NSDictionary <NSFileAttributeKey, id> *)attr {
57- self.fileSystemDict [path] = data;
67+ @synchronized (self) {
68+ self.fileSystemDict [path] = data;
69+ }
5870 return YES ;
5971}
6072
6173- (NSArray *)activePathContents {
62- NSMutableArray *pathsWithActive = [[NSMutableArray alloc ] init ];
63- for (NSString *path in [_fileSystemDict allKeys ]) {
64- if ([path containsString: @" v5/reports/active" ]) {
65- [pathsWithActive addObject: path];
74+ @synchronized (self) {
75+ NSMutableArray *pathsWithActive = [[NSMutableArray alloc ] init ];
76+ for (NSString *path in [_fileSystemDict allKeys ]) {
77+ if ([path containsString: @" v5/reports/active" ]) {
78+ [pathsWithActive addObject: path];
79+ }
6680 }
81+ return pathsWithActive;
6782 }
68-
69- return pathsWithActive;
7083}
7184
7285- (NSData *)dataWithContentsOfFile : (NSString *)path {
73- return self.fileSystemDict [path];
86+ @synchronized (self) {
87+ return self.fileSystemDict [path];
88+ }
7489}
7590
7691- (void )enumerateFilesInDirectory : (NSString *)directory
7792 usingBlock : (void (^)(NSString *filePath, NSString *extension))block {
78- NSArray <NSString *> *filteredPaths = [self .fileSystemDict.allKeys
79- filteredArrayUsingPredicate: [NSPredicate predicateWithBlock: ^BOOL (NSString *path,
80- NSDictionary *bindings) {
81- return [path hasPrefix: directory];
82- }]];
83-
84- for (NSString *path in filteredPaths) {
85- NSString *extension;
86- NSString *fullPath;
87-
88- // Skip files that start with a dot. This is important, because if you try to move a .DS_Store
89- // file, it will fail if the target directory also has a .DS_Store file in it. Plus, its
90- // wasteful, because we don't care about dot files.
91- if ([path hasPrefix: @" ." ]) {
92- continue ;
93- }
94-
95- extension = [path pathExtension ];
96- fullPath = [directory stringByAppendingPathComponent: path];
97- if (block) {
98- block (fullPath, extension);
93+ @synchronized (self) {
94+ NSArray <NSString *> *filteredPaths = [self .fileSystemDict.allKeys
95+ filteredArrayUsingPredicate: [NSPredicate predicateWithBlock: ^BOOL (NSString *path,
96+ NSDictionary *bindings) {
97+ return [path hasPrefix: directory];
98+ }]];
99+
100+ for (NSString *path in filteredPaths) {
101+ NSString *extension;
102+ NSString *fullPath;
103+
104+ // Skip files that start with a dot. This is important, because if you try to move a
105+ // .DS_Store file, it will fail if the target directory also has a .DS_Store file in
106+ // it. Plus, it's wasteful, because we don't care about dot files.
107+ if ([path hasPrefix: @" ." ]) {
108+ continue ;
109+ }
110+
111+ extension = [path pathExtension ];
112+ fullPath = [directory stringByAppendingPathComponent: path];
113+ if (block) {
114+ block (fullPath, extension);
115+ }
99116 }
100117 }
101118}
0 commit comments