Fix bug 323847: save a copy of the corrupted bookmarks file when we fail to read bookmarks.

This commit is contained in:
smfr%smfr.org 2006-01-22 19:43:23 +00:00
parent d0645e169e
commit 0848e5b26a
4 changed files with 31 additions and 1 deletions

View File

@ -1112,7 +1112,6 @@ Otherwise, we return the URL we originally got. Right now this supports .url and
// them or we may get this event at startup before we've had time to load
// our window.
BrowserWindowController* controller = (BrowserWindowController*)[[self getFrontmostBrowserWindow] windowController];
BOOL tabOrWindowIsAvailable = (controller && [[controller getBrowserWrapper] isEmpty] && ![[controller getBrowserWrapper] isBusy]);
if (controller) {
BOOL tabOrWindowIsAvailable = ([[controller getBrowserWrapper] isEmpty] && ![[controller getBrowserWrapper] isBusy]);

View File

@ -1175,6 +1175,13 @@ static BookmarkManager* gBookmarkManager = nil;
{
if ([self readPListBookmarks:bookmarkPath])
return YES;
else
{
// save the corrupted bookmarks to a backup file
NSString* uniqueName = [fM backupFileNameFromPath:bookmarkPath withSuffix:@"-corrupted"];
[fM copyPath:bookmarkPath toPath:uniqueName handler:nil];
NSLog(@"Copied corrupted bookmarks file to %@", uniqueName);
}
}
else if ([fM isReadableFileAtPath:[profileDir stringByAppendingPathComponent:@"bookmarks.xml"]])
{

View File

@ -45,4 +45,8 @@
// this will return -1 on error
- (long long)sizeOfFileAtPath:(NSString*)inPath traverseLink:(BOOL)inTraverseLink;
// make a name for a backup file with the given path and suffix
// (e.g. bookmarks.plist will be changed to "bookmarksSUFFIX-1.plist".
- (NSString*)backupFileNameFromPath:(NSString*)inPath withSuffix:(NSString*)inFileSuffix;
@end

View File

@ -81,5 +81,25 @@
return [fileSize longLongValue];
}
- (NSString*)backupFileNameFromPath:(NSString*)inPath withSuffix:(NSString*)inFileSuffix
{
NSString* pathWithoutExtension = [inPath stringByDeletingPathExtension];
NSString* fileExtension = [inPath pathExtension];
int sequenceNumber = 1;
NSString* newName = nil;
do {
NSString* sequenceString = [NSString stringWithFormat:@"%@-%d", inFileSuffix, sequenceNumber];
newName = [pathWithoutExtension stringByAppendingString:sequenceString];
newName = [newName stringByAppendingPathExtension:fileExtension];
++sequenceNumber;
} while ([self fileExistsAtPath:newName]);
return newName;
}
@end