Proyectos de Subversion Iphone Microlearning

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
// Copyright 2021 Google LLC
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
//      http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14
 
15
#import "Crashlytics/Crashlytics/Models/FIRCLSLaunchMarkerModel.h"
16
 
17
#import "Crashlytics/Crashlytics/Helpers/FIRCLSInternalLogging.h"
18
 
19
@interface FIRCLSLaunchMarkerModel ()
20
 
21
@property(nonatomic, strong) FIRCLSFileManager *fileManager;
22
 
23
@end
24
 
25
@implementation FIRCLSLaunchMarkerModel
26
 
27
- (instancetype)initWithFileManager:(FIRCLSFileManager *)fileManager {
28
  self = [super init];
29
  if (!self) {
30
    return nil;
31
  }
32
 
33
  _fileManager = fileManager;
34
 
35
  return self;
36
}
37
 
38
- (BOOL)checkForAndCreateLaunchMarker {
39
  BOOL launchFailure = [self launchFailureMarkerPresent];
40
  if (launchFailure) {
41
    FIRCLSDeveloperLog("Crashlytics:Crash",
42
                       @"Last launch failed: this may indicate a crash shortly after app launch.");
43
  } else {
44
    [self createLaunchFailureMarker];
45
  }
46
 
47
  return launchFailure;
48
}
49
 
50
- (NSString *)launchFailureMarkerPath {
51
  return [[_fileManager structurePath] stringByAppendingPathComponent:@"launchmarker"];
52
}
53
 
54
- (BOOL)createLaunchFailureMarker {
55
  // It's tempting to use - [NSFileManger createFileAtPath:contents:attributes:] here. But that
56
  // operation, even with empty/nil contents does a ton of work to write out nothing via a
57
  // temporarly file. This is a much faster implemenation.
58
  const char *path = [[self launchFailureMarkerPath] fileSystemRepresentation];
59
 
60
#if TARGET_OS_IPHONE
61
  /*
62
   * data-protected non-portable open(2) :
63
   * int open_dprotected_np(user_addr_t path, int flags, int class, int dpflags, int mode)
64
   */
65
  int fd = open_dprotected_np(path, O_WRONLY | O_CREAT | O_TRUNC, 4, 0, 0644);
66
#else
67
  int fd = open(path, O_WRONLY | O_CREAT | O_TRUNC, 0644);
68
#endif
69
  if (fd == -1) {
70
    return NO;
71
  }
72
 
73
  return close(fd) == 0;
74
}
75
 
76
- (BOOL)launchFailureMarkerPresent {
77
  return [[_fileManager underlyingFileManager] fileExistsAtPath:[self launchFailureMarkerPath]];
78
}
79
 
80
- (BOOL)removeLaunchFailureMarker {
81
  return [_fileManager removeItemAtPath:[self launchFailureMarkerPath]];
82
}
83
 
84
@end