Enable logging in SAE; rework log file management to include multiple log directories.

pull/1/head
Matthew Chen 7 years ago
parent 23f151fa50
commit bf21d0c0ed

@ -46,6 +46,8 @@
3461284B1FD0B94000532771 /* SAELoadViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3461284A1FD0B93F00532771 /* SAELoadViewController.swift */; };
346129321FD1A26100532771 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = 346129051FD1A25B00532771 /* Localizable.strings */; };
346129341FD1A88700532771 /* OWSSwiftUtils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 346129331FD1A88700532771 /* OWSSwiftUtils.swift */; };
346129391FD1B47300532771 /* OWSPreferences.h in Headers */ = {isa = PBXBuildFile; fileRef = 346129371FD1B47200532771 /* OWSPreferences.h */; settings = {ATTRIBUTES = (Public, ); }; };
3461293A1FD1B47300532771 /* OWSPreferences.m in Sources */ = {isa = PBXBuildFile; fileRef = 346129381FD1B47200532771 /* OWSPreferences.m */; };
346B66311F4E29B200E5122F /* CropScaleImageViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 346B66301F4E29B200E5122F /* CropScaleImageViewController.swift */; };
3471B1DA1EB7C63600F6AEC8 /* NewNonContactConversationViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 3471B1D91EB7C63600F6AEC8 /* NewNonContactConversationViewController.m */; };
3472229F1EB22FFE00E53955 /* AddToGroupViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 3472229E1EB22FFE00E53955 /* AddToGroupViewController.m */; };
@ -299,7 +301,6 @@
76EB054018170B33006006FC /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 76EB03C318170B33006006FC /* AppDelegate.m */; };
76EB057A18170B33006006FC /* OWSContactsManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 76EB040918170B33006006FC /* OWSContactsManager.m */; };
76EB058218170B33006006FC /* Environment.m in Sources */ = {isa = PBXBuildFile; fileRef = 76EB041318170B33006006FC /* Environment.m */; };
76EB058818170B33006006FC /* OWSPreferences.m in Sources */ = {isa = PBXBuildFile; fileRef = 76EB041918170B33006006FC /* OWSPreferences.m */; };
76EB058A18170B33006006FC /* Release.m in Sources */ = {isa = PBXBuildFile; fileRef = 76EB041B18170B33006006FC /* Release.m */; };
76EB063A18170B33006006FC /* FunctionalUtil.m in Sources */ = {isa = PBXBuildFile; fileRef = 76EB04EB18170B33006006FC /* FunctionalUtil.m */; };
76EB063C18170B33006006FC /* NumberUtil.m in Sources */ = {isa = PBXBuildFile; fileRef = 76EB04ED18170B33006006FC /* NumberUtil.m */; };
@ -354,7 +355,6 @@
B660F7171C29988E00687D6E /* OWSContactsManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 76EB040918170B33006006FC /* OWSContactsManager.m */; };
B660F7181C29988E00687D6E /* CryptoTools.m in Sources */ = {isa = PBXBuildFile; fileRef = 7038632418F70C0700D4A43F /* CryptoTools.m */; };
B660F71B1C29988E00687D6E /* Environment.m in Sources */ = {isa = PBXBuildFile; fileRef = 76EB041318170B33006006FC /* Environment.m */; };
B660F71F1C29988E00687D6E /* OWSPreferences.m in Sources */ = {isa = PBXBuildFile; fileRef = 76EB041918170B33006006FC /* OWSPreferences.m */; };
B660F7201C29988E00687D6E /* Release.m in Sources */ = {isa = PBXBuildFile; fileRef = 76EB041B18170B33006006FC /* Release.m */; };
B660F7211C29988E00687D6E /* SignalKeyingStorage.m in Sources */ = {isa = PBXBuildFile; fileRef = B6B1013B196D213F007E3930 /* SignalKeyingStorage.m */; };
B660F7221C29988E00687D6E /* VersionMigrations.m in Sources */ = {isa = PBXBuildFile; fileRef = B60C16641988999D00E97A6C /* VersionMigrations.m */; };
@ -573,6 +573,8 @@
346129301FD1A26000532771 /* tr_TR */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = tr_TR; path = Signal/translations/tr_TR.lproj/Localizable.strings; sourceTree = SOURCE_ROOT; };
346129311FD1A26100532771 /* es */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = es; path = Signal/translations/es.lproj/Localizable.strings; sourceTree = SOURCE_ROOT; };
346129331FD1A88700532771 /* OWSSwiftUtils.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OWSSwiftUtils.swift; sourceTree = "<group>"; };
346129371FD1B47200532771 /* OWSPreferences.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OWSPreferences.h; sourceTree = "<group>"; };
346129381FD1B47200532771 /* OWSPreferences.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OWSPreferences.m; sourceTree = "<group>"; };
346B66301F4E29B200E5122F /* CropScaleImageViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CropScaleImageViewController.swift; sourceTree = "<group>"; };
3471B1D81EB7C63600F6AEC8 /* NewNonContactConversationViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NewNonContactConversationViewController.h; sourceTree = "<group>"; };
3471B1D91EB7C63600F6AEC8 /* NewNonContactConversationViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NewNonContactConversationViewController.m; sourceTree = "<group>"; };
@ -887,8 +889,6 @@
76EB040918170B33006006FC /* OWSContactsManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OWSContactsManager.m; sourceTree = "<group>"; };
76EB041218170B33006006FC /* Environment.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Environment.h; sourceTree = "<group>"; };
76EB041318170B33006006FC /* Environment.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Environment.m; sourceTree = "<group>"; };
76EB041818170B33006006FC /* OWSPreferences.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OWSPreferences.h; sourceTree = "<group>"; };
76EB041918170B33006006FC /* OWSPreferences.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OWSPreferences.m; sourceTree = "<group>"; };
76EB041A18170B33006006FC /* Release.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Release.h; sourceTree = "<group>"; };
76EB041B18170B33006006FC /* Release.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Release.m; sourceTree = "<group>"; };
76EB04EA18170B33006006FC /* FunctionalUtil.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FunctionalUtil.h; sourceTree = "<group>"; };
@ -1145,6 +1145,8 @@
34480B4A1FD0A7A200BC14EF /* OWSLogger.h */,
34480B4B1FD0A7A300BC14EF /* OWSLogger.m */,
34480B481FD0A60200BC14EF /* OWSMath.h */,
346129371FD1B47200532771 /* OWSPreferences.h */,
346129381FD1B47200532771 /* OWSPreferences.m */,
34480B4F1FD0A7A300BC14EF /* OWSScrubbingLogFormatter.h */,
34480B511FD0A7A400BC14EF /* OWSScrubbingLogFormatter.m */,
346129331FD1A88700532771 /* OWSSwiftUtils.swift */,
@ -1658,8 +1660,6 @@
45666F731D9BFDB9008FE134 /* Migrations */,
B6258B311C29E2E60014138E /* NotificationsManager.h */,
B6258B321C29E2E60014138E /* NotificationsManager.m */,
76EB041818170B33006006FC /* OWSPreferences.h */,
76EB041918170B33006006FC /* OWSPreferences.m */,
76EB041A18170B33006006FC /* Release.h */,
76EB041B18170B33006006FC /* Release.m */,
B6B1013A196D213F007E3930 /* SignalKeyingStorage.h */,
@ -2052,6 +2052,7 @@
34480B611FD0A98800BC14EF /* UIColor+OWS.h in Headers */,
453518961FC63DBF00210559 /* SignalMessaging.h in Headers */,
34480B631FD0A98800BC14EF /* UIView+OWS.h in Headers */,
346129391FD1B47300532771 /* OWSPreferences.h in Headers */,
34480B5B1FD0A7E300BC14EF /* SignalMessaging-Prefix.pch in Headers */,
34480B681FD0AA9400BC14EF /* UIFont+OWS.h in Headers */,
);
@ -2684,6 +2685,7 @@
34480B621FD0A98800BC14EF /* UIColor+OWS.m in Sources */,
34480B531FD0A7A400BC14EF /* OWSLogger.m in Sources */,
34480B641FD0A98800BC14EF /* UIView+OWS.m in Sources */,
3461293A1FD1B47300532771 /* OWSPreferences.m in Sources */,
34480B671FD0AA9400BC14EF /* UIFont+OWS.m in Sources */,
346129341FD1A88700532771 /* OWSSwiftUtils.swift in Sources */,
34480B591FD0A7A400BC14EF /* OWSScrubbingLogFormatter.m in Sources */,
@ -2882,7 +2884,6 @@
34B3F8941E8DF1710035BE1A /* HomeViewController.m in Sources */,
34E8BF381EE9E2FD00F5F4CA /* FingerprintViewScanController.m in Sources */,
346B66311F4E29B200E5122F /* CropScaleImageViewController.swift in Sources */,
76EB058818170B33006006FC /* OWSPreferences.m in Sources */,
45E5A6991F61E6DE001E4A8A /* MarqueeLabel.swift in Sources */,
34D1F0B01F867BFC0066283D /* OWSSystemMessageCell.m in Sources */,
45A663C51F92EC760027B59E /* GroupTableViewCell.swift in Sources */,
@ -2913,7 +2914,6 @@
B660F7171C29988E00687D6E /* OWSContactsManager.m in Sources */,
B660F7181C29988E00687D6E /* CryptoTools.m in Sources */,
B660F71B1C29988E00687D6E /* Environment.m in Sources */,
B660F71F1C29988E00687D6E /* OWSPreferences.m in Sources */,
451DA3CA1F148A9F008E2423 /* DeviceSleepManager.swift in Sources */,
B660F7201C29988E00687D6E /* Release.m in Sources */,
45BB93391E688E14001E3939 /* UIDevice+featureSupport.swift in Sources */,

