mirror of
https://github.com/sparkle-project/Sparkle
synced 2026-11-27 05:04:27 +00:00
Run SwifLint autocorrect
This commit is contained in:
1 parent
5df208336a
commit
bb56b5b259
11 files changed
+372
-373
No files matched your search
+43
-43
@@ -7,82 +7,82 @@
|
||||
//
|
||||
|
||||
import XCTest
|
||||
import Sparkle;
|
||||
import Sparkle
|
||||
|
||||
class SUAppcastTest: XCTestCase {
|
||||
|
||||
func testParseAppcast() {
|
||||
let appcast = SUAppcast();
|
||||
let testFile = Bundle(for: SUAppcastTest.self).path(forResource: "testappcast", ofType: "xml")!;
|
||||
let appcast = SUAppcast()
|
||||
let testFile = Bundle(for: SUAppcastTest.self).path(forResource: "testappcast", ofType: "xml")!
|
||||
let testData = NSData(contentsOfFile: testFile)!
|
||||
|
||||
|
||||
do {
|
||||
let items = try appcast.parseAppcastItems(fromXMLData: testData as Data) as! [SUAppcastItem];
|
||||
|
||||
XCTAssertEqual(4, items.count);
|
||||
|
||||
XCTAssertEqual("Version 2.0", items[0].title);
|
||||
XCTAssertEqual("desc", items[0].itemDescription);
|
||||
let items = try appcast.parseAppcastItems(fromXMLData: testData as Data) as! [SUAppcastItem]
|
||||
|
||||
XCTAssertEqual(4, items.count)
|
||||
|
||||
XCTAssertEqual("Version 2.0", items[0].title)
|
||||
XCTAssertEqual("desc", items[0].itemDescription)
|
||||
XCTAssertEqual("Sat, 26 Jul 2014 15:20:11 +0000", items[0].dateString)
|
||||
XCTAssertTrue(items[0].isCriticalUpdate);
|
||||
|
||||
XCTAssertTrue(items[0].isCriticalUpdate)
|
||||
|
||||
// This is the best release matching our system version
|
||||
XCTAssertEqual("Version 3.0", items[1].title);
|
||||
XCTAssertNil(items[1].itemDescription);
|
||||
XCTAssertEqual("Version 3.0", items[1].title)
|
||||
XCTAssertNil(items[1].itemDescription)
|
||||
XCTAssertNil(items[1].dateString)
|
||||
XCTAssertFalse(items[1].isCriticalUpdate);
|
||||
|
||||
XCTAssertEqual("Version 4.0", items[2].title);
|
||||
XCTAssertNil(items[2].itemDescription);
|
||||
XCTAssertFalse(items[1].isCriticalUpdate)
|
||||
|
||||
XCTAssertEqual("Version 4.0", items[2].title)
|
||||
XCTAssertNil(items[2].itemDescription)
|
||||
XCTAssertEqual("Sat, 26 Jul 2014 15:20:13 +0000", items[2].dateString)
|
||||
XCTAssertFalse(items[2].isCriticalUpdate);
|
||||
|
||||
XCTAssertEqual("Version 5.0", items[3].title);
|
||||
XCTAssertNil(items[3].itemDescription);
|
||||
XCTAssertFalse(items[2].isCriticalUpdate)
|
||||
|
||||
XCTAssertEqual("Version 5.0", items[3].title)
|
||||
XCTAssertNil(items[3].itemDescription)
|
||||
XCTAssertNil(items[3].dateString)
|
||||
XCTAssertFalse(items[3].isCriticalUpdate);
|
||||
|
||||
XCTAssertFalse(items[3].isCriticalUpdate)
|
||||
|
||||
// Test best appcast item & a delta update item
|
||||
var deltaItem: SUAppcastItem? = nil
|
||||
var deltaItem: SUAppcastItem?
|
||||
let bestAppcastItem = SUAppcastDriver.bestItem(fromAppcastItems: items, getDeltaItem: &deltaItem, withHostVersion: "1.0", comparator: SUStandardVersionComparator())
|
||||
|
||||
XCTAssertEqual(bestAppcastItem, items[1])
|
||||
XCTAssertEqual(deltaItem!.fileURL.lastPathComponent, "3.0_from_1.0.patch")
|
||||
|
||||
|
||||
// Test latest delta update item available
|
||||
var latestDeltaItem: SUAppcastItem? = nil
|
||||
var latestDeltaItem: SUAppcastItem?
|
||||
SUAppcastDriver.bestItem(fromAppcastItems: items, getDeltaItem: &latestDeltaItem, withHostVersion: "2.0", comparator: SUStandardVersionComparator())
|
||||
|
||||
|
||||
XCTAssertEqual(latestDeltaItem!.fileURL.lastPathComponent, "3.0_from_2.0.patch")
|
||||
|
||||
|
||||
// Test a delta item that does not exist
|
||||
var nonexistantDeltaItem: SUAppcastItem? = nil
|
||||
var nonexistantDeltaItem: SUAppcastItem?
|
||||
SUAppcastDriver.bestItem(fromAppcastItems: items, getDeltaItem: &nonexistantDeltaItem, withHostVersion: "2.1", comparator: SUStandardVersionComparator())
|
||||
|
||||
|
||||
XCTAssertNil(nonexistantDeltaItem)
|
||||
} catch let err as NSError {
|
||||
NSLog("%@", err);
|
||||
XCTFail(err.localizedDescription);
|
||||
NSLog("%@", err)
|
||||
XCTFail(err.localizedDescription)
|
||||
}
|
||||
}
|
||||
|
||||
func testNamespaces() {
|
||||
let appcast = SUAppcast();
|
||||
let testFile = Bundle(for: SUAppcastTest.self).path(forResource: "testnamespaces", ofType: "xml")!;
|
||||
let appcast = SUAppcast()
|
||||
let testFile = Bundle(for: SUAppcastTest.self).path(forResource: "testnamespaces", ofType: "xml")!
|
||||
let testData = NSData(contentsOfFile: testFile)!
|
||||
|
||||
do {
|
||||
let items = try appcast.parseAppcastItems(fromXMLData: testData as Data) as! [SUAppcastItem];
|
||||
let items = try appcast.parseAppcastItems(fromXMLData: testData as Data) as! [SUAppcastItem]
|
||||
|
||||
XCTAssertEqual(2, items.count);
|
||||
XCTAssertEqual(2, items.count)
|
||||
|
||||
XCTAssertEqual("Version 2.0", items[1].title);
|
||||
XCTAssertEqual("desc", items[1].itemDescription);
|
||||
XCTAssertNotNil(items[0].releaseNotesURL);
|
||||
XCTAssertEqual("https://sparkle-project.org/#works", items[0].releaseNotesURL!.absoluteString);
|
||||
XCTAssertEqual("Version 2.0", items[1].title)
|
||||
XCTAssertEqual("desc", items[1].itemDescription)
|
||||
XCTAssertNotNil(items[0].releaseNotesURL)
|
||||
XCTAssertEqual("https://sparkle-project.org/#works", items[0].releaseNotesURL!.absoluteString)
|
||||
} catch let err as NSError {
|
||||
NSLog("%@", err);
|
||||
XCTFail(err.localizedDescription);
|
||||
NSLog("%@", err)
|
||||
XCTFail(err.localizedDescription)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -13,54 +13,54 @@ class SUFileManagerTest: XCTestCase
|
||||
func makeTempFiles(_ testBlock: (SUFileManager, URL, URL, URL, URL, URL, URL) -> Void)
|
||||
{
|
||||
let fileManager = SUFileManager()
|
||||
|
||||
|
||||
let tempDirectoryURL = try! fileManager.makeTemporaryDirectory(withPreferredName: "Sparkle Unit Test Data", appropriateForDirectoryURL: URL(fileURLWithPath: NSHomeDirectory()))
|
||||
|
||||
|
||||
defer {
|
||||
try! fileManager.removeItem(at: tempDirectoryURL)
|
||||
}
|
||||
|
||||
|
||||
let ordinaryFileURL = tempDirectoryURL.appendingPathComponent("a file written by sparkles unit tests")
|
||||
try! "foo".data(using: String.Encoding.utf8)!.write(to: ordinaryFileURL, options: .atomic)
|
||||
|
||||
|
||||
let directoryURL = tempDirectoryURL.appendingPathComponent("a directory written by sparkles unit tests")
|
||||
try! FileManager.default.createDirectory(at: directoryURL, withIntermediateDirectories: false, attributes: nil)
|
||||
|
||||
|
||||
let fileInDirectoryURL = directoryURL.appendingPathComponent("a file inside a directory written by sparkles unit tests")
|
||||
try! "bar baz".data(using: String.Encoding.utf8)!.write(to: fileInDirectoryURL, options: .atomic)
|
||||
|
||||
|
||||
let validSymlinkURL = tempDirectoryURL.appendingPathComponent("symlink test")
|
||||
try! FileManager.default.createSymbolicLink(at: validSymlinkURL, withDestinationURL: directoryURL)
|
||||
|
||||
|
||||
let invalidSymlinkURL = tempDirectoryURL.appendingPathComponent("symlink test 2")
|
||||
try! FileManager.default.createSymbolicLink(at: invalidSymlinkURL, withDestinationURL: (tempDirectoryURL.appendingPathComponent("does not exist")))
|
||||
|
||||
|
||||
testBlock(fileManager, tempDirectoryURL, ordinaryFileURL, directoryURL, fileInDirectoryURL, validSymlinkURL, invalidSymlinkURL)
|
||||
}
|
||||
|
||||
|
||||
func testMoveFiles()
|
||||
{
|
||||
makeTempFiles() { fileManager, rootURL, ordinaryFileURL, directoryURL, fileInDirectoryURL, validSymlinkURL, invalidSymlinkURL in
|
||||
XCTAssertNil(try? fileManager.moveItem(at: ordinaryFileURL, to: directoryURL))
|
||||
XCTAssertNil(try? fileManager.moveItem(at: ordinaryFileURL, to: directoryURL.appendingPathComponent("foo").appendingPathComponent("bar")))
|
||||
XCTAssertNil(try? fileManager.moveItem(at: rootURL.appendingPathComponent("does not exist"), to: directoryURL))
|
||||
|
||||
|
||||
let newFileURL = (ordinaryFileURL.deletingLastPathComponent().appendingPathComponent("new file"))
|
||||
try! fileManager.moveItem(at: ordinaryFileURL, to: newFileURL)
|
||||
XCTAssertFalse(fileManager._itemExists(at: ordinaryFileURL))
|
||||
XCTAssertTrue(fileManager._itemExists(at: newFileURL))
|
||||
|
||||
|
||||
let newValidSymlinkURL = (ordinaryFileURL.deletingLastPathComponent().appendingPathComponent("new symlink"))
|
||||
try! fileManager.moveItem(at: validSymlinkURL, to: newValidSymlinkURL)
|
||||
XCTAssertFalse(fileManager._itemExists(at: validSymlinkURL))
|
||||
XCTAssertTrue(fileManager._itemExists(at: newValidSymlinkURL))
|
||||
XCTAssertTrue(fileManager._itemExists(at: directoryURL))
|
||||
|
||||
|
||||
let newInvalidSymlinkURL = (ordinaryFileURL.deletingLastPathComponent().appendingPathComponent("new invalid symlink"))
|
||||
try! fileManager.moveItem(at: invalidSymlinkURL, to: newInvalidSymlinkURL)
|
||||
XCTAssertFalse(fileManager._itemExists(at: invalidSymlinkURL))
|
||||
XCTAssertTrue(fileManager._itemExists(at: newValidSymlinkURL))
|
||||
|
||||
|
||||
let newDirectoryURL = (ordinaryFileURL.deletingLastPathComponent().appendingPathComponent("new directory"))
|
||||
try! fileManager.moveItem(at: directoryURL, to: newDirectoryURL)
|
||||
XCTAssertFalse(fileManager._itemExists(at: directoryURL))
|
||||
@@ -69,23 +69,23 @@ class SUFileManagerTest: XCTestCase
|
||||
XCTAssertTrue(fileManager._itemExists(at: newDirectoryURL.appendingPathComponent(fileInDirectoryURL.lastPathComponent)))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func testCopyFiles()
|
||||
{
|
||||
makeTempFiles() { fileManager, rootURL, ordinaryFileURL, directoryURL, fileInDirectoryURL, validSymlinkURL, invalidSymlinkURL in
|
||||
makeTempFiles() { fileManager, rootURL, ordinaryFileURL, directoryURL, fileInDirectoryURL, _, invalidSymlinkURL in
|
||||
XCTAssertNil(try? fileManager.copyItem(at: ordinaryFileURL, to: directoryURL))
|
||||
XCTAssertNil(try? fileManager.copyItem(at: ordinaryFileURL, to: directoryURL.appendingPathComponent("foo").appendingPathComponent("bar")))
|
||||
XCTAssertNil(try? fileManager.copyItem(at: rootURL.appendingPathComponent("does not exist"), to: directoryURL))
|
||||
|
||||
|
||||
let newFileURL = (ordinaryFileURL.deletingLastPathComponent().appendingPathComponent("new file"))
|
||||
try! fileManager.copyItem(at: ordinaryFileURL, to: newFileURL)
|
||||
XCTAssertTrue(fileManager._itemExists(at: ordinaryFileURL))
|
||||
XCTAssertTrue(fileManager._itemExists(at: newFileURL))
|
||||
|
||||
|
||||
let newSymlinkURL = (ordinaryFileURL.deletingLastPathComponent().appendingPathComponent("new symlink file"))
|
||||
try! fileManager.copyItem(at: invalidSymlinkURL, to: newSymlinkURL)
|
||||
XCTAssertTrue(fileManager._itemExists(at: newSymlinkURL))
|
||||
|
||||
|
||||
let newDirectoryURL = (ordinaryFileURL.deletingLastPathComponent().appendingPathComponent("new directory"))
|
||||
try! fileManager.copyItem(at: directoryURL, to: newDirectoryURL)
|
||||
XCTAssertTrue(fileManager._itemExists(at: directoryURL))
|
||||
@@ -97,80 +97,80 @@ class SUFileManagerTest: XCTestCase
|
||||
|
||||
func testRemoveFiles()
|
||||
{
|
||||
makeTempFiles() { fileManager, rootURL, ordinaryFileURL, directoryURL, fileInDirectoryURL, validSymlinkURL, invalidSymlinkURL in
|
||||
makeTempFiles() { fileManager, rootURL, ordinaryFileURL, directoryURL, fileInDirectoryURL, validSymlinkURL, _ in
|
||||
XCTAssertNil(try? fileManager.removeItem(at: rootURL.appendingPathComponent("does not exist")))
|
||||
|
||||
|
||||
try! fileManager.removeItem(at: ordinaryFileURL)
|
||||
XCTAssertFalse(fileManager._itemExists(at: ordinaryFileURL))
|
||||
|
||||
|
||||
try! fileManager.removeItem(at: validSymlinkURL)
|
||||
XCTAssertFalse(fileManager._itemExists(at: validSymlinkURL))
|
||||
XCTAssertTrue(fileManager._itemExists(at: directoryURL))
|
||||
|
||||
|
||||
try! fileManager.removeItem(at: directoryURL)
|
||||
XCTAssertFalse(fileManager._itemExists(at: directoryURL))
|
||||
XCTAssertFalse(fileManager._itemExists(at: fileInDirectoryURL))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func testReleaseFilesFromQuarantine()
|
||||
{
|
||||
makeTempFiles() { fileManager, rootURL, ordinaryFileURL, directoryURL, fileInDirectoryURL, validSymlinkURL, invalidSymlinkURL in
|
||||
makeTempFiles() { fileManager, _, ordinaryFileURL, directoryURL, fileInDirectoryURL, validSymlinkURL, _ in
|
||||
try! fileManager.releaseItemFromQuarantine(atRootURL: ordinaryFileURL)
|
||||
try! fileManager.releaseItemFromQuarantine(atRootURL: directoryURL)
|
||||
try! fileManager.releaseItemFromQuarantine(atRootURL: validSymlinkURL)
|
||||
|
||||
|
||||
let quarantineData = "does not really matter what is here".cString(using: String.Encoding.utf8)!
|
||||
let quarantineDataLength = Int(strlen(quarantineData))
|
||||
|
||||
|
||||
XCTAssertEqual(0, setxattr(ordinaryFileURL.path, SUAppleQuarantineIdentifier, quarantineData, quarantineDataLength, 0, XATTR_CREATE))
|
||||
XCTAssertGreaterThan(getxattr(ordinaryFileURL.path, SUAppleQuarantineIdentifier, nil, 0, 0, XATTR_NOFOLLOW), 0)
|
||||
|
||||
|
||||
try! fileManager.releaseItemFromQuarantine(atRootURL: ordinaryFileURL)
|
||||
XCTAssertEqual(-1, getxattr(ordinaryFileURL.path, SUAppleQuarantineIdentifier, nil, 0, 0, XATTR_NOFOLLOW))
|
||||
|
||||
|
||||
XCTAssertEqual(0, setxattr(directoryURL.path, SUAppleQuarantineIdentifier, quarantineData, quarantineDataLength, 0, XATTR_CREATE))
|
||||
XCTAssertGreaterThan(getxattr(directoryURL.path, SUAppleQuarantineIdentifier, nil, 0, 0, XATTR_NOFOLLOW), 0)
|
||||
|
||||
|
||||
XCTAssertEqual(0, setxattr(fileInDirectoryURL.path, SUAppleQuarantineIdentifier, quarantineData, quarantineDataLength, 0, XATTR_CREATE))
|
||||
XCTAssertGreaterThan(getxattr(fileInDirectoryURL.path, SUAppleQuarantineIdentifier, nil, 0, 0, XATTR_NOFOLLOW), 0)
|
||||
|
||||
|
||||
// Extended attributes can't be set on symbolic links currently
|
||||
try! fileManager.releaseItemFromQuarantine(atRootURL: validSymlinkURL)
|
||||
XCTAssertGreaterThan(getxattr(directoryURL.path, SUAppleQuarantineIdentifier, nil, 0, 0, XATTR_NOFOLLOW), 0)
|
||||
XCTAssertEqual(-1, getxattr(validSymlinkURL.path, SUAppleQuarantineIdentifier, nil, 0, 0, XATTR_NOFOLLOW))
|
||||
|
||||
|
||||
try! fileManager.releaseItemFromQuarantine(atRootURL: directoryURL)
|
||||
|
||||
|
||||
XCTAssertEqual(-1, getxattr(directoryURL.path, SUAppleQuarantineIdentifier, nil, 0, 0, XATTR_NOFOLLOW))
|
||||
XCTAssertEqual(-1, getxattr(fileInDirectoryURL.path, SUAppleQuarantineIdentifier, nil, 0, 0, XATTR_NOFOLLOW))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func groupIDAtPath(_ path: String) -> gid_t
|
||||
{
|
||||
let attributes = try! FileManager.default.attributesOfItem(atPath: path)
|
||||
let groupID = attributes[FileAttributeKey.groupOwnerAccountID] as! NSNumber
|
||||
return groupID.uint32Value
|
||||
}
|
||||
|
||||
|
||||
// Only the super user can alter user IDs, so changing user IDs is not tested here
|
||||
// Instead we try to change the group ID - we just have to be a member of that group
|
||||
func testAlterFilesGroupID()
|
||||
{
|
||||
makeTempFiles() { fileManager, rootURL, ordinaryFileURL, directoryURL, fileInDirectoryURL, validSymlinkURL, invalidSymlinkURL in
|
||||
makeTempFiles() { fileManager, rootURL, ordinaryFileURL, directoryURL, fileInDirectoryURL, validSymlinkURL, _ in
|
||||
XCTAssertNil(try? fileManager.changeOwnerAndGroupOfItem(atRootURL: ordinaryFileURL, toMatch: rootURL.appendingPathComponent("does not exist")))
|
||||
|
||||
|
||||
XCTAssertNil(try? fileManager.changeOwnerAndGroupOfItem(atRootURL: rootURL.appendingPathComponent("does not exist"), toMatch: ordinaryFileURL))
|
||||
|
||||
|
||||
let everyoneGroup = getgrnam("everyone")
|
||||
let everyoneGroupID = everyoneGroup?.pointee.gr_gid
|
||||
|
||||
|
||||
let staffGroup = getgrnam("staff")
|
||||
let staffGroupID = staffGroup?.pointee.gr_gid
|
||||
|
||||
|
||||
XCTAssertNotEqual(staffGroupID, everyoneGroupID)
|
||||
|
||||
|
||||
XCTAssertEqual(staffGroupID, self.groupIDAtPath(ordinaryFileURL.path))
|
||||
XCTAssertEqual(staffGroupID, self.groupIDAtPath(directoryURL.path))
|
||||
XCTAssertEqual(staffGroupID, self.groupIDAtPath(fileInDirectoryURL.path))
|
||||
@@ -179,55 +179,55 @@ class SUFileManagerTest: XCTestCase
|
||||
try! fileManager.changeOwnerAndGroupOfItem(atRootURL: fileInDirectoryURL, toMatch: ordinaryFileURL)
|
||||
try! fileManager.changeOwnerAndGroupOfItem(atRootURL: ordinaryFileURL, toMatch: ordinaryFileURL)
|
||||
try! fileManager.changeOwnerAndGroupOfItem(atRootURL: validSymlinkURL, toMatch: ordinaryFileURL)
|
||||
|
||||
|
||||
XCTAssertEqual(staffGroupID, self.groupIDAtPath(ordinaryFileURL.path))
|
||||
XCTAssertEqual(staffGroupID, self.groupIDAtPath(directoryURL.path))
|
||||
XCTAssertEqual(staffGroupID, self.groupIDAtPath(validSymlinkURL.path))
|
||||
|
||||
|
||||
XCTAssertEqual(0, chown(ordinaryFileURL.path, getuid(), everyoneGroupID!))
|
||||
XCTAssertEqual(everyoneGroupID, self.groupIDAtPath(ordinaryFileURL.path))
|
||||
|
||||
|
||||
try! fileManager.changeOwnerAndGroupOfItem(atRootURL: fileInDirectoryURL, toMatch: ordinaryFileURL)
|
||||
XCTAssertEqual(everyoneGroupID, self.groupIDAtPath(fileInDirectoryURL.path))
|
||||
|
||||
|
||||
try! fileManager.changeOwnerAndGroupOfItem(atRootURL: fileInDirectoryURL, toMatch: directoryURL)
|
||||
XCTAssertEqual(staffGroupID, self.groupIDAtPath(fileInDirectoryURL.path))
|
||||
|
||||
|
||||
try! fileManager.changeOwnerAndGroupOfItem(atRootURL: validSymlinkURL, toMatch: ordinaryFileURL)
|
||||
XCTAssertEqual(everyoneGroupID, self.groupIDAtPath(validSymlinkURL.path))
|
||||
|
||||
|
||||
try! fileManager.changeOwnerAndGroupOfItem(atRootURL: directoryURL, toMatch: ordinaryFileURL)
|
||||
XCTAssertEqual(everyoneGroupID, self.groupIDAtPath(directoryURL.path))
|
||||
XCTAssertEqual(everyoneGroupID, self.groupIDAtPath(fileInDirectoryURL.path))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func testUpdateFileModificationTime()
|
||||
{
|
||||
makeTempFiles() { fileManager, rootURL, ordinaryFileURL, directoryURL, fileInDirectoryURL, validSymlinkURL, invalidSymlinkURL in
|
||||
makeTempFiles() { fileManager, rootURL, ordinaryFileURL, directoryURL, _, validSymlinkURL, _ in
|
||||
XCTAssertNil(try? fileManager.updateModificationAndAccessTimeOfItem(at: rootURL.appendingPathComponent("does not exist")))
|
||||
|
||||
|
||||
let oldOrdinaryFileAttributes = try! FileManager.default.attributesOfItem(atPath: ordinaryFileURL.path)
|
||||
let oldDirectoryAttributes = try! FileManager.default.attributesOfItem(atPath: directoryURL.path)
|
||||
let oldValidSymlinkAttributes = try! FileManager.default.attributesOfItem(atPath: validSymlinkURL.path)
|
||||
|
||||
|
||||
sleep(1); // wait for clock to advance
|
||||
|
||||
|
||||
try! fileManager.updateModificationAndAccessTimeOfItem(at: ordinaryFileURL)
|
||||
try! fileManager.updateModificationAndAccessTimeOfItem(at: directoryURL)
|
||||
try! fileManager.updateModificationAndAccessTimeOfItem(at: validSymlinkURL)
|
||||
|
||||
|
||||
let newOrdinaryFileAttributes = try! FileManager.default.attributesOfItem(atPath: ordinaryFileURL.path)
|
||||
XCTAssertGreaterThan((newOrdinaryFileAttributes[FileAttributeKey.modificationDate] as! Date).timeIntervalSince(oldOrdinaryFileAttributes[FileAttributeKey.modificationDate] as! Date), 0)
|
||||
|
||||
|
||||
let newDirectoryAttributes = try! FileManager.default.attributesOfItem(atPath: directoryURL.path)
|
||||
XCTAssertGreaterThan((newDirectoryAttributes[FileAttributeKey.modificationDate] as! Date).timeIntervalSince(oldDirectoryAttributes[FileAttributeKey.modificationDate] as! Date), 0)
|
||||
|
||||
|
||||
let newSymlinkAttributes = try! FileManager.default.attributesOfItem(atPath: validSymlinkURL.path)
|
||||
XCTAssertGreaterThan((newSymlinkAttributes[FileAttributeKey.modificationDate] as! Date).timeIntervalSince(oldValidSymlinkAttributes[FileAttributeKey.modificationDate] as! Date), 0)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func testUpdateFileAccessTime()
|
||||
{
|
||||
let accessTime: ((URL) -> timespec?) = { url in
|
||||
@@ -239,34 +239,34 @@ class SUFileManagerTest: XCTestCase
|
||||
return outputStat.st_atimespec
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
let timespecEqual: (timespec, timespec) -> Bool = {t1, t2 in
|
||||
(t1.tv_sec == t2.tv_sec && t1.tv_nsec == t2.tv_nsec)
|
||||
}
|
||||
|
||||
makeTempFiles() { fileManager, rootURL, ordinaryFileURL, directoryURL, fileInDirectoryURL, validSymlinkURL, invalidSymlinkURL in
|
||||
|
||||
makeTempFiles() { fileManager, rootURL, ordinaryFileURL, directoryURL, fileInDirectoryURL, validSymlinkURL, _ in
|
||||
XCTAssertNil(try? fileManager.updateAccessTimeOfItem(atRootURL: rootURL.appendingPathComponent("does not exist")))
|
||||
|
||||
|
||||
let oldOrdinaryFileTime = accessTime(ordinaryFileURL)!
|
||||
let oldDirectoryTime = accessTime(directoryURL)!
|
||||
let oldValidSymlinkTime = accessTime(validSymlinkURL)!
|
||||
|
||||
|
||||
sleep(1); // wait for clock to advance
|
||||
|
||||
|
||||
// Make sure access time haven't changed since; lstat() shouldn't have changed the access time..
|
||||
XCTAssertTrue(timespecEqual(oldOrdinaryFileTime, accessTime(ordinaryFileURL)!))
|
||||
XCTAssertTrue(timespecEqual(oldDirectoryTime, accessTime(directoryURL)!))
|
||||
XCTAssertTrue(timespecEqual(oldValidSymlinkTime, accessTime(validSymlinkURL)!))
|
||||
|
||||
|
||||
// Test the symlink and make sure the target directory doesn't change
|
||||
try! fileManager.updateAccessTimeOfItem(atRootURL: validSymlinkURL)
|
||||
XCTAssertFalse(timespecEqual(oldValidSymlinkTime, accessTime(validSymlinkURL)!))
|
||||
XCTAssertTrue(timespecEqual(oldDirectoryTime, accessTime(directoryURL)!))
|
||||
|
||||
|
||||
// Test an ordinary file
|
||||
try! fileManager.updateAccessTimeOfItem(atRootURL: ordinaryFileURL)
|
||||
XCTAssertFalse(timespecEqual(oldOrdinaryFileTime, accessTime(ordinaryFileURL)!))
|
||||
|
||||
|
||||
// Test the directory and file inside the directory
|
||||
try! fileManager.updateAccessTimeOfItem(atRootURL: directoryURL)
|
||||
let newDirectoryTime = accessTime(directoryURL)!
|
||||
@@ -274,50 +274,50 @@ class SUFileManagerTest: XCTestCase
|
||||
XCTAssertTrue(timespecEqual(newDirectoryTime, accessTime(fileInDirectoryURL)!))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func testFileExists()
|
||||
{
|
||||
makeTempFiles() { fileManager, rootURL, ordinaryFileURL, directoryURL, fileInDirectoryURL, validSymlinkURL, invalidSymlinkURL in
|
||||
makeTempFiles() { fileManager, rootURL, ordinaryFileURL, directoryURL, _, validSymlinkURL, invalidSymlinkURL in
|
||||
XCTAssertTrue(fileManager._itemExists(at: ordinaryFileURL))
|
||||
XCTAssertTrue(fileManager._itemExists(at: directoryURL))
|
||||
XCTAssertFalse(fileManager._itemExists(at: rootURL.appendingPathComponent("does not exist")))
|
||||
|
||||
|
||||
var isOrdinaryFileDirectory: ObjCBool = false
|
||||
XCTAssertTrue(fileManager._itemExists(at: ordinaryFileURL, isDirectory: &isOrdinaryFileDirectory) && !isOrdinaryFileDirectory.boolValue)
|
||||
|
||||
|
||||
var isDirectoryADirectory: ObjCBool = false
|
||||
XCTAssertTrue(fileManager._itemExists(at: directoryURL, isDirectory: &isDirectoryADirectory) && isDirectoryADirectory.boolValue)
|
||||
|
||||
|
||||
XCTAssertFalse(fileManager._itemExists(at: rootURL.appendingPathComponent("does not exist"), isDirectory: nil))
|
||||
|
||||
|
||||
XCTAssertTrue(fileManager._itemExists(at: validSymlinkURL))
|
||||
|
||||
|
||||
var validSymlinkIsADirectory: ObjCBool = false
|
||||
XCTAssertTrue(fileManager._itemExists(at: validSymlinkURL, isDirectory: &validSymlinkIsADirectory) && !validSymlinkIsADirectory.boolValue)
|
||||
|
||||
|
||||
// Symlink should still exist even if it doesn't point to a file that exists
|
||||
XCTAssertTrue(fileManager._itemExists(at: invalidSymlinkURL))
|
||||
|
||||
|
||||
var invalidSymlinkIsADirectory: ObjCBool = false
|
||||
XCTAssertTrue(fileManager._itemExists(at: invalidSymlinkURL, isDirectory: &invalidSymlinkIsADirectory) && !invalidSymlinkIsADirectory.boolValue)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func testMakeDirectory()
|
||||
{
|
||||
makeTempFiles() { fileManager, rootURL, ordinaryFileURL, directoryURL, fileInDirectoryURL, validSymlinkURL, invalidSymlinkURL in
|
||||
makeTempFiles() { fileManager, rootURL, ordinaryFileURL, directoryURL, _, validSymlinkURL, _ in
|
||||
XCTAssertNil(try? fileManager.makeDirectory(at: ordinaryFileURL))
|
||||
XCTAssertNil(try? fileManager.makeDirectory(at: directoryURL))
|
||||
|
||||
|
||||
XCTAssertNil(try? fileManager.makeDirectory(at: rootURL.appendingPathComponent("this should").appendingPathComponent("be a failure")))
|
||||
|
||||
|
||||
let newDirectoryURL = rootURL.appendingPathComponent("new test directory")
|
||||
XCTAssertFalse(fileManager._itemExists(at: newDirectoryURL))
|
||||
try! fileManager.makeDirectory(at: newDirectoryURL)
|
||||
|
||||
|
||||
var isDirectory: ObjCBool = false
|
||||
XCTAssertTrue(fileManager._itemExists(at: newDirectoryURL, isDirectory: &isDirectory))
|
||||
|
||||
|
||||
try! fileManager.removeItem(at: directoryURL)
|
||||
XCTAssertNil(try? fileManager.makeDirectory(at: validSymlinkURL))
|
||||
}
|
||||
|
||||
@@ -14,47 +14,47 @@ class SUSpotlightImporterTest: XCTestCase
|
||||
{
|
||||
let fileManager = SUFileManager()
|
||||
let tempDirectoryURL = try! fileManager.makeTemporaryDirectory(withPreferredName: "Sparkle Unit Test Data", appropriateForDirectoryURL: URL(fileURLWithPath: NSHomeDirectory()))
|
||||
|
||||
|
||||
let bundleDirectory = tempDirectoryURL.appendingPathComponent("bundle.app")
|
||||
try! fileManager.makeDirectory(at: bundleDirectory)
|
||||
|
||||
|
||||
let innerDirectory = bundleDirectory.appendingPathComponent("foo")
|
||||
try! fileManager.makeDirectory(at: innerDirectory)
|
||||
try! Data().write(to: (bundleDirectory.appendingPathComponent("bar")), options: .atomicWrite)
|
||||
|
||||
|
||||
let importerDirectory = innerDirectory.appendingPathComponent("baz.mdimporter")
|
||||
|
||||
|
||||
try! fileManager.makeDirectory(at: importerDirectory)
|
||||
try! fileManager.makeDirectory(at: innerDirectory.appendingPathComponent("flag"))
|
||||
|
||||
|
||||
try! Data().write(to: (importerDirectory.appendingPathComponent("file")), options: .atomicWrite)
|
||||
|
||||
|
||||
let oldFooDirectoryAttributes = try! FileManager.default.attributesOfItem(atPath: innerDirectory.path)
|
||||
let oldBarFileAttributes = try! FileManager.default.attributesOfItem(atPath: bundleDirectory.appendingPathComponent("bar").path)
|
||||
let oldImporterAttributes = try! FileManager.default.attributesOfItem(atPath: importerDirectory.path)
|
||||
let oldFlagAttributes = try! FileManager.default.attributesOfItem(atPath: innerDirectory.appendingPathComponent("flag").path)
|
||||
let oldFileInImporterAttributes = try! FileManager.default.attributesOfItem(atPath: importerDirectory.appendingPathComponent("file").path)
|
||||
|
||||
|
||||
sleep(1) // wait for clock to advance
|
||||
|
||||
|
||||
// Update spotlight bundles
|
||||
SUBinaryDeltaUnarchiver.updateSpotlightImporters(atBundlePath: bundleDirectory.path)
|
||||
|
||||
|
||||
let newFooDirectoryAttributes = try! FileManager.default.attributesOfItem(atPath: innerDirectory.path)
|
||||
XCTAssertEqual((newFooDirectoryAttributes[FileAttributeKey.modificationDate] as! Date).timeIntervalSince(oldFooDirectoryAttributes[FileAttributeKey.modificationDate] as! Date), 0)
|
||||
|
||||
|
||||
let newBarFileAttributes = try! FileManager.default.attributesOfItem(atPath: bundleDirectory.appendingPathComponent("bar").path)
|
||||
XCTAssertEqual((newBarFileAttributes[FileAttributeKey.modificationDate] as! Date).timeIntervalSince(oldBarFileAttributes[FileAttributeKey.modificationDate] as! Date), 0)
|
||||
|
||||
|
||||
let newImporterAttributes = try! FileManager.default.attributesOfItem(atPath: importerDirectory.path)
|
||||
XCTAssertGreaterThan((newImporterAttributes[FileAttributeKey.modificationDate] as! Date).timeIntervalSince(oldImporterAttributes[FileAttributeKey.modificationDate] as! Date), 0)
|
||||
|
||||
|
||||
let newFlagAttributes = try! FileManager.default.attributesOfItem(atPath: innerDirectory.appendingPathComponent("flag").path)
|
||||
XCTAssertEqual((newFlagAttributes[FileAttributeKey.modificationDate] as! Date).timeIntervalSince(oldFlagAttributes[FileAttributeKey.modificationDate] as! Date), 0)
|
||||
|
||||
|
||||
let newFileInImporterAttributes = try! FileManager.default.attributesOfItem(atPath: importerDirectory.appendingPathComponent("file").path)
|
||||
XCTAssertEqual((newFileInImporterAttributes[FileAttributeKey.modificationDate] as! Date).timeIntervalSince(oldFileInImporterAttributes[FileAttributeKey.modificationDate] as! Date), 0)
|
||||
|
||||
|
||||
try! fileManager.removeItem(at: tempDirectoryURL)
|
||||
}
|
||||
}
|
||||
@@ -13,84 +13,84 @@ class SUUnarchiverTest: XCTestCase
|
||||
func unarchiveTestAppWithExtension(_ archiveExtension: String, password: String? = nil) {
|
||||
let appName = "SparkleTestCodeSignApp"
|
||||
let archiveResourceURL = Bundle(for: type(of: self)).url(forResource: appName, withExtension: archiveExtension)!
|
||||
|
||||
|
||||
let fileManager = FileManager.default
|
||||
|
||||
|
||||
// Do not remove this temporary directory
|
||||
// If we do want to clean up and remove it (which isn't necessary but nice), we'd have to remove it
|
||||
// after *both* our unarchive success and failure calls below finish (they both have async completion blocks inside their implementation)
|
||||
let tempDirectoryURL = try! fileManager.url(for: .itemReplacementDirectory, in: .userDomainMask, appropriateFor: URL(fileURLWithPath: NSHomeDirectory()), create: true)
|
||||
|
||||
|
||||
let unarchivedSuccessExpectation = super.expectation(description: "Unarchived Success (format: \(archiveExtension))")
|
||||
let unarchivedFailureExpectation = super.expectation(description: "Unarchived Failure (format: \(archiveExtension))")
|
||||
|
||||
|
||||
let tempArchiveURL = tempDirectoryURL.appendingPathComponent(archiveResourceURL.lastPathComponent)
|
||||
let extractedAppURL = tempDirectoryURL.appendingPathComponent(appName).appendingPathExtension("app")
|
||||
|
||||
self.unarchiveTestSuccessAppWithExtension(archiveExtension, appName: appName, tempDirectoryURL: tempDirectoryURL, tempArchiveURL: tempArchiveURL, archiveResourceURL: archiveResourceURL, password: password, testExpectation: unarchivedSuccessExpectation);
|
||||
self.unarchiveTestFailureAppWithExtension(archiveExtension, tempDirectoryURL: tempDirectoryURL, password: password, testExpectation: unarchivedFailureExpectation);
|
||||
|
||||
|
||||
self.unarchiveTestSuccessAppWithExtension(archiveExtension, appName: appName, tempDirectoryURL: tempDirectoryURL, tempArchiveURL: tempArchiveURL, archiveResourceURL: archiveResourceURL, password: password, testExpectation: unarchivedSuccessExpectation)
|
||||
self.unarchiveTestFailureAppWithExtension(archiveExtension, tempDirectoryURL: tempDirectoryURL, password: password, testExpectation: unarchivedFailureExpectation)
|
||||
|
||||
super.waitForExpectations(timeout: 7.0, handler: nil)
|
||||
|
||||
|
||||
XCTAssertTrue(fileManager.fileExists(atPath: extractedAppURL.path))
|
||||
|
||||
|
||||
XCTAssertEqual("6a60ab31430cfca8fb499a884f4a29f73e59b472", hashOfTree(extractedAppURL.path))
|
||||
}
|
||||
|
||||
|
||||
func unarchiveTestFailureAppWithExtension(_ archiveExtension: String, tempDirectoryURL: URL, password: String?, testExpectation: XCTestExpectation) {
|
||||
let tempArchiveURL = tempDirectoryURL.appendingPathComponent("error-invalid").appendingPathExtension(archiveExtension);
|
||||
let tempArchiveURL = tempDirectoryURL.appendingPathComponent("error-invalid").appendingPathExtension(archiveExtension)
|
||||
let unarchiver = SUUnarchiver.unarchiver(forPath: tempArchiveURL.path, updatingHostBundlePath: nil, decryptionPassword: password)!
|
||||
|
||||
|
||||
unarchiver.unarchive(completionBlock: {(error: Error?) -> Void in
|
||||
XCTAssertNotNil(error);
|
||||
XCTAssertNotNil(error)
|
||||
testExpectation.fulfill()
|
||||
}, progressBlock: nil);
|
||||
}, progressBlock: nil)
|
||||
}
|
||||
|
||||
|
||||
func unarchiveTestSuccessAppWithExtension(_ archiveExtension: String, appName: String, tempDirectoryURL: URL, tempArchiveURL: URL, archiveResourceURL: URL, password: String?, testExpectation: XCTestExpectation) {
|
||||
|
||||
|
||||
let fileManager = FileManager.default
|
||||
|
||||
|
||||
try! fileManager.copyItem(at: archiveResourceURL, to: tempArchiveURL)
|
||||
|
||||
|
||||
let unarchiver = SUUnarchiver.unarchiver(forPath: tempArchiveURL.path, updatingHostBundlePath: nil, decryptionPassword: password)!
|
||||
|
||||
|
||||
unarchiver.unarchive(completionBlock: {(error: Error?) -> Void in
|
||||
XCTAssertNil(error);
|
||||
XCTAssertNil(error)
|
||||
testExpectation.fulfill()
|
||||
}, progressBlock: nil);
|
||||
}, progressBlock: nil)
|
||||
}
|
||||
|
||||
|
||||
func testUnarchivingZip()
|
||||
{
|
||||
self.unarchiveTestAppWithExtension("zip")
|
||||
}
|
||||
|
||||
|
||||
func testUnarchivingTarDotGz()
|
||||
{
|
||||
self.unarchiveTestAppWithExtension("tar.gz")
|
||||
}
|
||||
|
||||
|
||||
func testUnarchivingTar()
|
||||
{
|
||||
self.unarchiveTestAppWithExtension("tar")
|
||||
}
|
||||
|
||||
|
||||
func testUnarchivingTarDotBz2()
|
||||
{
|
||||
self.unarchiveTestAppWithExtension("tar.bz2")
|
||||
}
|
||||
|
||||
|
||||
func testUnarchivingTarDotXz()
|
||||
{
|
||||
self.unarchiveTestAppWithExtension("tar.xz")
|
||||
}
|
||||
|
||||
|
||||
func testUnarchivingDmg()
|
||||
{
|
||||
self.unarchiveTestAppWithExtension("dmg")
|
||||
}
|
||||
|
||||
|
||||
func testUnarchivingEncryptedDmg()
|
||||
{
|
||||
self.unarchiveTestAppWithExtension("enc.dmg", password: "testpass")
|
||||
|
||||
@@ -10,10 +10,10 @@ import XCTest
|
||||
|
||||
class SUTestApplicationTest: XCTestCase
|
||||
{
|
||||
var testApplicationURL: URL? = nil
|
||||
var testApplicationBackupURL: URL? = nil
|
||||
var tempDirectoryURL: URL? = nil
|
||||
|
||||
var testApplicationURL: URL?
|
||||
var testApplicationBackupURL: URL?
|
||||
var tempDirectoryURL: URL?
|
||||
|
||||
func runningTestApplication() -> NSRunningApplication
|
||||
{
|
||||
// TODO: don't hardcode bundle ID?
|
||||
@@ -21,91 +21,91 @@ class SUTestApplicationTest: XCTestCase
|
||||
XCTAssertEqual(runningApplications.count, 1, "More than one or zero running instances of the Test Application are found")
|
||||
return runningApplications[0]
|
||||
}
|
||||
|
||||
|
||||
override func setUp()
|
||||
{
|
||||
super.setUp()
|
||||
|
||||
|
||||
let app = XCUIApplication()
|
||||
app.launch()
|
||||
|
||||
|
||||
XCTAssertFalse(app.dialogs["alert"].staticTexts["Update succeeded!"].exists, "Update is already installed; please do a clean build")
|
||||
|
||||
|
||||
// We need to grab the app URL so we can back up the app
|
||||
// When a successful test is over we'll revert the update
|
||||
let testApplicationURL = self.runningTestApplication().bundleURL!
|
||||
|
||||
|
||||
let tempDirectoryURL = try! FileManager.default.url(for: .itemReplacementDirectory, in: FileManager.SearchPathDomainMask.userDomainMask, appropriateFor: testApplicationURL, create: true)
|
||||
|
||||
|
||||
let testApplicationBackupURL = tempDirectoryURL.appendingPathComponent(testApplicationURL.lastPathComponent)
|
||||
|
||||
|
||||
try! FileManager.default.copyItem(at: testApplicationURL, to: testApplicationBackupURL)
|
||||
|
||||
|
||||
self.testApplicationURL = testApplicationURL
|
||||
self.testApplicationBackupURL = testApplicationBackupURL
|
||||
self.tempDirectoryURL = tempDirectoryURL
|
||||
|
||||
|
||||
// when we add more tests we don't want to continue after a failure
|
||||
// since a test can fail after the new app has been placed in
|
||||
self.continueAfterFailure = false
|
||||
}
|
||||
|
||||
|
||||
override func tearDown()
|
||||
{
|
||||
// Terminate just in case the app hasn't already quit
|
||||
XCUIApplication().terminate()
|
||||
|
||||
|
||||
// Revert our update with the original test application
|
||||
|
||||
var resultingURL: NSURL? = nil
|
||||
|
||||
var resultingURL: NSURL?
|
||||
try! FileManager.default.replaceItem(at: self.testApplicationURL!, withItemAt: self.testApplicationBackupURL!, backupItemName: nil, options: .usingNewMetadataOnly, resultingItemURL: &resultingURL)
|
||||
|
||||
|
||||
do {
|
||||
try FileManager.default.removeItem(at: self.tempDirectoryURL!)
|
||||
} catch let error as NSError {
|
||||
NSLog("Failed to remove temporary directory \(self.tempDirectoryURL) with error: \(error)")
|
||||
}
|
||||
|
||||
|
||||
// The URL we get back from NSFileManager should be the same..
|
||||
XCTAssertEqual(self.testApplicationURL, resultingURL as URL?, "Test application was replaced, but at a different location")
|
||||
|
||||
|
||||
super.tearDown()
|
||||
}
|
||||
|
||||
|
||||
func testRegularUpdate()
|
||||
{
|
||||
let app = XCUIApplication()
|
||||
let menuBarsQuery = app.menuBars
|
||||
|
||||
menuBarsQuery.menuBarItems["Sparkle Test App"].click()
|
||||
|
||||
|
||||
// If the update window already showed up automatically, this option will be disabled.
|
||||
// Even if it's disabled, attempting to click it will do no harm and continue on
|
||||
menuBarsQuery.menuItems["Check for Updates…"].click()
|
||||
|
||||
|
||||
// Workaround to make sure we can click the install update button later
|
||||
// This workaround is needed if the alert prompts up automatically *before* we manually check for updates
|
||||
// I'm not sure why this workaround works or is necessary
|
||||
app.dialogs["SUUpdateAlert"].staticTexts["Software Update"].click()
|
||||
|
||||
|
||||
app.dialogs["SUUpdateAlert"].buttons["Install Update"].click()
|
||||
app.windows["SUStatus"].buttons["Install and Relaunch"].click()
|
||||
|
||||
|
||||
// Wait for the new updated app to finish launching so we can test if it's the frontmost app
|
||||
sleep(3)
|
||||
|
||||
|
||||
// Our new updated app should be launched now. Test if it's the active app
|
||||
// We used to run into timing issues where the updated app sometimes may not show up as the frontmost one
|
||||
XCTAssertTrue(self.runningTestApplication().isActive)
|
||||
|
||||
|
||||
// Grab another XCUIApplication instance rather than using the old one, just in case
|
||||
let updatedApp = XCUIApplication()
|
||||
|
||||
|
||||
// Check if we can click the "Update succeeded!" label rather than using the exists property
|
||||
// Checking the exists property doesn't reload the "cache" and as such the UI tests still would think we are
|
||||
// referring to the older app. Clicking does force the UI tests to find the new app however
|
||||
updatedApp.dialogs["alert"].staticTexts["Update succeeded!"].click()
|
||||
|
||||
|
||||
updatedApp.dialogs["alert"].buttons["OK"].click()
|
||||
}
|
||||
}
|
||||
@@ -6,12 +6,12 @@
|
||||
import Foundation
|
||||
|
||||
// Maximum number of delta updates (per OS).
|
||||
let maxDeltas = 5;
|
||||
let maxDeltas = 5
|
||||
|
||||
func makeError(code: SUError, _ description: String) -> NSError {
|
||||
return NSError(domain: SUSparkleErrorDomain, code: Int(OSStatus(code.rawValue)), userInfo: [
|
||||
NSLocalizedDescriptionKey: description,
|
||||
]);
|
||||
])
|
||||
}
|
||||
|
||||
func makeAppcast(archivesSourceDir: URL, keys: PrivateKeys, verbose: Bool) throws -> [String:[ArchiveItem]] {
|
||||
@@ -20,19 +20,19 @@ func makeAppcast(archivesSourceDir: URL, keys: PrivateKeys, verbose: Bool) throw
|
||||
|
||||
let allUpdates = (try unarchiveUpdates(archivesSourceDir: archivesSourceDir, archivesDestDir: cacheDir, verbose:verbose))
|
||||
.sorted(by: {
|
||||
.orderedDescending == comparator.compareVersion($0.version, toVersion:$1.version)
|
||||
.orderedDescending == comparator.compareVersion($0.version, toVersion: $1.version)
|
||||
})
|
||||
|
||||
if allUpdates.count == 0 {
|
||||
throw makeError(code: .noUpdateError, "No usable archives found in \(archivesSourceDir.path)");
|
||||
throw makeError(code: .noUpdateError, "No usable archives found in \(archivesSourceDir.path)")
|
||||
}
|
||||
|
||||
var updatesByAppcast:[String:[ArchiveItem]] = [:];
|
||||
var updatesByAppcast: [String: [ArchiveItem]] = [:]
|
||||
|
||||
let group = DispatchGroup();
|
||||
let group = DispatchGroup()
|
||||
|
||||
for update in allUpdates {
|
||||
group.enter();
|
||||
group.enter()
|
||||
DispatchQueue.global().async {
|
||||
if let privateDSAKey = keys.privateDSAKey {
|
||||
do {
|
||||
@@ -62,27 +62,27 @@ func makeAppcast(archivesSourceDir: URL, keys: PrivateKeys, verbose: Bool) throw
|
||||
group.leave();
|
||||
}
|
||||
|
||||
let appcastFile = update.feedURL?.lastPathComponent ?? "appcast.xml";
|
||||
let appcastFile = update.feedURL?.lastPathComponent ?? "appcast.xml"
|
||||
if updatesByAppcast[appcastFile] == nil {
|
||||
updatesByAppcast[appcastFile] = [];
|
||||
updatesByAppcast[appcastFile] = []
|
||||
}
|
||||
updatesByAppcast[appcastFile]!.append(update);
|
||||
updatesByAppcast[appcastFile]!.append(update)
|
||||
}
|
||||
|
||||
for (_, updates) in updatesByAppcast {
|
||||
var latestUpdatePerOS:[String:ArchiveItem] = [:];
|
||||
var latestUpdatePerOS: [String: ArchiveItem] = [:]
|
||||
|
||||
for update in updates {
|
||||
// items are ordered starting latest first
|
||||
let os = update.minimumSystemVersion;
|
||||
let os = update.minimumSystemVersion
|
||||
if latestUpdatePerOS[os] == nil {
|
||||
latestUpdatePerOS[os] = update;
|
||||
latestUpdatePerOS[os] = update
|
||||
}
|
||||
}
|
||||
|
||||
for (_,latestItem) in latestUpdatePerOS {
|
||||
var numDeltas = 0;
|
||||
let appBaseName = latestItem.appPath.deletingPathExtension().lastPathComponent;
|
||||
for (_, latestItem) in latestUpdatePerOS {
|
||||
var numDeltas = 0
|
||||
let appBaseName = latestItem.appPath.deletingPathExtension().lastPathComponent
|
||||
for item in updates {
|
||||
if numDeltas > maxDeltas {
|
||||
break;
|
||||
@@ -90,15 +90,15 @@ func makeAppcast(archivesSourceDir: URL, keys: PrivateKeys, verbose: Bool) throw
|
||||
|
||||
// No downgrades
|
||||
if .orderedAscending != comparator.compareVersion(item.version, toVersion: latestItem.version) {
|
||||
continue;
|
||||
continue
|
||||
}
|
||||
// Old version will not be able to verify the new version
|
||||
if !item.supportsDSA && item.publicEdKey == nil {
|
||||
continue;
|
||||
}
|
||||
|
||||
let deltaBaseName = appBaseName + latestItem.version + "-" + item.version;
|
||||
let deltaPath = archivesSourceDir.appendingPathComponent(deltaBaseName).appendingPathExtension("delta");
|
||||
let deltaBaseName = appBaseName + latestItem.version + "-" + item.version
|
||||
let deltaPath = archivesSourceDir.appendingPathComponent(deltaBaseName).appendingPathExtension("delta")
|
||||
|
||||
var delta:DeltaUpdate;
|
||||
let ignoreMarkerPath = cacheDir.appendingPathComponent(deltaPath.lastPathComponent).appendingPathExtension(".ignore");
|
||||
@@ -108,13 +108,13 @@ func makeAppcast(archivesSourceDir: URL, keys: PrivateKeys, verbose: Bool) throw
|
||||
}
|
||||
if !fm.fileExists(atPath: deltaPath.path) {
|
||||
do {
|
||||
delta = try DeltaUpdate.create(from: item, to: latestItem, archivePath: deltaPath);
|
||||
delta = try DeltaUpdate.create(from: item, to: latestItem, archivePath: deltaPath)
|
||||
} catch {
|
||||
print("Could not create delta update", deltaPath.path, error);
|
||||
continue;
|
||||
print("Could not create delta update", deltaPath.path, error)
|
||||
continue
|
||||
}
|
||||
} else {
|
||||
delta = DeltaUpdate(fromVersion: item.version, archivePath: deltaPath);
|
||||
delta = DeltaUpdate(fromVersion: item.version, archivePath: deltaPath)
|
||||
}
|
||||
|
||||
numDeltas += 1;
|
||||
@@ -131,7 +131,7 @@ func makeAppcast(archivesSourceDir: URL, keys: PrivateKeys, verbose: Bool) throw
|
||||
do {
|
||||
delta.dsaSignature = try dsaSignature(path: deltaPath, privateDSAKey: privateDSAKey);
|
||||
} catch {
|
||||
print(delta.archivePath.lastPathComponent, error);
|
||||
print(delta.archivePath.lastPathComponent, error)
|
||||
}
|
||||
}
|
||||
if let publicEdKey = item.publicEdKey, let privateEdKey = keys.privateEdKey {
|
||||
@@ -153,9 +153,9 @@ func makeAppcast(archivesSourceDir: URL, keys: PrivateKeys, verbose: Bool) throw
|
||||
}
|
||||
}
|
||||
|
||||
group.wait();
|
||||
group.wait()
|
||||
|
||||
return updatesByAppcast;
|
||||
return updatesByAppcast
|
||||
}
|
||||
|
||||
func markDeltaAsIgnored(delta: DeltaUpdate, markerPath: URL) {
|
||||
|
||||
@@ -12,23 +12,23 @@ class DeltaUpdate {
|
||||
var edSignature: String?;
|
||||
|
||||
init(fromVersion: String, archivePath: URL) {
|
||||
self.archivePath = archivePath;
|
||||
self.fromVersion = fromVersion;
|
||||
self.archivePath = archivePath
|
||||
self.fromVersion = fromVersion
|
||||
}
|
||||
|
||||
var fileSize : Int64 {
|
||||
let archiveFileAttributes = try! FileManager.default.attributesOfItem(atPath: self.archivePath.path);
|
||||
return (archiveFileAttributes[.size] as! NSNumber).int64Value;
|
||||
var fileSize: Int64 {
|
||||
let archiveFileAttributes = try! FileManager.default.attributesOfItem(atPath: self.archivePath.path)
|
||||
return (archiveFileAttributes[.size] as! NSNumber).int64Value
|
||||
}
|
||||
|
||||
class func create(from: ArchiveItem, to: ArchiveItem, archivePath: URL) throws -> DeltaUpdate {
|
||||
var applyDiffError: NSError? = nil;
|
||||
var applyDiffError: NSError?
|
||||
|
||||
if (!createBinaryDelta(from.appPath.path, to.appPath.path, archivePath.path, .beigeMajorVersion, false, &applyDiffError)) {
|
||||
throw applyDiffError!;
|
||||
if !createBinaryDelta(from.appPath.path, to.appPath.path, archivePath.path, .beigeMajorVersion, false, &applyDiffError) {
|
||||
throw applyDiffError!
|
||||
}
|
||||
|
||||
return DeltaUpdate(fromVersion: from.version, archivePath: archivePath);
|
||||
return DeltaUpdate(fromVersion: from.version, archivePath: archivePath)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,7 +82,7 @@ class ArchiveItem: CustomStringConvertible {
|
||||
|
||||
let appPath = bundles[0];
|
||||
guard let infoPlist = NSDictionary(contentsOf: appPath.appendingPathComponent("Contents/Info.plist")) else {
|
||||
throw makeError(code: .unarchivingError, "No plist \(appPath.path)");
|
||||
throw makeError(code: .unarchivingError, "No plist \(appPath.path)")
|
||||
}
|
||||
guard let version = infoPlist[kCFBundleVersionKey] as? String else {
|
||||
throw makeError(code: .unarchivingError, "No Version \(kCFBundleVersionKey as String? ?? "missing kCFBundleVersionKey") \(appPath)");
|
||||
@@ -91,9 +91,9 @@ class ArchiveItem: CustomStringConvertible {
|
||||
let publicEdKey = infoPlist[SUPublicEDKeyKey] as? String;
|
||||
let supportsDSA = infoPlist[SUPublicDSAKeyKey] != nil || infoPlist[SUPublicDSAKeyFileKey] != nil;
|
||||
|
||||
var feedURL:URL? = nil;
|
||||
var feedURL: URL?
|
||||
if let feedURLStr = infoPlist["SUFeedURL"] as? String {
|
||||
feedURL = URL(string: feedURLStr);
|
||||
feedURL = URL(string: feedURLStr)
|
||||
}
|
||||
|
||||
try self.init(version: version,
|
||||
@@ -105,21 +105,21 @@ class ArchiveItem: CustomStringConvertible {
|
||||
appPath: appPath,
|
||||
archivePath: archivePath);
|
||||
} else {
|
||||
throw makeError(code: .missingUpdateError, "No supported items in \(unarchivedDir) \(items) [note: only .app bundles are supported]");
|
||||
throw makeError(code: .missingUpdateError, "No supported items in \(unarchivedDir) \(items) [note: only .app bundles are supported]")
|
||||
}
|
||||
}
|
||||
|
||||
var shortVersion: String {
|
||||
return self._shortVersion ?? self.version;
|
||||
return self._shortVersion ?? self.version
|
||||
}
|
||||
|
||||
var description : String {
|
||||
var description: String {
|
||||
return "\(self.archivePath) \(self.version)"
|
||||
}
|
||||
|
||||
var archiveURL: URL? {
|
||||
guard let escapedFilename = self.archivePath.lastPathComponent.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) else {
|
||||
return nil;
|
||||
return nil
|
||||
}
|
||||
if let relative = self.feedURL {
|
||||
return URL(string: escapedFilename, relativeTo: relative)
|
||||
@@ -127,27 +127,27 @@ class ArchiveItem: CustomStringConvertible {
|
||||
return URL(string: escapedFilename)
|
||||
}
|
||||
|
||||
var pubDate : String {
|
||||
let date = self.archiveFileAttributes[.creationDate] as! Date;
|
||||
let formatter = DateFormatter();
|
||||
formatter.dateFormat = "EEE, dd MMM yyyy HH:mm:ss ZZ";
|
||||
return formatter.string(from: date);
|
||||
var pubDate: String {
|
||||
let date = self.archiveFileAttributes[.creationDate] as! Date
|
||||
let formatter = DateFormatter()
|
||||
formatter.dateFormat = "EEE, dd MMM yyyy HH:mm:ss ZZ"
|
||||
return formatter.string(from: date)
|
||||
}
|
||||
|
||||
var fileSize : Int64 {
|
||||
return (self.archiveFileAttributes[.size] as! NSNumber).int64Value;
|
||||
var fileSize: Int64 {
|
||||
return (self.archiveFileAttributes[.size] as! NSNumber).int64Value
|
||||
}
|
||||
|
||||
private var releaseNotesPath : URL? {
|
||||
var basename = self.archivePath.deletingPathExtension();
|
||||
if basename.pathExtension == "tar" { // tar.gz
|
||||
basename = basename.deletingPathExtension();
|
||||
basename = basename.deletingPathExtension()
|
||||
}
|
||||
let releaseNotes = basename.appendingPathExtension("html");
|
||||
let releaseNotes = basename.appendingPathExtension("html")
|
||||
if !FileManager.default.fileExists(atPath: releaseNotes.path) {
|
||||
return nil;
|
||||
return nil
|
||||
}
|
||||
return releaseNotes;
|
||||
return releaseNotes
|
||||
}
|
||||
|
||||
private func getReleaseNotesAsHTMLFragment(_ path: URL) -> String? {
|
||||
@@ -155,29 +155,29 @@ class ArchiveItem: CustomStringConvertible {
|
||||
if html.utf8.count < 1000 &&
|
||||
!html.localizedCaseInsensitiveContains("<!DOCTYPE") &&
|
||||
!html.localizedCaseInsensitiveContains("<body") {
|
||||
return html;
|
||||
return html
|
||||
}
|
||||
}
|
||||
return nil;
|
||||
return nil
|
||||
}
|
||||
|
||||
var releaseNotesHTML : String? {
|
||||
var releaseNotesHTML: String? {
|
||||
if let path = self.releaseNotesPath {
|
||||
return self.getReleaseNotesAsHTMLFragment(path);
|
||||
return self.getReleaseNotesAsHTMLFragment(path)
|
||||
}
|
||||
return nil;
|
||||
return nil
|
||||
}
|
||||
|
||||
var releaseNotesURL : URL? {
|
||||
var releaseNotesURL: URL? {
|
||||
guard let path = self.releaseNotesPath else {
|
||||
return nil;
|
||||
return nil
|
||||
}
|
||||
// The file is already used as inline description
|
||||
if self.getReleaseNotesAsHTMLFragment(path) != nil {
|
||||
return nil;
|
||||
return nil
|
||||
}
|
||||
guard let escapedFilename = path.lastPathComponent.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) else {
|
||||
return nil;
|
||||
return nil
|
||||
}
|
||||
if let relative = self.feedURL {
|
||||
return URL(string: escapedFilename, relativeTo: relative)
|
||||
@@ -185,5 +185,5 @@ class ArchiveItem: CustomStringConvertible {
|
||||
return URL(string: escapedFilename)
|
||||
}
|
||||
|
||||
let mimeType = "application/octet-stream";
|
||||
let mimeType = "application/octet-stream"
|
||||
}
|
||||
@@ -5,22 +5,22 @@
|
||||
|
||||
import Foundation
|
||||
|
||||
let maxVersionsInFeed = 5;
|
||||
let maxVersionsInFeed = 5
|
||||
|
||||
func findElement(name: String, parent: XMLElement) -> XMLElement? {
|
||||
if let found = try? parent.nodes(forXPath: name) {
|
||||
if found.count > 0 {
|
||||
if let element = found[0] as? XMLElement {
|
||||
return element;
|
||||
return element
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil;
|
||||
return nil
|
||||
}
|
||||
|
||||
func findOrCreateElement(name: String, parent: XMLElement) -> XMLElement {
|
||||
if let element = findElement(name: name, parent: parent) {
|
||||
return element;
|
||||
return element
|
||||
}
|
||||
let element = XMLElement(name: name);
|
||||
parent.addChild(element);
|
||||
@@ -33,59 +33,59 @@ func text(_ text: String) -> XMLNode {
|
||||
|
||||
|
||||
func writeAppcast(appcastDestPath: URL, updates: [ArchiveItem]) throws {
|
||||
let appBaseName = updates[0].appPath.deletingPathExtension().lastPathComponent;
|
||||
let appBaseName = updates[0].appPath.deletingPathExtension().lastPathComponent
|
||||
|
||||
let sparkleNS = "http://www.andymatuschak.org/xml-namespaces/sparkle";
|
||||
let sparkleNS = "http://www.andymatuschak.org/xml-namespaces/sparkle"
|
||||
|
||||
var doc: XMLDocument;
|
||||
var doc: XMLDocument
|
||||
do {
|
||||
let options: XMLNode.Options = [
|
||||
XMLNode.Options.nodeLoadExternalEntitiesNever,
|
||||
XMLNode.Options.nodePreserveCDATA,
|
||||
XMLNode.Options.nodePreserveWhitespace,
|
||||
];
|
||||
doc = try XMLDocument(contentsOf: appcastDestPath, options: options);
|
||||
]
|
||||
doc = try XMLDocument(contentsOf: appcastDestPath, options: options)
|
||||
} catch {
|
||||
let root = XMLElement(name: "rss");
|
||||
root.addAttribute(XMLNode.attribute(withName: "xmlns:sparkle", stringValue: sparkleNS) as! XMLNode);
|
||||
root.addAttribute(XMLNode.attribute(withName: "version", stringValue: "2.0") as! XMLNode);
|
||||
doc = XMLDocument(rootElement: root);
|
||||
doc.isStandalone = true;
|
||||
let root = XMLElement(name: "rss")
|
||||
root.addAttribute(XMLNode.attribute(withName: "xmlns:sparkle", stringValue: sparkleNS) as! XMLNode)
|
||||
root.addAttribute(XMLNode.attribute(withName: "version", stringValue: "2.0") as! XMLNode)
|
||||
doc = XMLDocument(rootElement: root)
|
||||
doc.isStandalone = true
|
||||
}
|
||||
|
||||
var channel: XMLElement;
|
||||
var channel: XMLElement
|
||||
|
||||
let rootNodes = try doc.nodes(forXPath: "/rss");
|
||||
let rootNodes = try doc.nodes(forXPath: "/rss")
|
||||
if rootNodes.count != 1 {
|
||||
throw makeError(code: .appcastError, "Weird XML? \(appcastDestPath.path)");
|
||||
throw makeError(code: .appcastError, "Weird XML? \(appcastDestPath.path)")
|
||||
}
|
||||
let root = rootNodes[0] as! XMLElement
|
||||
let channelNodes = try root.nodes(forXPath: "channel");
|
||||
let channelNodes = try root.nodes(forXPath: "channel")
|
||||
if channelNodes.count > 0 {
|
||||
channel = channelNodes[0] as! XMLElement;
|
||||
channel = channelNodes[0] as! XMLElement
|
||||
} else {
|
||||
channel = XMLElement(name: "channel");
|
||||
channel.addChild(XMLElement.element(withName: "title", stringValue: appBaseName) as! XMLElement);
|
||||
root.addChild(channel);
|
||||
}
|
||||
|
||||
var numItems = 0;
|
||||
var numItems = 0
|
||||
for update in updates {
|
||||
var item: XMLElement;
|
||||
let existingItems = try channel.nodes(forXPath: "item[enclosure[@sparkle:version=\"\(update.version)\"]]");
|
||||
let createNewItem = existingItems.count == 0;
|
||||
var item: XMLElement
|
||||
let existingItems = try channel.nodes(forXPath: "item[enclosure[@sparkle:version=\"\(update.version)\"]]")
|
||||
let createNewItem = existingItems.count == 0
|
||||
|
||||
// Update all old items, but aim for less than 5 in new feeds
|
||||
if createNewItem && numItems >= maxVersionsInFeed {
|
||||
continue;
|
||||
continue
|
||||
}
|
||||
numItems += 1;
|
||||
numItems += 1
|
||||
|
||||
if createNewItem {
|
||||
item = XMLElement.element(withName: "item") as! XMLElement;
|
||||
channel.addChild(item);
|
||||
} else {
|
||||
item = existingItems[0] as! XMLElement;
|
||||
item = existingItems[0] as! XMLElement
|
||||
}
|
||||
|
||||
if nil == findElement(name: "title", parent: item) {
|
||||
@@ -96,10 +96,10 @@ func writeAppcast(appcastDestPath: URL, updates: [ArchiveItem]) throws {
|
||||
}
|
||||
|
||||
if let html = update.releaseNotesHTML {
|
||||
let descElement = findOrCreateElement(name: "description", parent: item);
|
||||
let cdata = XMLNode(kind:.text, options:.nodeIsCDATA);
|
||||
cdata.stringValue = html;
|
||||
descElement.setChildren([cdata]);
|
||||
let descElement = findOrCreateElement(name: "description", parent: item)
|
||||
let cdata = XMLNode(kind: .text, options: .nodeIsCDATA)
|
||||
cdata.stringValue = html
|
||||
descElement.setChildren([cdata])
|
||||
}
|
||||
|
||||
var minVer = findElement(name: SUAppcastElementMinimumSystemVersion, parent: item);
|
||||
@@ -107,7 +107,7 @@ func writeAppcast(appcastDestPath: URL, updates: [ArchiveItem]) throws {
|
||||
minVer = XMLElement.element(withName: SUAppcastElementMinimumSystemVersion, uri: sparkleNS) as? XMLElement;
|
||||
item.addChild(minVer!);
|
||||
}
|
||||
minVer?.setChildren([text(update.minimumSystemVersion)]);
|
||||
minVer?.setChildren([text(update.minimumSystemVersion)])
|
||||
|
||||
let relElement = findElement(name: SUAppcastElementReleaseNotesLink, parent: item);
|
||||
if let url = update.releaseNotesURL {
|
||||
@@ -115,7 +115,7 @@ func writeAppcast(appcastDestPath: URL, updates: [ArchiveItem]) throws {
|
||||
item.addChild(XMLElement.element(withName: SUAppcastElementReleaseNotesLink, stringValue: url.absoluteString) as! XMLElement);
|
||||
}
|
||||
} else if let childIndex = relElement?.index {
|
||||
item.removeChild(at: childIndex);
|
||||
item.removeChild(at: childIndex)
|
||||
}
|
||||
|
||||
var enclosure = findElement(name: "enclosure", parent: item);
|
||||
@@ -125,8 +125,8 @@ func writeAppcast(appcastDestPath: URL, updates: [ArchiveItem]) throws {
|
||||
}
|
||||
|
||||
guard let archiveURL = update.archiveURL?.absoluteString else {
|
||||
throw makeError(code: .appcastError, "Bad archive name or feed URL");
|
||||
};
|
||||
throw makeError(code: .appcastError, "Bad archive name or feed URL")
|
||||
}
|
||||
var attributes = [
|
||||
XMLNode.attribute(withName: "url", stringValue: archiveURL) as! XMLNode,
|
||||
XMLNode.attribute(withName: SUAppcastAttributeVersion, uri: sparkleNS, stringValue: update.version) as! XMLNode,
|
||||
@@ -140,7 +140,7 @@ func writeAppcast(appcastDestPath: URL, updates: [ArchiveItem]) throws {
|
||||
if let sig = update.dsaSignature {
|
||||
attributes.append(XMLNode.attribute(withName: SUAppcastAttributeDSASignature, uri: sparkleNS, stringValue: sig) as! XMLNode);
|
||||
}
|
||||
enclosure!.attributes = attributes;
|
||||
enclosure!.attributes = attributes
|
||||
|
||||
if update.deltas.count > 0 {
|
||||
var deltas = findElement(name: SUAppcastElementDeltas, parent: item);
|
||||
@@ -148,7 +148,7 @@ func writeAppcast(appcastDestPath: URL, updates: [ArchiveItem]) throws {
|
||||
deltas = XMLElement.element(withName: SUAppcastElementDeltas, uri: sparkleNS) as? XMLElement;
|
||||
item.addChild(deltas!);
|
||||
} else {
|
||||
deltas!.setChildren([]);
|
||||
deltas!.setChildren([])
|
||||
}
|
||||
for delta in update.deltas {
|
||||
var attributes = [
|
||||
|
||||
@@ -20,21 +20,21 @@ struct PrivateKeys {
|
||||
func loadPrivateDSAKey(at privateKeyURL: URL) throws -> SecKey {
|
||||
let data = try Data(contentsOf: privateKeyURL);
|
||||
|
||||
var cfitems: CFArray? = nil;
|
||||
var format = SecExternalFormat.formatOpenSSL;
|
||||
var type = SecExternalItemType.itemTypePrivateKey;
|
||||
var cfitems: CFArray?
|
||||
var format = SecExternalFormat.formatOpenSSL
|
||||
var type = SecExternalItemType.itemTypePrivateKey
|
||||
|
||||
let status = SecItemImport(data as CFData, nil, &format, &type, SecItemImportExportFlags(rawValue: UInt32(0)), nil, nil, &cfitems);
|
||||
if (status != errSecSuccess || cfitems == nil) {
|
||||
print("Private DSA key file", privateKeyURL.path, "exists, but it could not be read. SecItemImport error", status);
|
||||
throw NSError(domain: SUSparkleErrorDomain, code: Int(OSStatus(SUError.signatureError.rawValue)), userInfo: nil);
|
||||
let status = SecItemImport(data as CFData, nil, &format, &type, SecItemImportExportFlags(rawValue: UInt32(0)), nil, nil, &cfitems)
|
||||
if status != errSecSuccess || cfitems == nil {
|
||||
print("Private DSA key file", privateKeyURL.path, "exists, but it could not be read. SecItemImport error", status)
|
||||
throw NSError(domain: SUSparkleErrorDomain, code: Int(OSStatus(SUError.signatureError.rawValue)), userInfo: nil)
|
||||
}
|
||||
|
||||
if (format != SecExternalFormat.formatOpenSSL || type != SecExternalItemType.itemTypePrivateKey) {
|
||||
throw makeError(code: .signatureError, "Not an OpensSSL private key \(format) \(type)");
|
||||
if format != SecExternalFormat.formatOpenSSL || type != SecExternalItemType.itemTypePrivateKey {
|
||||
throw makeError(code: .signatureError, "Not an OpensSSL private key \(format) \(type)")
|
||||
}
|
||||
|
||||
return (cfitems! as NSArray)[0] as! SecKey;
|
||||
return (cfitems! as NSArray)[0] as! SecKey
|
||||
}
|
||||
|
||||
func loadPrivateDSAKey(named keyName: String, fromKeychainAt keychainURL: URL) throws -> SecKey {
|
||||
@@ -50,7 +50,7 @@ func loadPrivateDSAKey(named keyName: String, fromKeychainAt keychainURL: URL) t
|
||||
kSecAttrLabel: keyName as CFString,
|
||||
kSecMatchLimit: kSecMatchLimitOne,
|
||||
kSecUseKeychain: keychain!,
|
||||
kSecReturnRef: kCFBooleanTrue
|
||||
kSecReturnRef: kCFBooleanTrue,
|
||||
]
|
||||
|
||||
var item: CFTypeRef? = nil
|
||||
@@ -63,10 +63,10 @@ func loadPrivateDSAKey(named keyName: String, fromKeychainAt keychainURL: URL) t
|
||||
|
||||
func dsaSignature(path: URL, privateDSAKey: SecKey) throws -> String {
|
||||
|
||||
var error: Unmanaged<CFError>?;
|
||||
var error: Unmanaged<CFError>?
|
||||
|
||||
let stream = InputStream(fileAtPath:path.path)!;
|
||||
let dataReadTransform = SecTransformCreateReadTransformWithReadStream(stream);
|
||||
let stream = InputStream(fileAtPath: path.path)!
|
||||
let dataReadTransform = SecTransformCreateReadTransformWithReadStream(stream)
|
||||
|
||||
let dataDigestTransform = SecDigestTransformCreate(kSecDigestSHA1, 20, nil);
|
||||
guard let dataSignTransform = SecSignTransformCreate(privateDSAKey, &error) else {
|
||||
@@ -74,25 +74,25 @@ func dsaSignature(path: URL, privateDSAKey: SecKey) throws -> String {
|
||||
throw error!.takeRetainedValue();
|
||||
}
|
||||
|
||||
let group = SecTransformCreateGroupTransform();
|
||||
SecTransformConnectTransforms(dataReadTransform, kSecTransformOutputAttributeName, dataDigestTransform, kSecTransformInputAttributeName, group, &error);
|
||||
if (error != nil) {
|
||||
throw error!.takeRetainedValue();
|
||||
let group = SecTransformCreateGroupTransform()
|
||||
SecTransformConnectTransforms(dataReadTransform, kSecTransformOutputAttributeName, dataDigestTransform, kSecTransformInputAttributeName, group, &error)
|
||||
if error != nil {
|
||||
throw error!.takeRetainedValue()
|
||||
}
|
||||
|
||||
SecTransformConnectTransforms(dataDigestTransform, kSecTransformOutputAttributeName, dataSignTransform, kSecTransformInputAttributeName, group, &error);
|
||||
if (error != nil) {
|
||||
throw error!.takeRetainedValue();
|
||||
SecTransformConnectTransforms(dataDigestTransform, kSecTransformOutputAttributeName, dataSignTransform, kSecTransformInputAttributeName, group, &error)
|
||||
if error != nil {
|
||||
throw error!.takeRetainedValue()
|
||||
}
|
||||
|
||||
let result = SecTransformExecute(group, &error);
|
||||
if (error != nil) {
|
||||
throw error!.takeRetainedValue();
|
||||
let result = SecTransformExecute(group, &error)
|
||||
if error != nil {
|
||||
throw error!.takeRetainedValue()
|
||||
}
|
||||
guard let resultData = result as? Data else {
|
||||
throw makeError(code: .signatureError, "SecTransformExecute returned non-data");
|
||||
throw makeError(code: .signatureError, "SecTransformExecute returned non-data")
|
||||
}
|
||||
return resultData.base64EncodedString();
|
||||
return resultData.base64EncodedString()
|
||||
}
|
||||
|
||||
func edSignature(path: URL, publicEdKey: Data, privateEdKey: Data) throws -> String {
|
||||
|
||||
@@ -5,12 +5,12 @@
|
||||
|
||||
import Foundation
|
||||
|
||||
func unarchive(itemPath:URL, archiveDestDir: URL, callback: @escaping (Error?) -> Void) {
|
||||
let fileManager = FileManager.default;
|
||||
let tempDir = archiveDestDir.appendingPathExtension("tmp");
|
||||
let itemCopy = tempDir.appendingPathComponent(itemPath.lastPathComponent);
|
||||
func unarchive(itemPath: URL, archiveDestDir: URL, callback: @escaping (Error?) -> Void) {
|
||||
let fileManager = FileManager.default
|
||||
let tempDir = archiveDestDir.appendingPathExtension("tmp")
|
||||
let itemCopy = tempDir.appendingPathComponent(itemPath.lastPathComponent)
|
||||
|
||||
_ = try? fileManager.createDirectory(at: tempDir, withIntermediateDirectories: true, attributes: [:]);
|
||||
_ = try? fileManager.createDirectory(at: tempDir, withIntermediateDirectories: true, attributes: [:])
|
||||
|
||||
do {
|
||||
do {
|
||||
@@ -21,89 +21,89 @@ func unarchive(itemPath:URL, archiveDestDir: URL, callback: @escaping (Error?) -
|
||||
if let unarchiver = SUUnarchiver.unarchiver(forPath: itemCopy.path, updatingHostBundlePath:nil, decryptionPassword:nil) {
|
||||
unarchiver.unarchive(completionBlock: { (error: Error?) in
|
||||
if error != nil {
|
||||
callback(error);
|
||||
return;
|
||||
callback(error)
|
||||
return
|
||||
}
|
||||
|
||||
_ = try? fileManager.removeItem(at: itemCopy);
|
||||
_ = try? fileManager.removeItem(at: itemCopy)
|
||||
do {
|
||||
try fileManager.moveItem(at: tempDir, to: archiveDestDir);
|
||||
callback(nil);
|
||||
try fileManager.moveItem(at: tempDir, to: archiveDestDir)
|
||||
callback(nil)
|
||||
} catch {
|
||||
callback(error);
|
||||
callback(error)
|
||||
}
|
||||
}, progressBlock: nil)
|
||||
} else {
|
||||
_ = try? fileManager.removeItem(at: itemCopy);
|
||||
callback(makeError(code: .unarchivingError, "Not a supported archive format: \(itemCopy)"));
|
||||
_ = try? fileManager.removeItem(at: itemCopy)
|
||||
callback(makeError(code: .unarchivingError, "Not a supported archive format: \(itemCopy)"))
|
||||
}
|
||||
} catch {
|
||||
_ = try? fileManager.removeItem(at: tempDir);
|
||||
callback(error);
|
||||
_ = try? fileManager.removeItem(at: tempDir)
|
||||
callback(error)
|
||||
}
|
||||
}
|
||||
|
||||
func unarchiveUpdates(archivesSourceDir: URL, archivesDestDir: URL, verbose: Bool) throws -> [ArchiveItem] {
|
||||
if verbose {
|
||||
print("Unarchiving to temp directory", archivesDestDir.path);
|
||||
print("Unarchiving to temp directory", archivesDestDir.path)
|
||||
}
|
||||
|
||||
let group = DispatchGroup();
|
||||
let group = DispatchGroup()
|
||||
|
||||
let fileManager = FileManager.default;
|
||||
let fileManager = FileManager.default
|
||||
|
||||
var unarchived:[ArchiveItem] = [];
|
||||
var unarchived: [ArchiveItem] = []
|
||||
|
||||
let dir = try fileManager.contentsOfDirectory(atPath: archivesSourceDir.path);
|
||||
var running = 0;
|
||||
let dir = try fileManager.contentsOfDirectory(atPath: archivesSourceDir.path)
|
||||
var running = 0
|
||||
for item in dir.filter({ !$0.hasPrefix(".") && !$0.hasSuffix(".delta") && !$0.hasSuffix(".xml") && !$0.hasSuffix(".html") }) {
|
||||
let itemPath = archivesSourceDir.appendingPathComponent(item);
|
||||
let archiveDestDir = archivesDestDir.appendingPathComponent(itemPath.lastPathComponent);
|
||||
let itemPath = archivesSourceDir.appendingPathComponent(item)
|
||||
let archiveDestDir = archivesDestDir.appendingPathComponent(itemPath.lastPathComponent)
|
||||
|
||||
var isDir:ObjCBool = false;
|
||||
if (fileManager.fileExists(atPath: itemPath.path, isDirectory: &isDir) && isDir.boolValue) {
|
||||
continue;
|
||||
var isDir: ObjCBool = false
|
||||
if fileManager.fileExists(atPath: itemPath.path, isDirectory: &isDir) && isDir.boolValue {
|
||||
continue
|
||||
}
|
||||
|
||||
let addItem = {
|
||||
do {
|
||||
let item = try ArchiveItem(fromArchive: itemPath, unarchivedDir: archiveDestDir);
|
||||
let item = try ArchiveItem(fromArchive: itemPath, unarchivedDir: archiveDestDir)
|
||||
if verbose {
|
||||
print("Found archive", item);
|
||||
print("Found archive", item)
|
||||
}
|
||||
objc_sync_enter(unarchived);
|
||||
unarchived.append(item);
|
||||
objc_sync_exit(unarchived);
|
||||
objc_sync_enter(unarchived)
|
||||
unarchived.append(item)
|
||||
objc_sync_exit(unarchived)
|
||||
} catch {
|
||||
if verbose {
|
||||
print("Skipped", item, error);
|
||||
print("Skipped", item, error)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if fileManager.fileExists(atPath: archiveDestDir.path) {
|
||||
addItem();
|
||||
addItem()
|
||||
} else {
|
||||
group.enter();
|
||||
group.enter()
|
||||
unarchive(itemPath: itemPath, archiveDestDir: archiveDestDir) { (error: Error?) in
|
||||
if let error = error {
|
||||
print("Could not unarchive", itemPath.path, error);
|
||||
print("Could not unarchive", itemPath.path, error)
|
||||
} else {
|
||||
addItem();
|
||||
addItem()
|
||||
}
|
||||
group.leave();
|
||||
group.leave()
|
||||
}
|
||||
}
|
||||
|
||||
// Crude limit of concurrency
|
||||
running += 1;
|
||||
running += 1
|
||||
if running >= 8 {
|
||||
running = 0;
|
||||
group.wait();
|
||||
running = 0
|
||||
group.wait()
|
||||
}
|
||||
}
|
||||
|
||||
group.wait();
|
||||
group.wait()
|
||||
|
||||
return unarchived;
|
||||
return unarchived
|
||||
}
|
||||
+11
-12
@@ -8,7 +8,7 @@
|
||||
|
||||
import Foundation
|
||||
|
||||
var verbose = false;
|
||||
var verbose = false
|
||||
|
||||
func printUsage() {
|
||||
let command = URL(fileURLWithPath: CommandLine.arguments.first!).lastPathComponent;
|
||||
@@ -80,8 +80,7 @@ func main() {
|
||||
|
||||
keyName = args[2]
|
||||
keychainURL = URL(fileURLWithPath: args[4])
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
if args[3] != "-n" {
|
||||
printUsage()
|
||||
exit(1)
|
||||
@@ -110,19 +109,19 @@ func main() {
|
||||
let allUpdates = try makeAppcast(archivesSourceDir: archivesSourceDir, keys: keys, verbose:verbose);
|
||||
|
||||
for (appcastFile, updates) in allUpdates {
|
||||
let appcastDestPath = URL(fileURLWithPath: appcastFile, relativeTo: archivesSourceDir);
|
||||
try writeAppcast(appcastDestPath:appcastDestPath, updates:updates);
|
||||
print("Written", appcastDestPath.path, "based on", updates.count, "updates");
|
||||
let appcastDestPath = URL(fileURLWithPath: appcastFile, relativeTo: archivesSourceDir)
|
||||
try writeAppcast(appcastDestPath: appcastDestPath, updates: updates)
|
||||
print("Written", appcastDestPath.path, "based on", updates.count, "updates")
|
||||
}
|
||||
} catch {
|
||||
print("Error generating appcast from directory", archivesSourceDir.path, "\n", error);
|
||||
exit(1);
|
||||
print("Error generating appcast from directory", archivesSourceDir.path, "\n", error)
|
||||
exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
DispatchQueue.global().async(execute: {
|
||||
main();
|
||||
CFRunLoopStop(CFRunLoopGetMain());
|
||||
});
|
||||
main()
|
||||
CFRunLoopStop(CFRunLoopGetMain())
|
||||
})
|
||||
|
||||
CFRunLoopRun();
|
||||
CFRunLoopRun()
|
||||
Reference in new issue
Block a user