diff --git a/Signal/src/util/OWSOrphanDataCleaner.m b/Signal/src/util/OWSOrphanDataCleaner.m index 97f15267a..0c576cfaa 100644 --- a/Signal/src/util/OWSOrphanDataCleaner.m +++ b/Signal/src/util/OWSOrphanDataCleaner.m @@ -214,8 +214,7 @@ typedef void (^OrphanDataBlock)(OWSOrphanData *); // a single launch of the app. Since our "date threshold" // for deletion is relative to the current launch time, // all temp files currently in use should be safe. - NSString *temporaryDirectory = NSTemporaryDirectory(); - NSArray *_Nullable tempFilePaths = [self filePathsInDirectorySafe:temporaryDirectory].allObjects; + NSArray *_Nullable tempFilePaths = [self getTempFilePaths]; if (!tempFilePaths || !self.isMainAppAndActive) { return nil; } @@ -714,6 +713,21 @@ typedef void (^OrphanDataBlock)(OWSOrphanData *); return YES; } ++ (nullable NSArray *)getTempFilePaths +{ + NSString *dir1 = NSTemporaryDirectory(); + NSArray *_Nullable paths1 = [[self filePathsInDirectorySafe:dir1].allObjects mutableCopy]; + + NSString *dir2 = OWSFileSystem.accessibleAfterFirstAuthTempDirectoryPath; + NSArray *_Nullable paths2 = [[self filePathsInDirectorySafe:dir2].allObjects mutableCopy]; + + if (paths1 && paths2) { + return [paths1 arrayByAddingObjectsFromArray:paths2]; + } else { + return nil; + } +} + @end NS_ASSUME_NONNULL_END diff --git a/SignalServiceKit/src/Messages/Attachments/OWSAttachmentsProcessor.m b/SignalServiceKit/src/Messages/Attachments/OWSAttachmentsProcessor.m index a555312c7..3790507f4 100644 --- a/SignalServiceKit/src/Messages/Attachments/OWSAttachmentsProcessor.m +++ b/SignalServiceKit/src/Messages/Attachments/OWSAttachmentsProcessor.m @@ -312,7 +312,8 @@ static const CGFloat kAttachmentDownloadProgressTheta = 0.001f; const long kMaxDownloadSize = 150 * 1024 * 1024; __block BOOL hasCheckedContentLength = NO; - NSString *tempSubdirPath = [NSTemporaryDirectory() stringByAppendingPathComponent:[NSUUID UUID].UUIDString]; + NSString *tempSubdirPath = [OWSFileSystem.accessibleAfterFirstAuthTempDirectoryPath + stringByAppendingPathComponent:[NSUUID UUID].UUIDString]; NSString *tempFilePath1 = [tempSubdirPath stringByAppendingPathComponent:[NSUUID UUID].UUIDString]; NSString *tempFilePath2 = [tempSubdirPath stringByAppendingPathComponent:[NSUUID UUID].UUIDString]; NSURL *tempFileURL1 = [NSURL fileURLWithPath:tempFilePath1]; diff --git a/SignalServiceKit/src/Util/OWSFileSystem.h b/SignalServiceKit/src/Util/OWSFileSystem.h index b56e9f49d..add7e4bb8 100644 --- a/SignalServiceKit/src/Util/OWSFileSystem.h +++ b/SignalServiceKit/src/Util/OWSFileSystem.h @@ -19,6 +19,8 @@ NS_ASSUME_NONNULL_BEGIN + (NSString *)appSharedDataDirectoryPath; ++ (NSString *)accessibleAfterFirstAuthTempDirectoryPath; + + (NSString *)cachesDirectoryPath; + (nullable NSError *)renameFilePathUsingRandomExtension:(NSString *)oldFilePath; diff --git a/SignalServiceKit/src/Util/OWSFileSystem.m b/SignalServiceKit/src/Util/OWSFileSystem.m index 3b43014d6..a7ab98a00 100644 --- a/SignalServiceKit/src/Util/OWSFileSystem.m +++ b/SignalServiceKit/src/Util/OWSFileSystem.m @@ -110,6 +110,15 @@ NS_ASSUME_NONNULL_BEGIN return CurrentAppContext().appSharedDataDirectoryPath; } ++ (NSString *)accessibleAfterFirstAuthTempDirectoryPath +{ + NSString *const dirName = @"accessibleAfterFirstAuthTmp"; + NSString *const dirPath = [[self appDocumentDirectoryPath] stringByAppendingPathComponent:dirName]; + BOOL ok = [self ensureDirectoryExists:dirPath]; + OWSAssert(ok); + return dirPath; +} + + (NSString *)cachesDirectoryPath { NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);