Skip to content

Commit

Permalink
Do not use NSFileManager write/read API so that we can get errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
emsquared committed Aug 12, 2012
1 parent f65a2bc commit 812b4f4
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 15 deletions.
46 changes: 33 additions & 13 deletions Classes/Library/TLOFileLogger.m
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ - (void)updatePropertyListCache /* @private */

// ---- //

NSString *writeError;
NSString *parseError;

#ifdef DEBUG
NSPropertyListFormat format = NSPropertyListXMLFormat_v1_0;
Expand All @@ -189,38 +189,58 @@ - (void)updatePropertyListCache /* @private */

NSData *plist = [NSPropertyListSerialization dataFromPropertyList:propertyList
format:format
errorDescription:&writeError];
errorDescription:&parseError];

// ---- //

if (NSObjectIsEmpty(plist) || writeError) {
LogToConsole(@"Error Creating Property List: %@", writeError);
if (NSObjectIsEmpty(plist) || parseError) {
LogToConsole(@"Error Creating Property List: %@", parseError);
} else {
[_NSFileManager() createFileAtPath:self.filename
contents:plist
attributes:nil];
NSError *dataWriteError;

[_temporaryPropertyListItems removeAllObjects];
[plist writeToFile:self.filename options:0 error:&dataWriteError];

if (dataWriteError) {
LogToConsole(@"Error Writing Property List: %@", [dataWriteError localizedDescription]);

[_temporaryPropertyListItems removeAllObjects];
}
}
}
}

- (NSDictionary *)propertyList /* @private */
{
if (self.writePlainText == NO) {
NSData *rawData = [_NSFileManager() contentsAtPath:self.filename];
if (PointerIsEmpty(rawData) || rawData.length == 0)
NSError *readError;

NSData *rawData = [NSString stringWithContentsOfFile:self.filename
encoding:NSUTF8StringEncoding
error:&readError];

if (readError) {
LogToConsole(@"Error Reading Property List: %@", [readError localizedDescription]);

return [NSDictionary dictionary];
}

// ---- //

if (NSObjectIsEmpty(rawData)) {
return [NSDictionary dictionary];
}

// ---- //

NSString *readError;
NSString *parseError;

NSDictionary *plist = [NSPropertyListSerialization propertyListFromData:rawData
mutabilityOption:NSPropertyListImmutable
format:NULL
errorDescription:&readError];
errorDescription:&parseError];

if (readError) {
DebugLogToConsole(@"Error Reading Property List: %@", readError);
DebugLogToConsole(@"Error Reading Property List: %@", parseError);
} else {
return plist;
}
Expand Down
4 changes: 2 additions & 2 deletions Resources/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@
<key>TXBundleBuildCodeName</key>
<string>Turtle Soup</string>
<key>TXBundleBuildNumber</key>
<string>12346</string>
<string>12347</string>
<key>TXBundleBuildReference</key>
<string>2.1.1p3-305-g84bd6f4-appstore</string>
<string>2.1.1p3-308-gf65a2bc-stdbuild</string>
</dict>
</plist>

0 comments on commit 812b4f4

Please sign in to comment.