Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
8b351a16fe
@ -249,7 +249,7 @@ RCT_EXPORT_METHOD(reloadUpdate:(NSDictionary *)options)
|
||||
}
|
||||
}
|
||||
|
||||
RCT_EXPORT_METHOD(markSuccuss)
|
||||
RCT_EXPORT_METHOD(markSuccess)
|
||||
{
|
||||
// update package info
|
||||
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
|
||||
@ -322,7 +322,7 @@ RCT_EXPORT_METHOD(markSuccuss)
|
||||
{
|
||||
NSString *sourceOrigin = [[NSBundle mainBundle] resourcePath];
|
||||
NSString *bundleOrigin = [[RCTHotUpdate binaryBundleURL] path];
|
||||
[self patch:hashName romBundle:bundleOrigin source:sourceOrigin callback:callback];
|
||||
[self patch:hashName fromBundle:bundleOrigin source:sourceOrigin callback:callback];
|
||||
}
|
||||
break;
|
||||
case HotUpdateTypePatchFromPpk:
|
||||
@ -331,7 +331,7 @@ RCT_EXPORT_METHOD(markSuccuss)
|
||||
|
||||
NSString *sourceOrigin = lastVertionDir;
|
||||
NSString *bundleOrigin = [lastVertionDir stringByAppendingPathComponent:BUNDLE_FILE_NAME];
|
||||
[self patch:hashName romBundle:bundleOrigin source:sourceOrigin callback:callback];
|
||||
[self patch:hashName fromBundle:bundleOrigin source:sourceOrigin callback:callback];
|
||||
}
|
||||
break;
|
||||
default:
|
||||
@ -345,7 +345,7 @@ RCT_EXPORT_METHOD(markSuccuss)
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)patch:(NSString *)hashName romBundle:(NSString *)bundleOrigin source:(NSString *)sourceOrigin callback:(void (^)(NSError *error))callback
|
||||
- (void)patch:(NSString *)hashName fromBundle:(NSString *)bundleOrigin source:(NSString *)sourceOrigin callback:(void (^)(NSError *error))callback
|
||||
{
|
||||
NSString *unzipDir = [[RCTHotUpdate downloadDir] stringByAppendingPathComponent:hashName];
|
||||
NSString *sourcePatch = [unzipDir stringByAppendingPathComponent:SOURCE_PATCH_NAME];
|
||||
@ -361,8 +361,11 @@ RCT_EXPORT_METHOD(markSuccuss)
|
||||
callback(error);
|
||||
return;
|
||||
}
|
||||
|
||||
NSDictionary *copies = json[@"copies"];
|
||||
[_fileManager copyFiles:copies fromDir:sourceOrigin toDir:unzipDir completionHandler:^(NSError *error) {
|
||||
NSDictionary *deletes = json[@"deletes"];
|
||||
|
||||
[_fileManager copyFiles:copies fromDir:sourceOrigin toDir:unzipDir deletes:deletes completionHandler:^(NSError *error) {
|
||||
if (error) {
|
||||
callback(error);
|
||||
}
|
||||
@ -392,7 +395,7 @@ RCT_EXPORT_METHOD(markSuccuss)
|
||||
|
||||
for(NSString *fileName in list) {
|
||||
if (![fileName isEqualToString:curVersion]) {
|
||||
[_fileManager removeFile:curVersion completionHandler:nil];
|
||||
[_fileManager removeFile:[downloadDir stringByAppendingPathComponent:fileName] completionHandler:nil];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -26,6 +26,7 @@
|
||||
- (void)copyFiles:(NSDictionary *)filesDic
|
||||
fromDir:(NSString *)fromDir
|
||||
toDir:(NSString *)toDir
|
||||
deletes:(NSDictionary *)deletes
|
||||
completionHandler:(void (^)(NSError *error))completionHandler;
|
||||
|
||||
- (void)removeFile:(NSString *)filePath
|
||||
|
@ -91,9 +91,27 @@
|
||||
- (void)copyFiles:(NSDictionary *)filesDic
|
||||
fromDir:(NSString *)fromDir
|
||||
toDir:(NSString *)toDir
|
||||
deletes:(NSDictionary *)deletes
|
||||
completionHandler:(void (^)(NSError *error))completionHandler
|
||||
{
|
||||
dispatch_async(_opQueue, ^{
|
||||
NSFileManager *fm = [NSFileManager defaultManager];
|
||||
|
||||
// merge old files
|
||||
if (deletes!= nil) {
|
||||
NSError *error = nil;
|
||||
NSString *srcDir = [fromDir stringByAppendingPathComponent:@"assets"];
|
||||
NSString *desDir = [toDir stringByAppendingPathComponent:@"assets"];
|
||||
[self _mergeContentsOfPath:srcDir intoPath:desDir deletes:deletes error:&error];
|
||||
if (error) {
|
||||
if (completionHandler) {
|
||||
completionHandler(error);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// copy files
|
||||
for (NSString *to in filesDic.allKeys) {
|
||||
NSString *from = filesDic[to];
|
||||
if (from.length <=0) {
|
||||
@ -102,8 +120,11 @@ completionHandler:(void (^)(NSError *error))completionHandler
|
||||
NSString *fromPath = [fromDir stringByAppendingPathComponent:from];
|
||||
NSString *toPath = [toDir stringByAppendingPathComponent:to];
|
||||
|
||||
if ([fm fileExistsAtPath:toPath]) {
|
||||
[fm removeItemAtPath:toPath error:nil];
|
||||
}
|
||||
NSError *error = nil;
|
||||
[[NSFileManager defaultManager] copyItemAtPath:fromPath toPath:toPath error:&error];
|
||||
[fm copyItemAtPath:fromPath toPath:toPath error:&error];
|
||||
if (error) {
|
||||
if (completionHandler) {
|
||||
completionHandler(error);
|
||||
@ -129,4 +150,44 @@ completionHandler:(void (^)(NSError *error))completionHandler
|
||||
});
|
||||
}
|
||||
|
||||
- (void)_mergeContentsOfPath:(NSString *)srcDir intoPath:(NSString *)dstDir deletes:(NSDictionary *)deletes error:(NSError**)err
|
||||
{
|
||||
NSFileManager *fm = [NSFileManager defaultManager];
|
||||
NSDirectoryEnumerator *srcDirEnum = [fm enumeratorAtPath:srcDir];
|
||||
NSString *subPath;
|
||||
while ((subPath = [srcDirEnum nextObject])) {
|
||||
|
||||
NSString *srcFullPath = [srcDir stringByAppendingPathComponent:subPath];
|
||||
NSString *potentialDstPath = [dstDir stringByAppendingPathComponent:subPath];
|
||||
|
||||
BOOL isDirectory = ([fm fileExistsAtPath:srcFullPath isDirectory:&isDirectory] && isDirectory);
|
||||
if (isDirectory) {
|
||||
if (![fm fileExistsAtPath:potentialDstPath isDirectory:nil]) {
|
||||
[fm createDirectoryAtPath:potentialDstPath withIntermediateDirectories:YES attributes:nil error:err];
|
||||
if (err && *err) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
BOOL inDeletes = NO;
|
||||
if (deletes) {
|
||||
NSString *path = [@"assets" stringByAppendingPathComponent:subPath];
|
||||
for (NSString *del in deletes) {
|
||||
if ([subPath isEqualToString:path]) {
|
||||
inDeletes = YES;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!inDeletes && ![fm fileExistsAtPath:potentialDstPath]) {
|
||||
[fm copyItemAtPath:srcFullPath toPath:potentialDstPath error:err];
|
||||
if (err && *err) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
|
Loading…
Reference in New Issue
Block a user