incubator-callback-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mmo...@apache.org
Subject ios commit: IOS6 - Fixing LocalStorage/WebSQL storage locations
Date Fri, 05 Oct 2012 14:13:44 GMT
Updated Branches:
  refs/heads/master 035e2fb9b -> 6e170879a


IOS6 - Fixing LocalStorage/WebSQL storage locations

1. Restore legacy versions of the databases to support upgrades to
ios/cordova (CB-1558)
2. Change backup data directory, so its not in the user Documents folder
any more (CB-1561)
3. Change IOS6 to not backup to iCloud, but instead use manual backups
just like on ios5.1


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/6e170879
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/tree/6e170879
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/diff/6e170879

Branch: refs/heads/master
Commit: 6e170879aa37d33701739fc3c28ed9f78156bf1f
Parents: 035e2fb
Author: Michal Mocny <mmocny@gmail.com>
Authored: Fri Oct 5 10:09:17 2012 -0400
Committer: Michal Mocny <mmocny@gmail.com>
Committed: Fri Oct 5 10:09:17 2012 -0400

----------------------------------------------------------------------
 CordovaLib/Classes/CDVLocalStorage.h   |    2 +-
 CordovaLib/Classes/CDVLocalStorage.m   |   81 +++++++++++++++++---------
 CordovaLib/Classes/CDVViewController.m |   16 +----
 3 files changed, 58 insertions(+), 41 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/blob/6e170879/CordovaLib/Classes/CDVLocalStorage.h
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVLocalStorage.h b/CordovaLib/Classes/CDVLocalStorage.h
index 686e519..251eb17 100644
--- a/CordovaLib/Classes/CDVLocalStorage.h
+++ b/CordovaLib/Classes/CDVLocalStorage.h
@@ -36,7 +36,7 @@
 + (BOOL)__verifyAndFixDatabaseLocationsWithAppPlistDict:(NSMutableDictionary*)appPlistDict
     bundlePath                                          :(NSString*)bundlePath
    fileManager                                         :(NSFileManager*)fileManager;
-+ (void)__restoreThenRemoveBackupLocations;
++ (void)__fixLegacyDatabaseLocationIssues;
 @end
 
 @interface CDVBackupInfo : NSObject

http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/blob/6e170879/CordovaLib/Classes/CDVLocalStorage.m
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVLocalStorage.m b/CordovaLib/Classes/CDVLocalStorage.m
index 0e539f1..8f87be0 100644
--- a/CordovaLib/Classes/CDVLocalStorage.m
+++ b/CordovaLib/Classes/CDVLocalStorage.m
@@ -54,27 +54,20 @@
 #pragma mark -
 #pragma mark Plugin interface methods
 
