cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mmo...@apache.org
Subject [1/2] ios commit: [ios] bugfixes and comments.
Date Mon, 22 Oct 2012 19:36:04 GMT
Updated Branches:
  refs/heads/master 78ba908ce -> 1dca15cfe


[ios] bugfixes and comments.


Project: http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/commit/1dca15cf
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/tree/1dca15cf
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/diff/1dca15cf

Branch: refs/heads/master
Commit: 1dca15cfe943a3aa45e886409780883977337caa
Parents: a39921b
Author: Michal Mocny <mmocny@gmail.com>
Authored: Mon Oct 22 15:24:27 2012 -0400
Committer: Michal Mocny <mmocny@gmail.com>
Committed: Mon Oct 22 15:36:28 2012 -0400

----------------------------------------------------------------------
 CordovaLib/Classes/CDVLocalStorage.m            |   38 +++++++++++------
 CordovaLib/Classes/CDVViewController.m          |    1 -
 bin/templates/project/__TESTING__/Cordova.plist |    2 +-
 3 files changed, 25 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/blob/1dca15cf/CordovaLib/Classes/CDVLocalStorage.m
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVLocalStorage.m b/CordovaLib/Classes/CDVLocalStorage.m
index 79e8db7..4e9a491 100644
--- a/CordovaLib/Classes/CDVLocalStorage.m
+++ b/CordovaLib/Classes/CDVLocalStorage.m
@@ -38,7 +38,7 @@
         [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onResignActive)
                                                      name:UIApplicationWillResignActiveNotification
object:nil];
 
-        self.backupInfo = [[self class] createBackupInfoWithCloudBackup:((NSString*)[classSettings
objectForKey:@"backupType"] == @"cloud")];
+        self.backupInfo = [[self class] createBackupInfoWithCloudBackup:[(NSString*)[classSettings
objectForKey:@"backupType"] isEqualToString:@"cloud"]];
 
         // over-ride current webview delegate (for restore reasons)
         self.webviewDelegate = theWebView.delegate;
@@ -53,6 +53,16 @@
 
 + (NSMutableArray*)createBackupInfoWithTargetDir:(NSString*)targetDir backupDir:(NSString*)backupDir
