@@ -33,8 +33,30 @@ + (SSYLinearFileWriter*)sharedFileWriter {
33
33
}
34
34
35
35
- (void )setPath : (NSString *)path {
36
- NSFileManager * fileManager = [NSFileManager defaultManager ] ;
37
- [fileManager createFileAtPath: path
36
+ NSFileManager * fileManager = [NSFileManager defaultManager ];
37
+
38
+ NSString * parentPath = [path stringByDeletingLastPathComponent ];
39
+ BOOL parentDirectoryIsDirectory = NO ;
40
+ BOOL parentDirectoryExists = [fileManager fileExistsAtPath: parentPath
41
+ isDirectory: &parentDirectoryIsDirectory];
42
+ BOOL needsCreateDirectory = NO ;
43
+ if (parentDirectoryExists) {
44
+ if (!parentDirectoryIsDirectory) {
45
+ [fileManager removeItemAtPath: parentPath
46
+ error: NULL ];
47
+ needsCreateDirectory = YES ;
48
+ }
49
+ } else {
50
+ needsCreateDirectory = YES ;
51
+ }
52
+ if (needsCreateDirectory) {
53
+ [fileManager createDirectoryAtPath: parentPath
54
+ withIntermediateDirectories: YES
55
+ attributes: nil
56
+ error: NULL ];
57
+ }
58
+
59
+ [fileManager createFileAtPath: path
38
60
contents: [NSData data ]
39
61
attributes: nil ] ;
40
62
@@ -56,8 +78,10 @@ - (void)writeLine:(NSString*)line {
56
78
57
79
+ (void )setToPath : (NSString *)path {
58
80
if (sharedFileWriter) {
59
- [sharedFileWriter release ] ;
60
- sharedFileWriter = nil ;
81
+ #if !__has_feature(objc_arc)
82
+ [sharedFileWriter release ] ;
83
+ #endif
84
+ sharedFileWriter = nil ;
61
85
}
62
86
[[SSYLinearFileWriter sharedFileWriter ] setPath: path] ;
63
87
}
@@ -70,11 +94,13 @@ + (void)close {
70
94
[[SSYLinearFileWriter sharedFileWriter ] setFileHandle: nil ] ;
71
95
}
72
96
97
+ #if !__has_feature(objc_arc)
73
98
- (void )dealloc {
74
99
[m_fileHandle release ] ;
75
100
76
101
[super dealloc ] ;
77
102
}
103
+ #endif
78
104
79
105
@end
80
106
0 commit comments