Revision ce32510a ChatSecure/Classes/Controllers/OTRMediaFileManager.m
ChatSecure/Classes/Controllers/OTRMediaFileManager.m | ||
---|---|---|
128 | 128 |
}]; |
129 | 129 |
} |
130 | 130 |
|
131 |
//#865 |
|
132 |
- (void)deleteDataForItem:(OTRMediaItem *)mediaItem |
|
133 |
buddyUniqueId:(NSString *)buddyUniqueId |
|
134 |
completion:(void (^)(BOOL success, NSError * _Nullable error))completion |
|
135 |
completionQueue:(nullable dispatch_queue_t)completionQueue { |
|
136 |
if (!completionQueue) { |
|
137 |
completionQueue = dispatch_get_main_queue(); |
|
138 |
} |
|
139 |
[self performAsyncWrite:^{ |
|
140 |
NSString *path = [[self class] pathForMediaItem:mediaItem buddyUniqueId:buddyUniqueId]; |
|
141 |
if (![path length]) { |
|
142 |
NSError *error = [NSError errorWithDomain:kOTRErrorDomain code:150 userInfo:@{NSLocalizedDescriptionKey:@"Unable to create file path"}]; |
|
143 |
if (completion) { |
|
144 |
dispatch_async(completionQueue, ^{ |
|
145 |
completion(NO, error); |
|
146 |
}); |
|
147 |
} |
|
148 |
return; |
|
149 |
} |
|
150 |
|
|
151 |
BOOL fileExists = [self.ioCipher fileExistsAtPath:path isDirectory:NULL]; |
|
152 |
|
|
153 |
if (fileExists) { |
|
154 |
NSError *error = nil; |
|
155 |
[self.ioCipher removeItemAtPath:path error:&error]; |
|
156 |
if (error) { |
|
157 |
NSError *error = [NSError errorWithDomain:kOTRErrorDomain code:151 userInfo:@{NSLocalizedDescriptionKey:@"Unable to remove existing file"}]; |
|
158 |
if (completion) { |
|
159 |
dispatch_async(completionQueue, ^{ |
|
160 |
completion(NO, error); |
|
161 |
}); |
|
162 |
} |
|
163 |
return; |
|
164 |
} |
|
165 |
} |
|
166 |
|
|
167 |
if (completion) { |
|
168 |
dispatch_async(completionQueue, ^{ |
|
169 |
completion(YES, nil); |
|
170 |
}); |
|
171 |
} |
|
172 |
}]; |
|
173 |
} |
|
174 |
|
|
131 | 175 |
/* Internal. If "length" is set, only return the length of the data, otherwise the data ifself */ |
132 | 176 |
- (nullable NSData*)dataForItem:(OTRMediaItem *)mediaItem |
133 | 177 |
buddyUniqueId:(NSString *)buddyUniqueId |
Also available in: Unified diff