Respond to CR.

// FREEBIE
This commit is contained in:
Matthew Chen 2017-11-16 10:12:47 -05:00
parent d7b0424c75
commit 2d8a7b03d0
8 changed files with 64 additions and 47 deletions

View File

@ -11,6 +11,7 @@
#import <SignalServiceKit/NSData+hexString.h>
#import <SignalServiceKit/NSDate+OWS.h>
#import <SignalServiceKit/NSNotificationCenter+OWS.h>
#import <SignalServiceKit/OWSFileSystem.h>
#import <SignalServiceKit/OWSMessageSender.h>
#import <SignalServiceKit/OWSRequestBuilder.h>
#import <SignalServiceKit/SecurityUtils.h>
@ -1409,15 +1410,7 @@ const NSUInteger kOWSProfileManager_MaxAvatarDiameter = 640;
}
}
NSURL *dirURL = [NSURL fileURLWithPath:profileAvatarsDirPath];
NSError *error = nil;
[dirURL setResourceValues:@{
NSURLIsExcludedFromBackupKey : @(YES),
}
error:&error];
if (error) {
OWSFail(@"Failed to exclude profile avatars directory from backup: %@", error);
}
[OWSFileSystem protectFolderAtPath:profileAvatarsDirPath];
});
return profileAvatarsDirPath;
}

View File

@ -77,6 +77,7 @@
#import <SignalServiceKit/OWSDispatch.h>
#import <SignalServiceKit/OWSEndSessionMessage.h>
#import <SignalServiceKit/OWSError.h>
#import <SignalServiceKit/OWSFileSystem.h>
#import <SignalServiceKit/OWSGetMessagesRequest.h>
#import <SignalServiceKit/OWSGetProfileRequest.h>
#import <SignalServiceKit/OWSIdentityManager.h>

View File

@ -844,10 +844,7 @@ extension URLSessionTask {
}
// Don't back up Giphy downloads.
var dirURL = NSURL.fileURL(withPath:dirPath)
var resourceValues = URLResourceValues()
resourceValues.isExcludedFromBackup = true
try dirURL.setResourceValues(resourceValues)
OWSFileSystem.protectFolder(atPath:dirPath)
} catch let error as NSError {
owsFail("\(GiphyAsset.TAG) ensureTempFolder failed: \(dirPath), \(error)")
gifFolderPath = tempDirPath

View File

@ -5,6 +5,7 @@
#import "TSAttachmentStream.h"
#import "MIMETypeUtil.h"
#import "NSData+Image.h"
#import "OWSFileSystem.h"
#import "TSAttachmentPointer.h"
#import <AVFoundation/AVFoundation.h>
#import <ImageIO/ImageIO.h>
@ -205,15 +206,7 @@ NS_ASSUME_NONNULL_BEGIN
}
}
NSURL *dirURL = [NSURL fileURLWithPath:attachmentsFolder];
NSError *error = nil;
[dirURL setResourceValues:@{
NSURLIsExcludedFromBackupKey : @(YES),
}
error:&error];
if (error) {
OWSFail(@"Failed to exclude attachments directory from backup: %@", error);
}
[OWSFileSystem protectFolderAtPath:attachmentsFolder];
});
return attachmentsFolder;
}

View File

@ -63,6 +63,10 @@ NS_ASSUME_NONNULL_BEGIN
@property (nullable, nonatomic, readonly) YapDatabaseConnection *dbReadConnection;
@property (nullable, nonatomic, readonly) YapDatabaseConnection *dbReadWriteConnection;
#pragma mark - Utilities
- (void)protectFolderAtPath:(NSString *)path;
@end
NS_ASSUME_NONNULL_END

View File

@ -5,10 +5,13 @@
#import "TSStorageManager.h"
#import "NSData+Base64.h"
#import "OWSAnalytics.h"
#import "OWSBatchMessageProcessor.h"
#import "OWSDisappearingMessagesFinder.h"
#import "OWSFailedAttachmentDownloadsJob.h"
#import "OWSFailedMessagesJob.h"
#import "OWSFileSystem.h"
#import "OWSIncomingMessageFinder.h"
#import "OWSMessageReceiver.h"
#import "SignalRecipient.h"
#import "TSAttachmentStream.h"
#import "TSDatabaseSecondaryIndexes.h"
@ -17,8 +20,6 @@
#import "TSThread.h"
#import <25519/Randomness.h>
#import <SAMKeychain/SAMKeychain.h>
#import <SignalServiceKit/OWSBatchMessageProcessor.h>
#import <SignalServiceKit/OWSMessageReceiver.h>
#import <YapDatabase/YapDatabaseRelationship.h>
NS_ASSUME_NONNULL_BEGIN
@ -349,29 +350,9 @@ void setDatabaseInitialized()
}
- (void)protectSignalFiles {
[self protectFolderAtPath:[TSAttachmentStream attachmentsFolder]];
[self protectFolderAtPath:[self dbPath]];
[self protectFolderAtPath:[[self dbPath] stringByAppendingString:@"-shm"]];
[self protectFolderAtPath:[[self dbPath] stringByAppendingString:@"-wal"]];
}
- (void)protectFolderAtPath:(NSString *)path {
if (![NSFileManager.defaultManager fileExistsAtPath:path]) {
return;
}
NSError *error;
NSDictionary *fileProtection = @{NSFileProtectionKey : NSFileProtectionCompleteUntilFirstUserAuthentication};
[[NSFileManager defaultManager] setAttributes:fileProtection ofItemAtPath:path error:&error];
NSDictionary *resourcesAttrs = @{ NSURLIsExcludedFromBackupKey : @YES };
NSURL *ressourceURL = [NSURL fileURLWithPath:path];
BOOL success = [ressourceURL setResourceValues:resourcesAttrs error:&error];
if (error || !success) {
OWSProdCritical([OWSAnalyticsEvents storageErrorFileProtection]);
}
[OWSFileSystem protectFolderAtPath:[self dbPath]];
[OWSFileSystem protectFolderAtPath:[[self dbPath] stringByAppendingString:@"-shm"]];
[OWSFileSystem protectFolderAtPath:[[self dbPath] stringByAppendingString:@"-wal"]];
}
- (nullable YapDatabaseConnection *)newDatabaseConnection

View File

@ -0,0 +1,15 @@
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
//
NS_ASSUME_NONNULL_BEGIN
@interface OWSFileSystem : NSObject
- (instancetype)init NS_UNAVAILABLE;
+ (void)protectFolderAtPath:(NSString *)path;
@end
NS_ASSUME_NONNULL_END

View File

@ -0,0 +1,33 @@
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
//
#import "OWSFileSystem.h"
NS_ASSUME_NONNULL_BEGIN
@implementation OWSFileSystem
+ (void)protectFolderAtPath:(NSString *)path
{
if (![NSFileManager.defaultManager fileExistsAtPath:path]) {
return;
}
NSError *error;
NSDictionary *fileProtection = @{ NSFileProtectionKey : NSFileProtectionCompleteUntilFirstUserAuthentication };
[[NSFileManager defaultManager] setAttributes:fileProtection ofItemAtPath:path error:&error];
NSDictionary *resourcesAttrs = @{ NSURLIsExcludedFromBackupKey : @YES };
NSURL *ressourceURL = [NSURL fileURLWithPath:path];
BOOL success = [ressourceURL setResourceValues:resourcesAttrs error:&error];
if (error || !success) {
OWSProdCritical([OWSAnalyticsEvents storageErrorFileProtection]);
}
}
@end
NS_ASSUME_NONNULL_END