-+ (NSMutableArray*)createBackupInfo
++ (NSMutableArray*)createBackupInfoWithTargetDir:(NSString*)targetDir backupDir:(NSString*)backupDir
rename:(BOOL)rename
 {
     NSMutableArray* backupInfo = [NSMutableArray arrayWithCapacity:3];
 
-    // set up common folders
-    NSString* appLibraryFolder = [NSSearchPathForDirectoriesInDomains (NSLibraryDirectory,
NSUserDomainMask, YES) objectAtIndex:0];
-    NSString* appDocumentsFolder = [NSSearchPathForDirectoriesInDomains (NSDocumentDirectory,
NSUserDomainMask, YES) objectAtIndex:0];
-    NSString* backupsFolder = [appDocumentsFolder stringByAppendingPathComponent:@"Backups"];
-
-    // create the backups folder
-    [[NSFileManager defaultManager] createDirectoryAtPath:backupsFolder withIntermediateDirectories:YES
attributes:nil error:nil];
+    NSString* original;
+    NSString* backup;
+    CDVBackupInfo* backupItem;
 
     // ////////// LOCALSTORAGE
 
-    NSString* original = [[appLibraryFolder stringByAppendingPathComponent           :
-            (IsAtLeastiOSVersion(@"5.1") && !IsAtLeastiOSVersion(@"6.0")) ? @"Caches":@"WebKit/LocalStorage"]
-        stringByAppendingPathComponent:@"file__0.localstorage"];
+    original = [targetDir stringByAppendingPathComponent:@"file__0.localstorage"];
+    backup = [backupDir stringByAppendingPathComponent:rename ? @"localstorage.appdata.db":@"file__0.localstorage"];
 
-    NSString* backup = [backupsFolder stringByAppendingPathComponent:@"localstorage.appdata.db"];
-
-    CDVBackupInfo* backupItem = [[CDVBackupInfo alloc] init];
+    backupItem = [[CDVBackupInfo alloc] init];
     backupItem.backup = backup;
     backupItem.original = original;
     backupItem.label = @"localStorage database";
@@ -83,11 +76,8 @@
 
     // ////////// WEBSQL MAIN DB
 
-    original = [[appLibraryFolder stringByAppendingPathComponent                     :
-            (IsAtLeastiOSVersion(@"5.1") && !IsAtLeastiOSVersion(@"6.0")) ? @"Caches":@"WebKit/Databases"]
-        stringByAppendingPathComponent:@"Databases.db"];
-
-    backup = [backupsFolder stringByAppendingPathComponent:@"websqlmain.appdata.db"];
+    original = [targetDir stringByAppendingPathComponent:@"Databases.db"];
+    backup = [backupDir stringByAppendingPathComponent:rename ? @"websqlmain.appdata.db":@"Databases.db"];
 
     backupItem = [[CDVBackupInfo alloc] init];
     backupItem.backup = backup;
@@ -98,11 +88,8 @@
 
     // ////////// WEBSQL DATABASES
 
-    original = [[appLibraryFolder stringByAppendingPathComponent                     :
-            (IsAtLeastiOSVersion(@"5.1") && !IsAtLeastiOSVersion(@"6.0")) ? @"Caches":@"WebKit/Databases"]
-        stringByAppendingPathComponent:@"file__0"];
-
-    backup = [backupsFolder stringByAppendingPathComponent:@"websqldbs.appdata.db"];
+    original = [targetDir stringByAppendingPathComponent:@"file__0"];
+    backup = [backupDir stringByAppendingPathComponent:rename ? @"websqldbs.appdata.db":@"file__0"];
 
     backupItem = [[CDVBackupInfo alloc] init];
     backupItem.backup = backup;
@@ -114,6 +101,18 @@
     return backupInfo;
 }
 
++ (NSMutableArray*)createBackupInfo
+{
+    NSString* appLibraryFolder = [NSSearchPathForDirectoriesInDomains (NSLibraryDirectory,
NSUserDomainMask, YES) objectAtIndex:0];
+    NSString* cacheFolder = [appLibraryFolder stringByAppendingPathComponent:@"Caches"];
+    NSString* backupsFolder = [appLibraryFolder stringByAppendingPathComponent:@"Backups"];
+
+    // create the backups folder
+    [[NSFileManager defaultManager] createDirectoryAtPath:backupsFolder withIntermediateDirectories:YES
attributes:nil error:nil];
+
+    return [self createBackupInfoWithTargetDir:cacheFolder backupDir:backupsFolder rename:YES];
+}
+
 + (BOOL)copyFrom:(NSString*)src to:(NSString*)dest error:(NSError * __autoreleasing*)error
 {
     NSFileManager* fileManager = [NSFileManager defaultManager];
@@ -304,16 +303,42 @@
     return dirty;
 }
 
