| 
									
										
										
										
											2018-08-31 13:16:11 +00:00
										 |  |  | #!/usr/bin/swift | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import Foundation | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | struct swifterr: TextOutputStream { | 
					
						
							|  |  |  |   public static var stream = swifterr() | 
					
						
							|  |  |  |   mutating func write(_ string: String) { fputs(string, stderr) } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-04 21:11:29 +00:00
										 |  |  | if #available(macOS 10.10, *) { | 
					
						
							|  |  |  |   if (CommandLine.arguments.count < 4) { | 
					
						
							|  |  |  |     exit(2) | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2018-08-31 13:16:11 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-04 21:11:29 +00:00
										 |  |  |   let dataLocationUrl: NSURL = NSURL.init(fileURLWithPath: CommandLine.arguments[1]) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   var errorBag: NSError? | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   let quarantineProperties: [String: Any] = [ | 
					
						
							|  |  |  |     kLSQuarantineAgentNameKey as String: "Homebrew Cask", | 
					
						
							|  |  |  |     kLSQuarantineTypeKey as String: kLSQuarantineTypeWebDownload, | 
					
						
							|  |  |  |     kLSQuarantineDataURLKey as String: CommandLine.arguments[2], | 
					
						
							|  |  |  |     kLSQuarantineOriginURLKey as String: CommandLine.arguments[3] | 
					
						
							|  |  |  |   ] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (dataLocationUrl.checkResourceIsReachableAndReturnError(&errorBag)) { | 
					
						
							|  |  |  |     do { | 
					
						
							|  |  |  |       try dataLocationUrl.setResourceValue( | 
					
						
							|  |  |  |         quarantineProperties as NSDictionary, | 
					
						
							|  |  |  |         forKey: URLResourceKey.quarantinePropertiesKey | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     catch { | 
					
						
							|  |  |  |       print(error.localizedDescription, to: &swifterr.stream) | 
					
						
							|  |  |  |       exit(1) | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2018-08-31 13:16:11 +00:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2018-09-04 21:11:29 +00:00
										 |  |  |   else { | 
					
						
							|  |  |  |     print(errorBag!.localizedDescription, to: &swifterr.stream) | 
					
						
							|  |  |  |     exit(3) | 
					
						
							| 
									
										
										
										
											2018-08-31 13:16:11 +00:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2018-09-04 21:11:29 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   exit(0) | 
					
						
							| 
									
										
										
										
											2018-08-31 13:16:11 +00:00
										 |  |  | } | 
					
						
							|  |  |  | else { | 
					
						
							| 
									
										
										
										
											2018-09-04 21:11:29 +00:00
										 |  |  |   exit(5) | 
					
						
							| 
									
										
										
										
											2018-08-31 13:16:11 +00:00
										 |  |  | } |