targetDirNests:(BOOL)targetDirNests backupDirNests:(BOOL)backupDirNests rename:(BOOL)rename
 {
+    /*
+     This "helper" does so much work and has so many options it would probably be clearer
to refactor the whole thing.
+     Basically, there are three database locations:
+
+     1. "Normal" dir -- LIB/<nested dires WebKit/LocalStorage etc>/<normal filenames>
+     2. "Caches" dir -- LIB/Caches/<normal filenames>
+     3. "Backup" dir -- DOC/Backups/<renamed filenames>
+
+     And between these three, there are various migration paths, most of which only consider
2 of the 3, which is why this helper is based on 2 locations and has a notion of "direction".
+     */
     NSMutableArray* backupInfo = [NSMutableArray arrayWithCapacity:3];
 
     NSString* original;
@@ -63,7 +73,7 @@
 
     original = [targetDir stringByAppendingPathComponent:targetDirNests ? @"WebKit/LocalStorage/file__0.localstorage":@"file__0.localstorage"];
     backup = [backupDir stringByAppendingPathComponent:(backupDirNests ? @"WebKit/LocalStorage":@"")];
-    backup = [backupDir stringByAppendingPathComponent:(rename ? @"localstorage.appdata.db":@"file__0.localstorage")];
+    backup = [backup stringByAppendingPathComponent:(rename ? @"localstorage.appdata.db":@"file__0.localstorage")];
 
     backupItem = [[CDVBackupInfo alloc] init];
     backupItem.backup = backup;
@@ -76,7 +86,7 @@
 
     original = [targetDir stringByAppendingPathComponent:targetDirNests ? @"WebKit/Databases/Databases.db":@"Databases.db"];
     backup = [backupDir stringByAppendingPathComponent:(backupDirNests ? @"WebKit/Databases":@"")];
-    backup = [backupDir stringByAppendingPathComponent:(rename ? @"websqlmain.appdata.db":@"Databases.db")];
+    backup = [backup stringByAppendingPathComponent:(rename ? @"websqlmain.appdata.db":@"Databases.db")];
 
     backupItem = [[CDVBackupInfo alloc] init];
     backupItem.backup = backup;
@@ -89,7 +99,7 @@
 
     original = [targetDir stringByAppendingPathComponent:targetDirNests ? @"WebKit/Databases/file__0":@"file__0"];
     backup = [backupDir stringByAppendingPathComponent:(backupDirNests ? @"WebKit/Databases":@"")];
-    backup = [backupDir stringByAppendingPathComponent:(rename ? @"websqldbs.appdata.db":@"file__0")];
+    backup = [backup stringByAppendingPathComponent:(rename ? @"websqldbs.appdata.db":@"file__0")];
 
     backupItem = [[CDVBackupInfo alloc] init];
     backupItem.backup = backup;
@@ -111,15 +121,15 @@
 
     // create the backups folder, if needed
     [[NSFileManager defaultManager] createDirectoryAtPath:backupsFolder withIntermediateDirectories:YES
attributes:nil error:nil];
-    [self addSkipBackupAttributeToItemAtURL:[NSURL fileURLWithPath:backupsFolder] skip:cloudBackup];
+
+    [self addSkipBackupAttributeToItemAtURL:[NSURL fileURLWithPath:backupsFolder] skip:!cloudBackup];
 
     return [self createBackupInfoWithTargetDir:cacheFolder backupDir:backupsFolder targetDirNests:NO
backupDirNests:NO rename:YES];
 }
 
 + (BOOL)addSkipBackupAttributeToItemAtURL:(NSURL*)URL skip:(BOOL)skip
 {
-    assert(IsAtLeastiOSVersion(@"5.1"));
-    assert([[NSFileManager defaultManager] fileExistsAtPath:[URL path]]);
+    NSAssert(IsAtLeastiOSVersion(@"5.1"), @"Cannot mark files for NSURLIsExcludedFromBackupKey
on iOS less than 5.1");
 
     NSError* error = nil;
     BOOL success = [URL setResourceValue:[NSNumber numberWithBool:skip] forKey:NSURLIsExcludedFromBackupKey
error:&error];
@@ -335,31 +345,31 @@
     NSString* appLibraryFolder = [NSSearchPathForDirectoriesInDomains (NSLibraryDirectory,
NSUserDomainMask, YES) objectAtIndex:0];
     NSString* appDocumentsFolder = [NSSearchPathForDirectoriesInDomains (NSDocumentDirectory,
NSUserDomainMask, YES) objectAtIndex:0];
 
-    NSMutableArray* backupInfo = nil;
+    NSMutableArray* backupInfo = [NSMutableArray arrayWithCapacity:0];
 
     if ([backupType isEqualToString:@"cloud"]) {
         // We would like to restore old backups/caches databases to the new destination (nested
in lib folder)
         [backupInfo addObjectsFromArray:[self createBackupInfoWithTargetDir:appLibraryFolder
backupDir:[appDocumentsFolder stringByAppendingPathComponent:@"Backups"] targetDirNests:YES
backupDirNests:NO rename:YES]];
         [backupInfo addObjectsFromArray:[self createBackupInfoWithTargetDir:appLibraryFolder
backupDir:[appLibraryFolder stringByAppendingPathComponent:@"Caches"] targetDirNests:YES backupDirNests:NO
rename:NO]];
     } else {
-        assert([backupType isEqualToString:@"local"]);
+        // For ios6 local backups we also want to restore from Backups dir -- but we don't
need to do that here, since the plugin will do that itself.
         [backupInfo addObjectsFromArray:[self createBackupInfoWithTargetDir:[appLibraryFolder
stringByAppendingPathComponent:@"Caches"] backupDir:appLibraryFolder targetDirNests:NO backupDirNests:YES
rename:NO]];
     }
 
     NSFileManager* manager = [NSFileManager defaultManager];
 
     for (CDVBackupInfo* info in backupInfo) {
-        if ([info shouldRestore]) {
-            NSLog(@"Restoring old webstorage backup. From: '%@' To: '%@'.", info.backup,
info.original);
-            [self copyFrom:info.backup to:info.original error:nil];
-        }
         if ([manager fileExistsAtPath:info.backup]) {
+            if ([info shouldRestore]) {
+                NSLog(@"Restoring old webstorage backup. From: '%@' To: '%@'.", info.backup,
info.original);
+                [self copyFrom:info.backup to:info.original error:nil];
+            }
             NSLog(@"Removing old webstorage backup: '%@'.", info.backup);
             [manager removeItemAtPath:info.backup error:nil];
         }
     }
 
-    [[NSUserDefaults standardUserDefaults] setBool:(backupType == @"cloud") forKey:@"WebKitStoreWebDataForBackup"];
+    [[NSUserDefaults standardUserDefaults] setBool:[backupType isEqualToString:@"cloud"]
forKey:@"WebKitStoreWebDataForBackup"];
 }
 
 #pragma mark -

http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/blob/1dca15cf/CordovaLib/Classes/CDVViewController.m
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVViewController.m b/CordovaLib/Classes/CDVViewController.m
index c1648d9..35e3d98 100644
--- a/CordovaLib/Classes/CDVViewController.m
+++ b/CordovaLib/Classes/CDVViewController.m
@@ -183,7 +183,6 @@
     } else if ([backupWebStorage isKindOfClass:[NSNumber class]]) {
         backupWebStorageType = [(NSNumber*) backupWebStorage boolValue] ? @"cloud" : @"none";
     }
-    NSLog(@"BackupType: %@", backupWebStorageType);
 
     if (IsAtLeastiOSVersion(@"5.1")) {
         [CDVLocalStorage __fixupDatabaseLocationsWithBackupType:backupWebStorageType];

http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/blob/1dca15cf/bin/templates/project/__TESTING__/Cordova.plist
----------------------------------------------------------------------
diff --git a/bin/templates/project/__TESTING__/Cordova.plist b/bin/templates/project/__TESTING__/Cordova.plist
index 2c92742..3200bd1 100644
--- a/bin/templates/project/__TESTING__/Cordova.plist
+++ b/bin/templates/project/__TESTING__/Cordova.plist
@@ -45,7 +45,7 @@
 	<key>OpenAllWhitelistURLsInWebView</key>
 	<false/>
 	<key>BackupWebStorage</key>
-	<string>gray</string>
+	<string>cloud</string>
 	<key>ExternalHosts</key>
 	<array/>
 	<key>Plugins</key>


Mime
View raw message