Validate signed FxPlug package layout and deploy isolated beta endpoints with live ACK checks
这个提交包含在:
1 父节点
55acdaa4b1
当前提交
30c8904003
5 个文件已更改
+75
-9
没有与搜索条件相匹配的文件
@@ -3,7 +3,8 @@
|
||||
#import <AppKit/AppKit.h>
|
||||
#import <CommonCrypto/CommonDigest.h>
|
||||
#include <atomic>
|
||||
#include <sys/xattr.h>
|
||||
#include <signal.h>
|
||||
#include <errno.h>
|
||||
|
||||
static NSError *DYUpdateError(NSString *message) { return [NSError errorWithDomain:@"com.dayu.color.update" code:1 userInfo:@{NSLocalizedDescriptionKey:message}]; }
|
||||
static NSURL *updateFolder(void) {
|
||||
@@ -38,8 +39,15 @@ static NSString *command(NSString *path,NSArray *arguments,NSError **error) {
|
||||
if((self=[super init])){_generation.store(0);NSURLSessionConfiguration *config=NSURLSessionConfiguration.ephemeralSessionConfiguration;
|
||||
config.timeoutIntervalForRequest=6;config.timeoutIntervalForResource=300;config.HTTPShouldSetCookies=NO;config.URLCache=nil;
|
||||
_session=[[NSURLSession sessionWithConfiguration:config delegate:self delegateQueue:nil]retain];_state=[@{@"phase":@"idle",@"message":@"启动时自动检查公测更新。"}copy];
|
||||
// Only this updater's abandoned inspection folders are disposable.
|
||||
dispatch_async(dispatch_get_global_queue(QOS_CLASS_UTILITY,0),^{for(NSURL *url in [NSFileManager.defaultManager contentsOfDirectoryAtURL:updateFolder() includingPropertiesForKeys:nil options:0 error:nil])if([url.lastPathComponent hasPrefix:@"inspection-"])[NSFileManager.defaultManager removeItemAtURL:url error:nil];});
|
||||
// Reclaim only abandoned validation folders, never another running updater's work.
|
||||
dispatch_async(dispatch_get_global_queue(QOS_CLASS_UTILITY,0),^{
|
||||
for(NSURL *url in [NSFileManager.defaultManager contentsOfDirectoryAtURL:updateFolder() includingPropertiesForKeys:@[NSURLContentModificationDateKey] options:0 error:nil]){
|
||||
NSArray *parts=[url.lastPathComponent componentsSeparatedByString:@"-"];
|
||||
if(parts.count<3||![parts[0]isEqual:@"inspection"]||[parts[1]rangeOfString:@"^[0-9]+$" options:NSRegularExpressionSearch].location==NSNotFound)continue;
|
||||
int pid=[parts[1]intValue];NSDate *date=nil;[url getResourceValue:&date forKey:NSURLContentModificationDateKey error:nil];
|
||||
if(pid>0&&kill(pid,0)!=0&&errno==ESRCH&&date&&date.timeIntervalSinceNow< -600)[NSFileManager.defaultManager removeItemAtURL:url error:nil];
|
||||
}
|
||||
});
|
||||
}return self;
|
||||
}
|
||||
- (void)dealloc {[_session invalidateAndCancel];[_session release];[_task release];[_package release];[_state release];[_manifest release];[_changed release];[super dealloc];}
|
||||
@@ -72,7 +80,7 @@ static NSString *command(NSString *path,NSArray *arguments,NSError **error) {
|
||||
NSString *signature=command(@"/usr/sbin/pkgutil",@[@"--check-signature",package.path],error);
|
||||
if(!signature||![signature containsString:@"Developer ID Installer:"]||![signature containsString:@"(B3W25FX5H5)"]){if(error)*error=DYUpdateError(@"更新包签名团队不匹配。");return NO;}
|
||||
if(!command(@"/usr/sbin/spctl",@[@"--assess",@"--type",@"install",@"--verbose=2",package.path],error))return NO;
|
||||
NSURL *inspection=[updateFolder() URLByAppendingPathComponent:[@"inspection-" stringByAppendingString:NSUUID.UUID.UUIDString]];
|
||||
NSURL *inspection=[updateFolder() URLByAppendingPathComponent:[NSString stringWithFormat:@"inspection-%d-%@",getpid(),NSUUID.UUID.UUIDString]];
|
||||
@try {
|
||||
if(!command(@"/usr/sbin/pkgutil",@[@"--expand-full",package.path,inspection.path],error))return NO;
|
||||
NSMutableArray *apps=[NSMutableArray array];NSUInteger entries=0;
|
||||
@@ -93,8 +101,12 @@ static NSString *command(NSString *path,NSArray *arguments,NSError **error) {
|
||||
BOOL appTarget=NO,templates=NO;
|
||||
for(NSURL *url in [NSFileManager.defaultManager enumeratorAtURL:inspection includingPropertiesForKeys:nil options:0 errorHandler:nil]){
|
||||
if([url.lastPathComponent isEqual:@"PackageInfo"]){NSString *xml=[NSString stringWithContentsOfURL:url encoding:NSUTF8StringEncoding error:nil];
|
||||
if([xml containsString:@"install-location=\"/Library/Plug-Ins/FxPlug\""])appTarget=YES;
|
||||
if(![xml containsString:@"com.dayu.color.installer"]){if(error)*error=DYUpdateError(@"更新包含不属于本产品的安装组件。");return NO;}
|
||||
NSXMLDocument *document=[[[NSXMLDocument alloc]initWithXMLString:xml options:0 error:nil]autorelease];
|
||||
NSXMLElement *root=document.rootElement;NSString *identifier=[[root attributeForName:@"identifier"]stringValue];
|
||||
NSString *location=[[root attributeForName:@"install-location"]stringValue]?:@"/";
|
||||
NSString *relative=[location isEqual:@"/"]?@"Payload/Library/Plug-Ins/FxPlug/大鱼调色.app":([location isEqual:@"/Library/Plug-Ins/FxPlug"]?@"Payload/大鱼调色.app":nil);
|
||||
if(relative&&[[[[url.URLByDeletingLastPathComponent URLByAppendingPathComponent:relative]path]stringByStandardizingPath]isEqual:app.path.stringByStandardizingPath])appTarget=YES;
|
||||
if(![identifier hasPrefix:@"com.dayu.color.installer."]){if(error)*error=DYUpdateError(@"更新包含不属于本产品的安装组件。");return NO;}
|
||||
}
|
||||
if([url.lastPathComponent isEqual:@"大鱼调色.moef"])templates=YES;
|
||||
}
|
||||
@@ -105,7 +117,7 @@ static NSString *command(NSString *path,NSArray *arguments,NSError **error) {
|
||||
- (void)check {
|
||||
NSString *phase=_state[@"phase"];if([@[@"checking",@"downloading",@"validating"]containsObject:phase])return;
|
||||
unsigned generation=++_generation;[self emit:@"checking" message:@"正在检查公测更新…"];
|
||||
NSString *url=[NSString stringWithFormat:@"https://dayu.media/wp-json/dayu-color/v1/update?bundle_id=com.dayu.color&channel=beta¤t_build=%@",[NSBundle.mainBundle objectForInfoDictionaryKey:@"CFBundleVersion"]];
|
||||
NSString *url=[NSString stringWithFormat:@"https://dayu.media/wp-json/dayu-color/v1/update?bundle_id=com.dayu.color&channel=beta¤t_build=%@",([NSBundle.mainBundle objectForInfoDictionaryKey:@"CFBundleVersion"]?:@"0")];
|
||||
NSMutableURLRequest *request=[NSMutableURLRequest requestWithURL:[NSURL URLWithString:url] cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:6];
|
||||
[_task release];_task=[[_session dataTaskWithRequest:request completionHandler:^(NSData *data,NSURLResponse *response,NSError *error){@autoreleasepool{
|
||||
NSDictionary *value=data.length<=32768?[NSJSONSerialization JSONObjectWithData:data?:[NSData data] options:0 error:nil]:nil;
|
||||
@@ -150,7 +162,7 @@ static NSString *command(NSString *path,NSArray *arguments,NSError **error) {
|
||||
}}]retain];[_task resume];
|
||||
}
|
||||
- (void)install {
|
||||
if(![_state[@"phase"]isEqual:@"ready"]&&![_state[@"phase"]isEqual:@"host_wait"])return;
|
||||
if(![@[@"ready",@"host_wait",@"installer"]containsObject:_state[@"phase"]])return;
|
||||
for(NSString *ID in @[@"com.apple.FinalCut",@"com.apple.FinalCutApp",@"com.apple.motionapp",@"com.apple.motionappApp"])
|
||||
if([NSRunningApplication runningApplicationsWithBundleIdentifier:ID].count){[self emit:@"host_wait" message:@"请先保存并正常退出 FCP / Motion,再点击安装更新。不会强制退出宿主。"];
|
||||
DYBetaEvent(@"update_installer",@{@"status":@"waiting_for_host"});return;}
|
||||
|
||||
在新工单中引用
屏蔽一个用户