Respond to CR.

// FREEBIE
pull/1/head
Matthew Chen 7 years ago
parent d7b0424c75
commit 2d8a7b03d0

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

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

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

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

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

@ -5,10 +5,13 @@
#import "TSStorageManager.h" #import "TSStorageManager.h"
#import "NSData+Base64.h" #import "NSData+Base64.h"
#import "OWSAnalytics.h" #import "OWSAnalytics.h"
#import "OWSBatchMessageProcessor.h"
#import "OWSDisappearingMessagesFinder.h" #import "OWSDisappearingMessagesFinder.h"
#import "OWSFailedAttachmentDownloadsJob.h" #import "OWSFailedAttachmentDownloadsJob.h"
#import "OWSFailedMessagesJob.h" #import "OWSFailedMessagesJob.h"
#import "OWSFileSystem.h"
#import "OWSIncomingMessageFinder.h" #import "OWSIncomingMessageFinder.h"
#import "OWSMessageReceiver.h"
#import "SignalRecipient.h" #import "SignalRecipient.h"
#import "TSAttachmentStream.h" #import "TSAttachmentStream.h"
#import "TSDatabaseSecondaryIndexes.h" #import "TSDatabaseSecondaryIndexes.h"
@ -17,8 +20,6 @@
#import "TSThread.h" #import "TSThread.h"
#import <25519/Randomness.h> #import <25519/Randomness.h>
#import <SAMKeychain/SAMKeychain.h> #import <SAMKeychain/SAMKeychain.h>
#import <SignalServiceKit/OWSBatchMessageProcessor.h>
#import <SignalServiceKit/OWSMessageReceiver.h>
#import <YapDatabase/YapDatabaseRelationship.h> #import <YapDatabase/YapDatabaseRelationship.h>
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
@ -349,29 +350,9 @@ void setDatabaseInitialized()
} }
- (void)protectSignalFiles { - (void)protectSignalFiles {
[self protectFolderAtPath:[TSAttachmentStream attachmentsFolder]]; [OWSFileSystem protectFolderAtPath:[self dbPath]];
[self protectFolderAtPath:[self dbPath]]; [OWSFileSystem protectFolderAtPath:[[self dbPath] stringByAppendingString:@"-shm"]];
[self protectFolderAtPath:[[self dbPath] stringByAppendingString:@"-shm"]]; [OWSFileSystem protectFolderAtPath:[[self dbPath] stringByAppendingString:@"-wal"]];
[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]);
}
} }
- (nullable YapDatabaseConnection *)newDatabaseConnection - (nullable YapDatabaseConnection *)newDatabaseConnection

@ -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

@ -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
Loading…
Cancel
Save