-+ (void)__restoreThenRemoveBackupLocations
++ (void)__fixLegacyDatabaseLocationIssues
 {
-    NSMutableArray* backupInfo = [CDVLocalStorage createBackupInfo];
+    if (IsAtLeastiOSVersion(@"6.0")) {
+        // Ensure that the webview does not backup the databases to iCloud (We set to this
true in 2.1, so need to reset it for upgraders).
+        [[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"WebKitStoreWebDataForBackup"];
+    }
+
+    /*
+     * There are currently two legacy storage locations:
+     *   {Lib}/WebKit/LocalStorage which was used for store database (without backup renaming)
in ios <5.1 and briefly for ios6, and
+     *   {Doc}/Backups which was used to store database backups (with backup renaming) with
ios5.1+ until Apple started rejecting apps
+     *      for using the {Doc} folder to save non user generated content.
+     */
+    NSString* appLibraryFolder = [NSSearchPathForDirectoriesInDomains (NSLibraryDirectory,
NSUserDomainMask, YES) objectAtIndex:0];
+    NSString* appDocumentsFolder = [NSSearchPathForDirectoriesInDomains (NSDocumentDirectory,
NSUserDomainMask, YES) objectAtIndex:0];
+
+    // targetDir is where we want our databases to end up
+    NSString* targetDir = [appLibraryFolder stringByAppendingPathComponent:@"Caches"];
+
+    // backupDir's are the places where we may find old legacy backups
+    NSString* backupDir = [appDocumentsFolder stringByAppendingPathComponent:@"Backups"];
+    NSString* backupDir2 = [appLibraryFolder stringByAppendingPathComponent:@"WebKit/LocalStorage"];
+
+    NSMutableArray* backupInfo = [self createBackupInfoWithTargetDir:targetDir backupDir:backupDir
rename:YES];
+    [backupInfo addObjectsFromArray:[self createBackupInfoWithTargetDir:targetDir backupDir:backupDir2
rename:NO]];
+
     NSFileManager* manager = [NSFileManager defaultManager];
 
     for (CDVBackupInfo* info in backupInfo) {
-        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];
+        }
+        if ([manager fileExistsAtPath:info.backup]) {
+            NSLog(@"Removing old webstorage backup: '%@'.", info.backup);
             [manager removeItemAtPath:info.backup error:nil];
-            NSLog(@"Restoring, then removing old webstorage backup. From: '%@' To: '%@'.",
info.backup, info.original);
         }
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/blob/6e170879/CordovaLib/Classes/CDVViewController.m
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVViewController.m b/CordovaLib/Classes/CDVViewController.m
index a3632f5..afdf75c 100644
--- a/CordovaLib/Classes/CDVViewController.m
+++ b/CordovaLib/Classes/CDVViewController.m
@@ -198,11 +198,7 @@
         [CDVLocalStorage __verifyAndFixDatabaseLocations];
     }
 
-    if (IsAtLeastiOSVersion(@"6.0")) {
-        // We don't manually back anything up in 6.0 and so we should remove any old backups.
-        [CDVLocalStorage __restoreThenRemoveBackupLocations];
-        [[NSUserDefaults standardUserDefaults] setBool:backupWebStorage forKey:@"WebKitStoreWebDataForBackup"];
-    }
+    [CDVLocalStorage __fixLegacyDatabaseLocationIssues];
 
     // // Instantiate the WebView ///////////////
 
@@ -229,14 +225,10 @@
     }
 
     /*
-     * Fire up CDVLocalStorage on iOS 5.1 to work-around WebKit storage limitations
+     * Fire up CDVLocalStorage on iOS 5.1+ to work-around WebKit storage limitations
      */
-    if (!IsAtLeastiOSVersion(@"6.0")) {
-        if (backupWebStorage) {
-            [self registerPlugin:[[CDVLocalStorage alloc] initWithWebView:self.webView] withClassName:NSStringFromClass([CDVLocalStorage
class])];
-        } else {
-            [CDVLocalStorage __restoreThenRemoveBackupLocations];
-        }
+    if (IsAtLeastiOSVersion(@"5.1") && backupWebStorage) {
+        [self registerPlugin:[[CDVLocalStorage alloc] initWithWebView:self.webView] withClassName:NSStringFromClass([CDVLocalStorage
class])];
     }
 
     /*


Mime
View raw message