Respond to CR.

This commit is contained in:
Matthew Chen 2017-11-30 10:02:04 -05:00
parent 779e89fe74
commit 8d4e9b4565
6 changed files with 52 additions and 43 deletions

View File

@ -188,6 +188,6 @@ SPEC CHECKSUMS:
YapDatabase: cd911121580ff16675f65ad742a9eb0ab4d9e266
YYImage: 1e1b62a9997399593e4b9c4ecfbbabbf1d3f3b54
PODFILE CHECKSUM: 8e42a06de2d254e448580cfd6212545739de62d6
PODFILE CHECKSUM: 558b99b22f87c7fb6e4a9c3084b14a384203d431
COCOAPODS: 1.3.1

View File

@ -24,6 +24,7 @@
#import "VersionMigrations.h"
#import "ViewControllerUtils.h"
#import <AxolotlKit/SessionCipher.h>
#import <SignalMessaging/SignalMessaging.h>
#import <SignalServiceKit/NSUserDefaults+OWS.h>
#import <SignalServiceKit/OWSBatchMessageProcessor.h>
#import <SignalServiceKit/OWSDisappearingMessagesJob.h>
@ -39,7 +40,6 @@
#import <SignalServiceKit/TSSocketManager.h>
#import <SignalServiceKit/TSStorageManager+Calling.h>
#import <SignalServiceKit/TextSecureKitEnv.h>
#import <SignalMessaging/SignalMessaging.h>
@import WebRTC;
@import Intents;
@ -104,13 +104,14 @@ static NSString *const kURLHostVerifyPrefix = @"verify";
DDLogWarn(@"%@ application: didFinishLaunchingWithOptions.", self.logTag);
// We need to this _after_ we set up logging but _before_ we do
// We need to do this _after_ we set up logging but _before_ we do
// anything else.
[self ensureIsReadyForAppExtensions];
#if RELEASE
// ensureIsReadyForAppExtensions may have changed the state of the logging
// preference, so honor that change if necessary.
// preference (due to [NSUserDefaults migrateToSharedUserDefaults]), so honor
// that change if necessary.
if (loggingIsEnabled && !OWSPreferences.loggingIsEnabled) {
[DebugLogger.sharedLogger disableFileLogging];
}

View File

