I'm using GTMLogger and have the following piece of code that seems to be crashing since moving to iOS5.1 . The weird thing i can't seem to reproduce it, but i know its happening to many users, so I'm not sure how to track it.
[NSConcreteFileHandle writeData:]: Bad file descriptor
I could just try/catch it but its not a solution as much as a workaround.
This is the suspicious part:
NSFileHandle *file = [NSFileHandle fileHandleForUpdatingAtPath:logFilePath];
if (file)
{
unsigned long long maxFileOffset = [file seekToEndOfFile];
if (maxFileOffset > kDebugFileMaxSize)
{
// read file, trunicate, save, reopen
[file seekToFileOffset:maxFileOffset - kDebugFileMaxSize];
NSMutableData *data = [NSMutableData dataWithData:[file readDataToEndOfFile]];
[file seekToFileOffset:0];
[file writeData:data];
[file truncateFileAtOffset:kDebugFileMaxSize];
[file seekToEndOfFile];
}
}
else
{
[[NSFileManager defaultManager] createFileAtPath:logFilePath contents:nil attributes:nil];
file = [NSFileHandle fileHandleForUpdatingAtPath:logFilePath];
}
Anyone ever got something like that ?
I eventually just got rid of GTMLogger and moved to some other logger, thanks for anyone who might've read this :)