@ -94,16 +94,16 @@ static NSString *const kURLHostVerifyPrefix = @"verify";
// This should be the first thing we do.
SetCurrentAppContext([MainAppContext new]);
BOOL loggingIsEnabled;
BOOL isLoggingEnabled;
#ifdef DEBUG
// Specified at Product -> Scheme -> Edit Scheme -> Test -> Arguments -> Environment to avoid things like
// the phone directory being looked up during tests.
loggingIsEnabled = TRUE;
isLoggingEnabled = TRUE;
[DebugLogger.sharedLogger enableTTYLogging];
#elif RELEASE
loggingIsEnabled = OWSPreferences.loggingIsEnabled;
isLoggingEnabled = OWSPreferences.isLoggingEnabled;
#endif
if (loggingIsEnabled) {
if (isLoggingEnabled) {
[DebugLogger.sharedLogger enableFileLogging];
}
@ -117,7 +117,7 @@ static NSString *const kURLHostVerifyPrefix = @"verify";
// ensureIsReadyForAppExtensions may have changed the state of the logging
// preference (due to [NSUserDefaults migrateToSharedUserDefaults]), so honor
// that change if necessary.
if (loggingIsEnabled && !OWSPreferences.loggingIsEnabled) {
if (isLoggingEnabled && !OWSPreferences.isLoggingEnabled) {
[DebugLogger.sharedLogger disableFileLogging];
}
#endif

@ -1408,22 +1408,7 @@ const NSUInteger kOWSProfileManager_MaxAvatarDiameter = 640;
dispatch_once(&onceToken, ^{
profileAvatarsDirPath = OWSProfileManager.sharedDataProfileAvatarsDirPath;
BOOL isDirectory;
BOOL exists = [[NSFileManager defaultManager] fileExistsAtPath:profileAvatarsDirPath isDirectory:&isDirectory];
if (exists) {
OWSAssert(isDirectory);
DDLogInfo(@"Profile avatars directory already exists");
} else {
NSError *error = nil;
[[NSFileManager defaultManager] createDirectoryAtPath:profileAvatarsDirPath
withIntermediateDirectories:YES
attributes:nil
error:&error];
if (error) {
DDLogError(@"Failed to create profile avatars directory: %@", error);
}
}
[OWSFileSystem ensureDirectoryExists:profileAvatarsDirPath];
[OWSFileSystem protectFolderAtPath:profileAvatarsDirPath];
});

@ -90,12 +90,12 @@ NS_ASSUME_NONNULL_BEGIN
OWSTableSection *loggingSection = [OWSTableSection new];
loggingSection.headerTitle = NSLocalizedString(@"LOGGING_SECTION", nil);
[loggingSection addItem:[OWSTableItem switchItemWithText:NSLocalizedString(@"SETTINGS_ADVANCED_DEBUGLOG", @"")
isOn:[OWSPreferences loggingIsEnabled]
isOn:[OWSPreferences isLoggingEnabled]
target:weakSelf
selector:@selector(didToggleEnableLogSwitch:)]];
if ([OWSPreferences loggingIsEnabled]) {
if ([OWSPreferences isLoggingEnabled]) {
[loggingSection
addItem:[OWSTableItem actionItemWithText:NSLocalizedString(@"SETTINGS_ADVANCED_SUBMIT_DEBUGLOG", @"")
actionBlock:^{
@ -263,7 +263,7 @@ NS_ASSUME_NONNULL_BEGIN
[[DebugLogger sharedLogger] enableFileLogging];
}
[OWSPreferences setLoggingEnabled:sender.isOn];
[OWSPreferences setIsLoggingEnabled:sender.isOn];
[self updateTableContents];
}

@ -2700,12 +2700,7 @@ typedef NS_ENUM(NSInteger, MessagesRangeSizeMode) {
{
NSString *temporaryDirectory = NSTemporaryDirectory();
NSString *videoDirPath = [temporaryDirectory stringByAppendingPathComponent:@"videos"];
if (![[NSFileManager defaultManager] fileExistsAtPath:videoDirPath]) {
[[NSFileManager defaultManager] createDirectoryAtPath:videoDirPath
withIntermediateDirectories:YES
attributes:nil
error:nil];
}
[OWSFileSystem ensureDirectoryExists:videoDirPath];
return [NSURL fileURLWithPath:videoDirPath];
}

@ -8,9 +8,9 @@
#import "OWSTableViewController.h"
#import "Signal-Swift.h"
#import "ThreadUtil.h"
#import <Curve25519Kit/Randomness.h>
#import <AFNetworking/AFNetworking.h>
#import <AxolotlKit/PreKeyBundle.h>
#import <Curve25519Kit/Randomness.h>
#import <SignalServiceKit/OWSBatchMessageProcessor.h>
#import <SignalServiceKit/OWSDisappearingConfigurationUpdateInfoMessage.h>
#import <SignalServiceKit/OWSDisappearingMessagesConfiguration.h>
@ -337,19 +337,7 @@ NS_ASSUME_NONNULL_BEGIN
[[fileManager URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject];
NSString *randomFilesDirectoryPath =
[[documentDirectoryURL path] stringByAppendingPathComponent:@"cached_random_files"];
NSError *error;
if (![fileManager fileExistsAtPath:randomFilesDirectoryPath]) {
[fileManager createDirectoryAtPath:randomFilesDirectoryPath
withIntermediateDirectories:YES
attributes:nil
error:&error];
OWSAssert(!error);
if (error) {
DDLogError(@"Error creating directory: %@", error);
failure();
return;
}
}
[OWSFileSystem ensureDirectoryExists:randomFilesDirectoryPath];
NSString *filePath = [randomFilesDirectoryPath stringByAppendingPathComponent:filename];
if ([fileManager fileExistsAtPath:filePath]) {
success(filePath);

@ -27,7 +27,7 @@ static NSString *const OWS102MoveLoggingPreferenceToUserDefaultsMigrationId = @"
if (existingValue) {
DDLogInfo(@"%@ assigning existing value: %@", self.logTag, existingValue);
[OWSPreferences setLoggingEnabled:[existingValue boolValue]];
[OWSPreferences setIsLoggingEnabled:[existingValue boolValue]];
if (![existingValue boolValue]) {
DDLogInfo(@"%@ Disabling file logger after one-time log settings migration.", self.logTag);

@ -3,7 +3,8 @@
//
#import "Pastelog.h"
#include <sys/sysctl.h>
#import "DebugLogger.h"
#import <sys/sysctl.h>
@interface Pastelog ()
@ -59,18 +60,21 @@
otherButtonTitles:nil];
[[self sharedManager].loadingAlertView show];
NSArray *fileNames = fileLogger.logFileManager.sortedLogFileNames;
NSArray *filePaths = fileLogger.logFileManager.sortedLogFilePaths;
NSArray<NSString *> *logFilePaths = DebugLogger.sharedLogger.allLogFilePaths;
NSMutableDictionary *gistFiles = [@{} mutableCopy];
NSMutableDictionary *gistFiles = [NSMutableDictionary new];
NSError *error;
for (unsigned int i = 0; i < [filePaths count]; i++) {
[gistFiles setObject:@{@"content":[NSString stringWithContentsOfFile:[filePaths objectAtIndex:i] encoding:NSUTF8StringEncoding error:&error]} forKey:[fileNames objectAtIndex:i]];
}
if (error) {
for (NSString *logFilePath in logFilePaths) {
NSError *error;
NSString *logContents =
[NSString stringWithContentsOfFile:logFilePath encoding:NSUTF8StringEncoding error:&error];
if (error) {
OWSFail(@"%@ Error loading log file contents: %@", self.logTag, error);
continue;
}
gistFiles[logFilePath.lastPathComponent] = @{
@"content" : logContents,
};
}
NSDictionary *gistDict = @{@"description":[self gistDescription], @"files":gistFiles};

@ -6,6 +6,8 @@
@interface DebugLogger : NSObject
@property (nonatomic) DDFileLogger *fileLogger;
+ (instancetype)sharedLogger;
- (void)enableFileLogging;
@ -16,8 +18,6 @@
- (void)wipeLogs;
- (NSString *)logsDirectory;
@property (nonatomic) DDFileLogger *fileLogger;
- (NSArray<NSString *> *)allLogFilePaths;
@end

@ -4,15 +4,13 @@
#import "DebugLogger.h"
#import "OWSScrubbingLogFormatter.h"
#import <SignalServiceKit/AppContext.h>
#import <SignalServiceKit/NSDate+OWS.h>
#import <SignalServiceKit/OWSFileSystem.h>
#pragma mark Logging - Production logging wants us to write some logs to a file in case we need it for debugging.
#import <CocoaLumberjack/DDTTYLogger.h>
@interface DebugLogger ()
@end
@implementation DebugLogger
+ (instancetype)sharedLogger
@ -25,11 +23,38 @@
return sharedManager;
}
+ (NSString *)mainAppLogsDirPath
{
NSString *dirPath = [[OWSFileSystem cachesDirectoryPath] stringByAppendingPathComponent:@"Logs"];
[OWSFileSystem ensureDirectoryExists:dirPath];
[OWSFileSystem protectFolderAtPath:dirPath];
return dirPath;
}
+ (NSString *)shareExtensionLogsDirPath
{
NSString *dirPath =
[[OWSFileSystem appSharedDataDirectoryPath] stringByAppendingPathComponent:@"ShareExtensionLogs"];
[OWSFileSystem ensureDirectoryExists:dirPath];
[OWSFileSystem protectFolderAtPath:dirPath];
return dirPath;
}
- (NSString *)logsDirPath
{
// This assumes that the only app extension is the share app extension.
return (CurrentAppContext().isMainApp ? DebugLogger.mainAppLogsDirPath : DebugLogger.shareExtensionLogsDirPath);
}
- (void)enableFileLogging
{
NSString *logsDirPath = [self logsDirPath];
// Logging to file, because it's in the Cache folder, they are not uploaded in iTunes/iCloud backups.
self.fileLogger = [DDFileLogger new];
id<DDLogFileManager> logFileManager =
[[DDLogFileManagerDefault alloc] initWithLogsDirectory:logsDirPath defaultFileProtectionLevel:@""];
self.fileLogger = [[DDFileLogger alloc] initWithLogFileManager:logFileManager];
// 24 hour rolling.
self.fileLogger.rollingFrequency = kDayInterval;
// Keep last 3 days of logs - or last 3 logs (if logs rollover due to max file size).
@ -52,22 +77,46 @@
[DDLog addLogger:DDTTYLogger.sharedInstance];
}
- (NSArray<NSString *> *)allLogFilePaths
{
NSFileManager *fileManager = [NSFileManager defaultManager];
NSMutableSet<NSString *> *logPathSet = [NSMutableSet new];
for (NSString *logDirPath in @[
DebugLogger.mainAppLogsDirPath,
DebugLogger.shareExtensionLogsDirPath,
]) {
NSError *error;
for (NSString *filename in [fileManager contentsOfDirectoryAtPath:logDirPath error:&error]) {
NSString *logPath = [logDirPath stringByAppendingPathComponent:filename];
[logPathSet addObject:logPath];
}
if (error) {
OWSFail(@"%@ Failed to find log files: %@", self.logTag, error);
}
}
// To be extra conservative, also add all logs from log file manager.
// This should be redundant with the logic above.
[logPathSet addObjectsFromArray:self.fileLogger.logFileManager.unsortedLogFilePaths];
NSArray<NSString *> *logPaths = logPathSet.allObjects;
return [logPaths sortedArrayUsingSelector:@selector(compare:)];
}
- (void)wipeLogs
{
BOOL reenableLogging = (self.fileLogger ? YES : NO);
NSError *error;
NSArray *logsPath = self.fileLogger.logFileManager.unsortedLogFilePaths;
NSArray<NSString *> *logFilePaths = self.allLogFilePaths;
BOOL reenableLogging = (self.fileLogger ? YES : NO);
if (reenableLogging) {
[self disableFileLogging];
}
for (NSUInteger i = 0; i < logsPath.count; i++) {
[[NSFileManager defaultManager] removeItemAtPath:[logsPath objectAtIndex:i] error:&error];
}
if (error) {
DDLogError(@"Logs couldn't be removed. %@", error.description);
NSFileManager *fileManager = [NSFileManager defaultManager];
NSError *error;
for (NSString *logFilePath in logFilePaths) {
BOOL success = [fileManager removeItemAtPath:logFilePath error:&error];
if (!success || error) {
OWSFail(@"%@ Failed to delete log file: %@", self.logTag, error);
}
}
if (reenableLogging) {
@ -75,26 +124,4 @@
}
}
- (NSString *)logsDirectory
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
NSString *baseDir = ([paths count] > 0) ? [paths objectAtIndex:0] : nil;
NSString *logsDirectory = [baseDir stringByAppendingPathComponent:@"Logs"];
if (![[NSFileManager defaultManager] fileExistsAtPath:logsDirectory]) {
NSError *error;
[[NSFileManager defaultManager] createDirectoryAtPath:logsDirectory
withIntermediateDirectories:YES
attributes:nil
error:nil];
if (error) {
DDLogError(@"Log folder couldn't be created. %@", error.description);
}
}
return logsDirectory;
}
@end

@ -36,8 +36,8 @@ extern NSString *const OWSPreferencesKeyEnableDebugLog;
- (BOOL)getHasArchivedAMessage;
- (void)setHasArchivedAMessage:(BOOL)enabled;
+ (BOOL)loggingIsEnabled;
+ (void)setLoggingEnabled:(BOOL)flag;
+ (BOOL)isLoggingEnabled;
+ (void)setIsLoggingEnabled:(BOOL)flag;
- (BOOL)screenSecurityIsEnabled;
- (void)setScreenSecurity:(BOOL)flag;

@ -3,8 +3,8 @@
//
#import "OWSPreferences.h"
#import "TSStorageHeaders.h"
#import <SignalServiceKit/NSUserDefaults+OWS.h>
#import <SignalServiceKit/TSStorageHeaders.h>
NS_ASSUME_NONNULL_BEGIN
@ -41,7 +41,8 @@ NSString *const OWSPreferencesKey_IsReadyForAppExtensions = @"isReadyForAppExten
#pragma mark - Helpers
- (void)clear {
- (void)clear
{
[NSUserDefaults removeAll];
}
@ -108,7 +109,7 @@ NSString *const OWSPreferencesKey_IsReadyForAppExtensions = @"isReadyForAppExten
}
}
+ (BOOL)loggingIsEnabled
+ (BOOL)isLoggingEnabled
{
NSNumber *preference = [NSUserDefaults.appUserDefaults objectForKey:OWSPreferencesKeyEnableDebugLog];
@ -119,7 +120,7 @@ NSString *const OWSPreferencesKey_IsReadyForAppExtensions = @"isReadyForAppExten
}
}
+ (void)setLoggingEnabled:(BOOL)flag
+ (void)setIsLoggingEnabled:(BOOL)flag
{
// Logging preferences are stored in UserDefaults instead of the database, so that we can (optionally) start
// logging before the database is initialized. This is important because sometimes there are problems *with* the

@ -204,22 +204,7 @@ NS_ASSUME_NONNULL_BEGIN
dispatch_once(&onceToken, ^{
attachmentsFolder = TSAttachmentStream.sharedDataAttachmentsDirPath;
BOOL isDirectory;
BOOL exists = [[NSFileManager defaultManager] fileExistsAtPath:attachmentsFolder isDirectory:&isDirectory];
if (exists) {
OWSAssert(isDirectory);
DDLogInfo(@"Attachments directory already exists");
} else {
NSError *error = nil;
[[NSFileManager defaultManager] createDirectoryAtPath:attachmentsFolder
withIntermediateDirectories:YES
attributes:nil
error:&error];
if (error) {
DDLogError(@"Failed to create attachments directory: %@", error);
}
}
[OWSFileSystem ensureDirectoryExists:attachmentsFolder];
[OWSFileSystem protectFolderAtPath:attachmentsFolder];
});

@ -388,23 +388,9 @@ void setDatabaseInitialized()
{
NSString *databaseDirPath = [[OWSFileSystem appSharedDataDirectoryPath] stringByAppendingPathComponent:@"database"];
NSFileManager *fileManager = [NSFileManager defaultManager];
if (![fileManager fileExistsAtPath:databaseDirPath]) {
NSError *_Nullable error;
BOOL success = [fileManager createDirectoryAtPath:databaseDirPath
withIntermediateDirectories:NO
attributes:nil
error:&error];
if (!success || error) {
NSString *errorDescription =
[NSString stringWithFormat:@"%@ Could not create new database directory: %@, error: %@",
self.logTag,
databaseDirPath,
error];
OWSFail(@"%@", errorDescription);
[NSException raise:TSStorageManagerExceptionName_CouldNotCreateDatabaseDirectory
format:@"%@", errorDescription];
}
if (![OWSFileSystem ensureDirectoryExists:databaseDirPath]) {
[NSException raise:TSStorageManagerExceptionName_CouldNotCreateDatabaseDirectory
format:@"Could not create new database directory"];
}
return databaseDirPath;
}

@ -3,6 +3,7 @@
//
#import "MIMETypeUtil.h"
#import "OWSFileSystem.h"
#if TARGET_OS_IPHONE
#import <MobileCoreServices/MobileCoreServices.h>
@ -321,15 +322,8 @@ NSString *const kSyncMessageFileExtension = @"bin";
NSString *attachmentFolderPath = [folder stringByAppendingPathComponent:uniqueId];
NSError *error = nil;
BOOL attachmentFolderPathExists = [[NSFileManager defaultManager] fileExistsAtPath:attachmentFolderPath];
if (!attachmentFolderPathExists) {
[[NSFileManager defaultManager] createDirectoryAtPath:attachmentFolderPath
withIntermediateDirectories:YES
attributes:nil
error:&error];
if (error) {
OWSFail(@"Failed to create attachment directory: %@", error);
return nil;
}
if (![OWSFileSystem ensureDirectoryExists:attachmentFolderPath]) {
return nil;
}
return [attachmentFolderPath
stringByAppendingPathComponent:[NSString

@ -14,10 +14,15 @@ NS_ASSUME_NONNULL_BEGIN
+ (NSString *)appSharedDataDirectoryPath;
+ (NSString *)cachesDirectoryPath;
+ (void)moveAppFilePath:(NSString *)oldFilePath
sharedDataFilePath:(NSString *)newFilePath
exceptionName:(NSString *)exceptionName;
// Returns NO IFF the directory does not exist and could not be created.
+ (BOOL)ensureDirectoryExists:(NSString *)dirPath;
@end
NS_ASSUME_NONNULL_END

@ -44,6 +44,13 @@ NS_ASSUME_NONNULL_BEGIN
return [groupContainerDirectoryURL path];
}
+ (NSString *)cachesDirectoryPath
{
NSArray<NSString *> *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
OWSAssert(paths.count >= 1);
return paths[0];
}
+ (void)moveAppFilePath:(NSString *)oldFilePath
sharedDataFilePath:(NSString *)newFilePath
exceptionName:(NSString *)exceptionName
@ -82,6 +89,28 @@ NS_ASSUME_NONNULL_BEGIN
fabs([startDate timeIntervalSinceNow]));
}
+ (BOOL)ensureDirectoryExists:(NSString *)dirPath
{
BOOL isDirectory;
BOOL exists = [[NSFileManager defaultManager] fileExistsAtPath:dirPath isDirectory:&isDirectory];
if (exists) {
OWSAssert(isDirectory);
return YES;
} else {
NSError *error = nil;
[[NSFileManager defaultManager] createDirectoryAtPath:dirPath
withIntermediateDirectories:YES
attributes:nil
error:&error];
if (error) {
OWSFail(@"%@ Failed to create directory: %@, error: %@", self.logTag, dirPath, error);
return NO;
}
return YES;
}
}
@end
NS_ASSUME_NONNULL_END

@ -16,37 +16,19 @@ class ShareViewController: UINavigationController, SAELoadViewDelegate {
// This should be the first thing we do.
SetCurrentAppContext(ShareAppExtensionContext())
// DebugLogger.shared().enableTTYLogging()
// if _isDebugAssertConfiguration() {
// DebugLogger.shared().enableFileLogging()
// } else {
// // TODO: Consult OWSPreferences.loggingIsEnabled.
// DebugLogger.shared().enableFileLogging()
// }
DebugLogger.shared().enableTTYLogging()
if _isDebugAssertConfiguration() {
DebugLogger.shared().enableFileLogging()
} else if (OWSPreferences.isLoggingEnabled()) {
// TODO: Consult OWSPreferences.isLoggingEnabled.
DebugLogger.shared().enableFileLogging()
}
_ = AppVersion()
//DDLogWarn(@"%@ application: didFinishLaunchingWithOptions.", self.logTag);
//
//// 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 (due to [NSUserDefaults migrateToSharedUserDefaults]), so honor
// // that change if necessary.
//if (loggingIsEnabled && !OWSPreferences.loggingIsEnabled) {
// [DebugLogger.sharedLogger disableFileLogging];
//}
//#endif
//
//[AppVersion instance];
//
//[self startupLogging];
Logger.debug("\(self.logTag()) \(#function)")
print("\(self.logTag()) \(#function) \(self.view.frame)")
let loadViewController = SAELoadViewController(delegate:self)
self.pushViewController(loadViewController, animated: false)
@ -63,22 +45,19 @@ class ShareViewController: UINavigationController, SAELoadViewDelegate {
//let proofOfSharedStorage = TSAccountManager.localNumber()
let proofOfSharedStorage = "TODO"
print("shared framework: \(proofOfSharedFramework) \n sharedStorage: \(proofOfSharedStorage) \n proof of ssk: \(proofOfSSK)")
Logger.debug("shared framework: \(proofOfSharedFramework) \n sharedStorage: \(proofOfSharedStorage) \n proof of ssk: \(proofOfSSK)")
Logger.debug("\(self.logTag()) \(#function)")
print("\(self.logTag()) \(#function) \(self.view.frame)")
}
override func viewWillAppear(_ animated: Bool) {
Logger.debug("\(self.logTag()) \(#function)")
print("\(self.logTag()) \(#function) \(self.view.frame)")
super.viewWillAppear(animated)
}
override func viewDidAppear(_ animated: Bool) {
Logger.debug("\(self.logTag()) \(#function)")
print("\(self.logTag()) \(#function) \(self.view.frame)")
super.viewDidAppear(animated)
}

@ -9,6 +9,7 @@
#import "UIFont+OWS.h"
#import "UIView+OWS.h"
#import <Foundation/Foundation.h>
#import <SignalMessaging/OWSPreferences.h>
#import <SignalServiceKit/AppContext.h>
#import <SignalServiceKit/AppVersion.h>
#import <SignalServiceKit/Asserts.h>

Loading…
Cancel
Save