aboutsummaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorstuconnolly <stuart02@gmail.com>2012-05-29 09:23:45 +0000
committerstuconnolly <stuart02@gmail.com>2012-05-29 09:23:45 +0000
commite97e966f09245cf9df982c6102e9d0a6ee111ff6 (patch)
treec70cb664ed78e9f7275228c1bac0473540cc1e04 /Source
parent93005290f2ceee7a573d69379a4d1f1875d5aa95 (diff)
downloadsequelpro-e97e966f09245cf9df982c6102e9d0a6ee111ff6.tar.gz
sequelpro-e97e966f09245cf9df982c6102e9d0a6ee111ff6.tar.bz2
sequelpro-e97e966f09245cf9df982c6102e9d0a6ee111ff6.zip
Favorites saving:
- Switch to using a UUID for the backup filename to prevent issues of it already existing. - Fix an obvious logic error whereby the saving would be aborted when we couldn't create the backup file (fixes issue #1357).
Diffstat (limited to 'Source')
-rw-r--r--Source/SPFavoritesController.m49
1 files changed, 24 insertions, 25 deletions
diff --git a/Source/SPFavoritesController.m b/Source/SPFavoritesController.m
index 2a432326..0a069b3a 100644
--- a/Source/SPFavoritesController.m
+++ b/Source/SPFavoritesController.m
@@ -369,7 +369,7 @@ static SPFavoritesController *sharedFavoritesController = nil;
}
NSString *favoritesFile = [dataPath stringByAppendingPathComponent:SPFavoritesDataFile];
- NSString *favoritesBackupFile = [dataPath stringByAppendingPathComponent:[@"~" stringByAppendingString:SPFavoritesDataFile]];
+ NSString *favoritesBackupFile = [dataPath stringByAppendingPathComponent:[NSString stringWithNewUUID]];
// If the favorites data file already exists, attempt to move it to keep as a backup
if ([fileManager fileExistsAtPath:favoritesFile]) {
@@ -389,36 +389,35 @@ static SPFavoritesController *sharedFavoritesController = nil;
return;
}
}
- else {
- NSDictionary *dictionary = [NSDictionary dictionaryWithObject:data forKey:SPFavoritesRootKey];
-
- // Convert the current favorites tree to a dictionary representation to create the plist data
- NSData *plistData = [NSPropertyListSerialization dataFromPropertyList:dictionary
- format:NSPropertyListXMLFormat_v1_0
- errorDescription:&errorString];
+
+ NSDictionary *dictionary = [NSDictionary dictionaryWithObject:data forKey:SPFavoritesRootKey];
+
+ // Convert the current favorites tree to a dictionary representation to create the plist data
+ NSData *plistData = [NSPropertyListSerialization dataFromPropertyList:dictionary
+ format:NSPropertyListXMLFormat_v1_0
+ errorDescription:&errorString];
+
+ if (plistData) {
+ [plistData writeToFile:favoritesFile options:NSAtomicWrite error:&error];
- if (plistData) {
- [plistData writeToFile:favoritesFile options:NSAtomicWrite error:&error];
+ if (error) {
+ NSLog(@"Error writing favorites data. Restoring backup if available: %@", [error localizedDescription]);
- if (error) {
- NSLog(@"Error writing favorites data. Restoring backup if available: %@", [error localizedDescription]);
-
- // Restore the original data file
- [fileManager moveItemAtPath:favoritesBackupFile toPath:favoritesFile error:NULL];
- }
- else {
- // Remove the original backup
- [fileManager removeItemAtPath:favoritesBackupFile error:NULL];
- }
+ // Restore the original data file
+ [fileManager moveItemAtPath:favoritesBackupFile toPath:favoritesFile error:NULL];
}
- else if (errorString) {
- NSLog(@"Error converting favorites data to plist format: %@", errorString);
-
- [errorString release];
-
+ else {
+ // Remove the original backup
[fileManager removeItemAtPath:favoritesBackupFile error:NULL];
}
}
+ else if (errorString) {
+ NSLog(@"Error converting favorites data to plist format: %@", errorString);
+
+ [errorString release];
+
+ [fileManager removeItemAtPath:favoritesBackupFile error:NULL];
+ }
pthread_mutex_unlock(&writeLock);