From b059fd7679ccf64a5e143563abbd4ad795c0c5e5 Mon Sep 17 00:00:00 2001 From: Geoffrey Goh Date: Tue, 8 Dec 2015 18:33:59 -0800 Subject: [PATCH] use appsupport dir --- CodePush.h | 2 +- CodePush.m | 6 +++--- CodePushPackage.m | 18 +++++++++++++++++- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/CodePush.h b/CodePush.h index ec3b880..b69ff7d 100644 --- a/CodePush.h +++ b/CodePush.h @@ -20,7 +20,7 @@ + (NSURL *)bundleURLForResource:(NSString *)resourceName withExtension:(NSString *)resourceExtension; -+ (NSString *)getDocumentsDirectory; ++ (NSString *)getApplicationSupportDirectory; @end diff --git a/CodePush.m b/CodePush.m index 6a6c958..fa05255 100644 --- a/CodePush.m +++ b/CodePush.m @@ -62,10 +62,10 @@ static NSString *const PendingUpdateRollbackTimeoutKey = @"rollbackTimeout"; } } -+ (NSString *)getDocumentsDirectory ++ (NSString *)getApplicationSupportDirectory { - NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]; - return documentsDirectory; + NSString *applicationSupportDirectory = [NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES) objectAtIndex:0]; + return applicationSupportDirectory; } // Private API methods diff --git a/CodePushPackage.m b/CodePushPackage.m index 13b8a26..fba060c 100644 --- a/CodePushPackage.m +++ b/CodePushPackage.m @@ -14,7 +14,7 @@ NSString * const UnzippedFolderName = @"unzipped"; + (NSString *)getCodePushPath { - return [[CodePush getDocumentsDirectory] stringByAppendingPathComponent:@"CodePush"]; + return [[CodePush getApplicationSupportDirectory] stringByAppendingPathComponent:@"CodePush"]; } + (NSString *)getDownloadFilePath @@ -290,6 +290,22 @@ NSString * const UnzippedFolderName = @"unzipped"; } if (relativeBundlePath) { + NSString *absoluteBundlePath = [newPackageFolderPath stringByAppendingPathComponent:relativeBundlePath]; + NSDictionary *bundleFileAttributes = [[[NSFileManager defaultManager] attributesOfItemAtPath:absoluteBundlePath error:&error] mutableCopy]; + if (error) { + failCallback(error); + return; + } + + [bundleFileAttributes setValue:[NSDate date] forKey:NSFileModificationDate]; + [[NSFileManager defaultManager] setAttributes:bundleFileAttributes + ofItemAtPath:absoluteBundlePath + error:&error]; + if (error) { + failCallback(error); + return; + } + [mutableUpdatePackage setValue:relativeBundlePath forKey:RelativeBundlePathKey]; } else { error = [[NSError alloc] initWithDomain:CodePushErrorDomain