mirror of
https://github.com/oxen-io/session-ios.git
synced 2023-12-13 21:30:14 +01:00
Cache the attachments folder in TSAttachmentStream.
// FREEBIE
This commit is contained in:
parent
b9f9b6a0c3
commit
8ef118f5da
|
@ -183,20 +183,31 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
|
||||
+ (NSString *)attachmentsFolder
|
||||
{
|
||||
NSString *documentsPath =
|
||||
[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject];
|
||||
NSString *attachmentFolder = [documentsPath stringByAppendingFormat:@"/Attachments"];
|
||||
static NSString *attachmentsFolder = nil;
|
||||
static dispatch_once_t onceToken;
|
||||
dispatch_once(&onceToken, ^{
|
||||
NSString *documentsPath =
|
||||
[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject];
|
||||
attachmentsFolder = [documentsPath stringByAppendingFormat:@"/Attachments"];
|
||||
|
||||
NSError *error = nil;
|
||||
[[NSFileManager defaultManager] createDirectoryAtPath:attachmentFolder
|
||||
withIntermediateDirectories:YES
|
||||
attributes:nil
|
||||
error:&error];
|
||||
if (error) {
|
||||
DDLogError(@"Failed to create attachments directory: %@", error);
|
||||
}
|
||||
BOOL isDirectory;
|
||||
BOOL exists = [[NSFileManager defaultManager] fileExistsAtPath:attachmentsFolder isDirectory:&isDirectory];
|
||||
if (exists) {
|
||||
OWSAssert(isDirectory);
|
||||
|
||||
return attachmentFolder;
|
||||
DDLogInfo(@"Attachments directory already exists");
|
||||
} else {
|
||||
NSError *error = nil;
|
||||
[[NSFileManager defaultManager] createDirectoryAtPath:attachmentsFolder
|
||||
withIntermediateDirectories:YES
|
||||
attributes:nil
|
||||
error:&error];
|
||||
if (error) {
|
||||
DDLogError(@"Failed to create attachments directory: %@", error);
|
||||
}
|
||||
}
|
||||
});
|
||||
return attachmentsFolder;
|
||||
}
|
||||
|
||||
+ (NSUInteger)numberOfItemsInAttachmentsFolder
|
||||
|
|
Loading…
Reference in a new issue