@ -1384,20 +1384,20 @@ const NSUInteger kOWSProfileManager_MaxAvatarDiameter = 640;
return image;
}
+ (NSString *)oldProfileAvatarsDirPath
+ (NSString *)legacyProfileAvatarsDirPath
{
return [[OWSFileSystem appDocumentDirectoryPath] stringByAppendingPathComponent:@"ProfileAvatars"];
}
+ (NSString *)newProfileAvatarsDirPath
+ (NSString *)sharedDataProfileAvatarsDirPath
{
return [[OWSFileSystem appSharedDataDirectoryPath] stringByAppendingPathComponent:@"ProfileAvatars"];
}
+ (void)migrateToSharedData
{
[OWSFileSystem moveAppFilePath:self.oldProfileAvatarsDirPath
sharedDataFilePath:self.newProfileAvatarsDirPath
[OWSFileSystem moveAppFilePath:self.legacyProfileAvatarsDirPath
sharedDataFilePath:self.sharedDataProfileAvatarsDirPath
exceptionName:@"ProfileManagerCouldNotMigrateProfileDirectory"];
}
@ -1406,7 +1406,7 @@ const NSUInteger kOWSProfileManager_MaxAvatarDiameter = 640;
static NSString *profileAvatarsDirPath = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
profileAvatarsDirPath = OWSProfileManager.newProfileAvatarsDirPath;
profileAvatarsDirPath = OWSProfileManager.sharedDataProfileAvatarsDirPath;
BOOL isDirectory;
BOOL exists = [[NSFileManager defaultManager] fileExistsAtPath:profileAvatarsDirPath isDirectory:&isDirectory];

View File

@ -180,20 +180,20 @@ NS_ASSUME_NONNULL_BEGIN
return [dataSource writeToPath:filePath];
}
+ (NSString *)oldAttachmentsDirPath
+ (NSString *)legacyAttachmentsDirPath
{
return [[OWSFileSystem appDocumentDirectoryPath] stringByAppendingPathComponent:@"Attachments"];
}
+ (NSString *)newAttachmentsDirPath
+ (NSString *)sharedDataAttachmentsDirPath
{
return [[OWSFileSystem appSharedDataDirectoryPath] stringByAppendingPathComponent:@"Attachments"];
}
+ (void)migrateToSharedData
{
[OWSFileSystem moveAppFilePath:self.oldAttachmentsDirPath
sharedDataFilePath:self.newAttachmentsDirPath
[OWSFileSystem moveAppFilePath:self.legacyAttachmentsDirPath
sharedDataFilePath:self.sharedDataAttachmentsDirPath
exceptionName:@"CouldNotMigrateAttachmentsDirectory"];
}
@ -202,7 +202,7 @@ NS_ASSUME_NONNULL_BEGIN
static NSString *attachmentsFolder = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
attachmentsFolder = TSAttachmentStream.newAttachmentsDirPath;
attachmentsFolder = TSAttachmentStream.sharedDataAttachmentsDirPath;
BOOL isDirectory;
BOOL exists = [[NSFileManager defaultManager] fileExistsAtPath:attachmentsFolder isDirectory:&isDirectory];

View File

@ -360,12 +360,12 @@ void setDatabaseInitialized()
{
// The old database location was in the Document directory,
// so protect the database files individually.
[OWSFileSystem protectFolderAtPath:[self oldDatabaseFilePath]];
[OWSFileSystem protectFolderAtPath:[self oldDatabaseFilePath_SHM]];
[OWSFileSystem protectFolderAtPath:[self oldDatabaseFilePath_WAL]];
[OWSFileSystem protectFolderAtPath:self.legacyDatabaseFilePath];
[OWSFileSystem protectFolderAtPath:self.legacyDatabaseFilePath_SHM];
[OWSFileSystem protectFolderAtPath:self.legacyDatabaseFilePath_WAL];
// Protect the entire new database directory.
[OWSFileSystem protectFolderAtPath:[self newDatabaseDirPath]];
[OWSFileSystem protectFolderAtPath:self.sharedDataDatabaseDirPath];
}
- (nullable YapDatabaseConnection *)newDatabaseConnection
@ -377,12 +377,12 @@ void setDatabaseInitialized()
return FALSE;
}
+ (NSString *)oldDatabaseDirPath
+ (NSString *)legacyDatabaseDirPath
{
return [OWSFileSystem appDocumentDirectoryPath];
}
+ (NSString *)newDatabaseDirPath
+ (NSString *)sharedDataDatabaseDirPath
{
NSString *databaseDirPath = [[OWSFileSystem appSharedDataDirectoryPath] stringByAppendingPathComponent:@"database"];
@ -422,54 +422,54 @@ void setDatabaseInitialized()
return [self.databaseFilename stringByAppendingString:@"-wal"];
}
+ (NSString *)oldDatabaseFilePath
+ (NSString *)legacyDatabaseFilePath
{
return [self.oldDatabaseDirPath stringByAppendingPathComponent:self.databaseFilename];
return [self.legacyDatabaseDirPath stringByAppendingPathComponent:self.databaseFilename];
}
+ (NSString *)oldDatabaseFilePath_SHM
+ (NSString *)legacyDatabaseFilePath_SHM
{
return [self.oldDatabaseDirPath stringByAppendingPathComponent:self.databaseFilename_SHM];
return [self.legacyDatabaseDirPath stringByAppendingPathComponent:self.databaseFilename_SHM];
}
+ (NSString *)oldDatabaseFilePath_WAL
+ (NSString *)legacyDatabaseFilePath_WAL
{
return [self.oldDatabaseDirPath stringByAppendingPathComponent:self.databaseFilename_WAL];
return [self.legacyDatabaseDirPath stringByAppendingPathComponent:self.databaseFilename_WAL];
}
+ (NSString *)newDatabaseFilePath
+ (NSString *)sharedDataDatabaseFilePath
{
return [self.newDatabaseDirPath stringByAppendingPathComponent:self.databaseFilename];
return [self.sharedDataDatabaseDirPath stringByAppendingPathComponent:self.databaseFilename];
}
+ (NSString *)newDatabaseFilePath_SHM
+ (NSString *)sharedDataDatabaseFilePath_SHM
{
return [self.newDatabaseDirPath stringByAppendingPathComponent:self.databaseFilename_SHM];
return [self.sharedDataDatabaseDirPath stringByAppendingPathComponent:self.databaseFilename_SHM];
}
+ (NSString *)newDatabaseFilePath_WAL
+ (NSString *)sharedDataDatabaseFilePath_WAL
{
return [self.newDatabaseDirPath stringByAppendingPathComponent:self.databaseFilename_WAL];
return [self.sharedDataDatabaseDirPath stringByAppendingPathComponent:self.databaseFilename_WAL];
}
+ (void)migrateToSharedData
{
[OWSFileSystem moveAppFilePath:self.oldDatabaseFilePath
sharedDataFilePath:self.newDatabaseFilePath
[OWSFileSystem moveAppFilePath:self.legacyDatabaseFilePath
sharedDataFilePath:self.sharedDataDatabaseFilePath
exceptionName:TSStorageManagerExceptionName_CouldNotMoveDatabaseFile];
[OWSFileSystem moveAppFilePath:self.oldDatabaseFilePath_SHM
sharedDataFilePath:self.newDatabaseFilePath_SHM
[OWSFileSystem moveAppFilePath:self.legacyDatabaseFilePath_SHM
sharedDataFilePath:self.sharedDataDatabaseFilePath_SHM
exceptionName:TSStorageManagerExceptionName_CouldNotMoveDatabaseFile];
[OWSFileSystem moveAppFilePath:self.oldDatabaseFilePath_WAL
sharedDataFilePath:self.newDatabaseFilePath_WAL
[OWSFileSystem moveAppFilePath:self.legacyDatabaseFilePath_WAL
sharedDataFilePath:self.sharedDataDatabaseFilePath_WAL
exceptionName:TSStorageManagerExceptionName_CouldNotMoveDatabaseFile];
}
- (NSString *)dbPath
{
DDLogVerbose(@"databasePath: %@", TSStorageManager.newDatabaseFilePath);
DDLogVerbose(@"databasePath: %@", TSStorageManager.sharedDataDatabaseFilePath);
return TSStorageManager.newDatabaseFilePath;
return TSStorageManager.sharedDataDatabaseFilePath;
}
+ (BOOL)isDatabasePasswordAccessible

View File

@ -28,9 +28,17 @@ NS_ASSUME_NONNULL_BEGIN
+ (void)removeAll
{
NSString *appDomain = NSBundle.mainBundle.bundleIdentifier;
[NSUserDefaults.standardUserDefaults removePersistentDomainForName:appDomain];
// TODO: How to clear the shared user defaults?
[NSUserDefaults.standardUserDefaults removeAll];
[self.appUserDefaults removeAll];
}
- (void)removeAll
{
NSDictionary<NSString *, id> *dictionary = self.dictionaryRepresentation;
for (NSString *key in dictionary) {
[self removeObjectForKey:key];
}
[self synchronize];
}
@end