mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-21 13:50:29 +00:00
Use a local NSFileManager insead of the defaultManager singleton, which is not thread safe.
This commit is contained in:
parent
333b6e6a8d
commit
7cc52cf4b9
@ -166,6 +166,7 @@ typedef enum CrashReportStatus {
|
|||||||
|
|
||||||
int _analyzerStarted;
|
int _analyzerStarted;
|
||||||
NSString *_crashesDir;
|
NSString *_crashesDir;
|
||||||
|
NSFileManager *_fileManager;
|
||||||
|
|
||||||
BOOL _crashIdenticalCurrentVersion;
|
BOOL _crashIdenticalCurrentVersion;
|
||||||
BOOL _crashReportActivated;
|
BOOL _crashReportActivated;
|
||||||
|
|||||||
@ -76,6 +76,8 @@ NSString *BWQuincyLocalize(NSString *stringToken) {
|
|||||||
- (BOOL)hasNonApprovedCrashReports;
|
- (BOOL)hasNonApprovedCrashReports;
|
||||||
- (BOOL)hasPendingCrashReport;
|
- (BOOL)hasPendingCrashReport;
|
||||||
|
|
||||||
|
@property (nonatomic, retain) NSFileManager *fileManager;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@implementation BWQuincyManager
|
@implementation BWQuincyManager
|
||||||
@ -91,6 +93,8 @@ NSString *BWQuincyLocalize(NSString *stringToken) {
|
|||||||
|
|
||||||
@synthesize appIdentifier = _appIdentifier;
|
@synthesize appIdentifier = _appIdentifier;
|
||||||
|
|
||||||
|
@synthesize fileManager = _fileManager;
|
||||||
|
|
||||||
#if __IPHONE_OS_VERSION_MIN_REQUIRED >= 40000
|
#if __IPHONE_OS_VERSION_MIN_REQUIRED >= 40000
|
||||||
+(BWQuincyManager *)sharedQuincyManager {
|
+(BWQuincyManager *)sharedQuincyManager {
|
||||||
static BWQuincyManager *sharedInstance = nil;
|
static BWQuincyManager *sharedInstance = nil;
|
||||||
@ -128,6 +132,7 @@ NSString *BWQuincyLocalize(NSString *stringToken) {
|
|||||||
_languageStyle = nil;
|
_languageStyle = nil;
|
||||||
_didCrashInLastSession = NO;
|
_didCrashInLastSession = NO;
|
||||||
_loggingEnabled = NO;
|
_loggingEnabled = NO;
|
||||||
|
_fileManager = [[NSFileManager alloc] init];
|
||||||
|
|
||||||
self.delegate = nil;
|
self.delegate = nil;
|
||||||
self.feedbackActivated = NO;
|
self.feedbackActivated = NO;
|
||||||
@ -155,13 +160,11 @@ NSString *BWQuincyLocalize(NSString *stringToken) {
|
|||||||
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
|
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
|
||||||
_crashesDir = [[NSString stringWithFormat:@"%@", [[paths objectAtIndex:0] stringByAppendingPathComponent:@"/crashes/"]] retain];
|
_crashesDir = [[NSString stringWithFormat:@"%@", [[paths objectAtIndex:0] stringByAppendingPathComponent:@"/crashes/"]] retain];
|
||||||
|
|
||||||
NSFileManager *fm = [NSFileManager defaultManager];
|
if (![self.fileManager fileExistsAtPath:_crashesDir]) {
|
||||||
|
|
||||||
if (![fm fileExistsAtPath:_crashesDir]) {
|
|
||||||
NSDictionary *attributes = [NSDictionary dictionaryWithObject: [NSNumber numberWithUnsignedLong: 0755] forKey: NSFilePosixPermissions];
|
NSDictionary *attributes = [NSDictionary dictionaryWithObject: [NSNumber numberWithUnsignedLong: 0755] forKey: NSFilePosixPermissions];
|
||||||
NSError *theError = NULL;
|
NSError *theError = NULL;
|
||||||
|
|
||||||
[fm createDirectoryAtPath:_crashesDir withIntermediateDirectories: YES attributes: attributes error: &theError];
|
[self.fileManager createDirectoryAtPath:_crashesDir withIntermediateDirectories: YES attributes: attributes error: &theError];
|
||||||
}
|
}
|
||||||
|
|
||||||
PLCrashReporter *crashReporter = [PLCrashReporter sharedReporter];
|
PLCrashReporter *crashReporter = [PLCrashReporter sharedReporter];
|
||||||
@ -209,6 +212,9 @@ NSString *BWQuincyLocalize(NSString *stringToken) {
|
|||||||
[_crashesDir release];
|
[_crashesDir release];
|
||||||
[_crashFiles release];
|
[_crashFiles release];
|
||||||
|
|
||||||
|
[_fileManager release];
|
||||||
|
_fileManager = nil;
|
||||||
|
|
||||||
[super dealloc];
|
[super dealloc];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -301,16 +307,14 @@ NSString *BWQuincyLocalize(NSString *stringToken) {
|
|||||||
|
|
||||||
- (BOOL)hasPendingCrashReport {
|
- (BOOL)hasPendingCrashReport {
|
||||||
if (_crashReportActivated) {
|
if (_crashReportActivated) {
|
||||||
NSFileManager *fm = [NSFileManager defaultManager];
|
if ([_crashFiles count] == 0 && [self.fileManager fileExistsAtPath:_crashesDir]) {
|
||||||
|
|
||||||
if ([_crashFiles count] == 0 && [fm fileExistsAtPath:_crashesDir]) {
|
|
||||||
NSString *file = nil;
|
NSString *file = nil;
|
||||||
NSError *error = NULL;
|
NSError *error = NULL;
|
||||||
|
|
||||||
NSDirectoryEnumerator *dirEnum = [fm enumeratorAtPath: _crashesDir];
|
NSDirectoryEnumerator *dirEnum = [self.fileManager enumeratorAtPath: _crashesDir];
|
||||||
|
|
||||||
while ((file = [dirEnum nextObject])) {
|
while ((file = [dirEnum nextObject])) {
|
||||||
NSDictionary *fileAttributes = [fm attributesOfItemAtPath:[_crashesDir stringByAppendingPathComponent:file] error:&error];
|
NSDictionary *fileAttributes = [self.fileManager attributesOfItemAtPath:[_crashesDir stringByAppendingPathComponent:file] error:&error];
|
||||||
if ([[fileAttributes objectForKey:NSFileSize] intValue] > 0) {
|
if ([[fileAttributes objectForKey:NSFileSize] intValue] > 0) {
|
||||||
[_crashFiles addObject:file];
|
[_crashFiles addObject:file];
|
||||||
}
|
}
|
||||||
@ -462,7 +466,6 @@ NSString *BWQuincyLocalize(NSString *stringToken) {
|
|||||||
- (void)_performSendingCrashReports {
|
- (void)_performSendingCrashReports {
|
||||||
NSMutableDictionary *approvedCrashReports = [NSMutableDictionary dictionaryWithDictionary:[[NSUserDefaults standardUserDefaults] dictionaryForKey: kApprovedCrashReports]];
|
NSMutableDictionary *approvedCrashReports = [NSMutableDictionary dictionaryWithDictionary:[[NSUserDefaults standardUserDefaults] dictionaryForKey: kApprovedCrashReports]];
|
||||||
|
|
||||||
NSFileManager *fm = [NSFileManager defaultManager];
|
|
||||||
NSError *error = NULL;
|
NSError *error = NULL;
|
||||||
|
|
||||||
NSString *userid = @"";
|
NSString *userid = @"";
|
||||||
@ -523,7 +526,7 @@ NSString *BWQuincyLocalize(NSString *stringToken) {
|
|||||||
[approvedCrashReports setObject:[NSNumber numberWithBool:YES] forKey:[_crashFiles objectAtIndex:i]];
|
[approvedCrashReports setObject:[NSNumber numberWithBool:YES] forKey:[_crashFiles objectAtIndex:i]];
|
||||||
} else {
|
} else {
|
||||||
// we cannot do anything with this report, so delete it
|
// we cannot do anything with this report, so delete it
|
||||||
[fm removeItemAtPath:filename error:&error];
|
[self.fileManager removeItemAtPath:filename error:&error];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -541,10 +544,8 @@ NSString *BWQuincyLocalize(NSString *stringToken) {
|
|||||||
- (void)_cleanCrashReports {
|
- (void)_cleanCrashReports {
|
||||||
NSError *error = NULL;
|
NSError *error = NULL;
|
||||||
|
|
||||||
NSFileManager *fm = [NSFileManager defaultManager];
|
|
||||||
|
|
||||||
for (NSUInteger i=0; i < [_crashFiles count]; i++) {
|
for (NSUInteger i=0; i < [_crashFiles count]; i++) {
|
||||||
[fm removeItemAtPath:[_crashesDir stringByAppendingPathComponent:[_crashFiles objectAtIndex:i]] error:&error];
|
[self.fileManager removeItemAtPath:[_crashesDir stringByAppendingPathComponent:[_crashFiles objectAtIndex:i]] error:&error];
|
||||||
}
|
}
|
||||||
[_crashFiles removeAllObjects];
|
[_crashFiles removeAllObjects];
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user