Improve handling of thumbnails dir.

This commit is contained in:
Matthew Chen 2018-09-05 11:54:39 -04:00
parent 3a5d1877da
commit 72a71c185b
2 changed files with 11 additions and 10 deletions

View File

@ -107,7 +107,6 @@ typedef void (^OWSThumbnailFailure)(void);
// Marks attachment as having completed "lazy backup restore."
- (void)updateWithLazyRestoreComplete;
// TODO: Review.
- (nullable TSAttachmentStream *)cloneAsThumbnail;
#pragma mark - Protobuf

View File

@ -734,15 +734,17 @@ typedef void (^OWSLoadedThumbnailSuccess)(OWSLoadedThumbnail *loadedThumbnail);
NSMutableArray<NSString *> *result = [NSMutableArray new];
NSString *thumbnailsDirPath = self.thumbnailsDirPath;
NSError *error;
NSArray<NSString *> *_Nullable fileNames =
[[NSFileManager defaultManager] contentsOfDirectoryAtPath:thumbnailsDirPath error:&error];
if (error || !fileNames) {
OWSFail(@"contentsOfDirectoryAtPath failed with error: %@", error);
} else {
for (NSString *fileName in fileNames) {
NSString *filePath = [thumbnailsDirPath stringByAppendingPathComponent:fileName];
[result addObject:filePath];
if ([[NSFileManager defaultManager] fileExistsAtPath:thumbnailsDirPath]) {
NSError *error;
NSArray<NSString *> *_Nullable fileNames =
[[NSFileManager defaultManager] contentsOfDirectoryAtPath:thumbnailsDirPath error:&error];
if (error || !fileNames) {
OWSFail(@"contentsOfDirectoryAtPath failed with error: %@", error);
} else {
for (NSString *fileName in fileNames) {
NSString *filePath = [thumbnailsDirPath stringByAppendingPathComponent:fileName];
[result addObject:filePath];
}
}
}