Fix failed attachment downloads in beta

pull/1/head
Michael Kirk 7 years ago
parent 1fb4ca9994
commit 6560358375

@ -214,8 +214,7 @@ typedef void (^OrphanDataBlock)(OWSOrphanData *);
// a single launch of the app. Since our "date threshold" // a single launch of the app. Since our "date threshold"
// for deletion is relative to the current launch time, // for deletion is relative to the current launch time,
// all temp files currently in use should be safe. // all temp files currently in use should be safe.
NSString *temporaryDirectory = NSTemporaryDirectory(); NSArray<NSString *> *_Nullable tempFilePaths = [self getTempFilePaths];
NSArray<NSString *> *_Nullable tempFilePaths = [self filePathsInDirectorySafe:temporaryDirectory].allObjects;
if (!tempFilePaths || !self.isMainAppAndActive) { if (!tempFilePaths || !self.isMainAppAndActive) {
return nil; return nil;
} }
@ -714,6 +713,21 @@ typedef void (^OrphanDataBlock)(OWSOrphanData *);
return YES; return YES;
} }
+ (nullable NSArray<NSString *> *)getTempFilePaths
{
NSString *dir1 = NSTemporaryDirectory();
NSArray<NSString *> *_Nullable paths1 = [[self filePathsInDirectorySafe:dir1].allObjects mutableCopy];
NSString *dir2 = OWSFileSystem.accessibleAfterFirstAuthTempDirectoryPath;
NSArray<NSString *> *_Nullable paths2 = [[self filePathsInDirectorySafe:dir2].allObjects mutableCopy];
if (paths1 && paths2) {
return [paths1 arrayByAddingObjectsFromArray:paths2];
} else {
return nil;
}
}
@end @end
NS_ASSUME_NONNULL_END NS_ASSUME_NONNULL_END

@ -312,7 +312,8 @@ static const CGFloat kAttachmentDownloadProgressTheta = 0.001f;
const long kMaxDownloadSize = 150 * 1024 * 1024; const long kMaxDownloadSize = 150 * 1024 * 1024;
__block BOOL hasCheckedContentLength = NO; __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 *tempFilePath1 = [tempSubdirPath stringByAppendingPathComponent:[NSUUID UUID].UUIDString];
NSString *tempFilePath2 = [tempSubdirPath stringByAppendingPathComponent:[NSUUID UUID].UUIDString]; NSString *tempFilePath2 = [tempSubdirPath stringByAppendingPathComponent:[NSUUID UUID].UUIDString];
NSURL *tempFileURL1 = [NSURL fileURLWithPath:tempFilePath1]; NSURL *tempFileURL1 = [NSURL fileURLWithPath:tempFilePath1];

@ -19,6 +19,8 @@ NS_ASSUME_NONNULL_BEGIN
+ (NSString *)appSharedDataDirectoryPath; + (NSString *)appSharedDataDirectoryPath;
+ (NSString *)accessibleAfterFirstAuthTempDirectoryPath;
+ (NSString *)cachesDirectoryPath; + (NSString *)cachesDirectoryPath;
+ (nullable NSError *)renameFilePathUsingRandomExtension:(NSString *)oldFilePath; + (nullable NSError *)renameFilePathUsingRandomExtension:(NSString *)oldFilePath;

@ -110,6 +110,15 @@ NS_ASSUME_NONNULL_BEGIN
return CurrentAppContext().appSharedDataDirectoryPath; 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 + (NSString *)cachesDirectoryPath
{ {
NSArray<NSString *> *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES); NSArray<NSString *> *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);

Loading…
Cancel
Save