diff --git a/.travis.yml b/.travis.yml
index 20dc67d5..a6bcf53f 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,7 +1,5 @@
language: objective-c
-osx_image: xcode7
+osx_image: xcode8
before_install:
- brew update
- - brew install macmade/tap/xcode-coveralls
script: make ci
-after_success: xcode-coveralls --exclude /Applications --exclude Tests --exclude Vendor build/Build/Intermediates/Sparkle.build/Coverage/Sparkle.build/Objects-normal/x86_64
diff --git a/Configurations/ConfigCommon.xcconfig b/Configurations/ConfigCommon.xcconfig
index 6894683f..97db40e7 100644
--- a/Configurations/ConfigCommon.xcconfig
+++ b/Configurations/ConfigCommon.xcconfig
@@ -36,8 +36,11 @@ GCC_PREPROCESSOR_DEFINITIONS_COMMON = SPARKLE_NORMALIZE_INSTALLED_APPLICATION_NA
CLANG_ENABLE_OBJC_ARC = YES
GCC_ENABLE_PASCAL_STRINGS = NO
+GCC_NO_COMMON_BLOCKS = YES;
+COMBINE_HIDPI_IMAGES = NO;
// Enable warnings
+CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
CLANG_ANALYZER_SECURITY_FLOATLOOPCOUNTER = YES
CLANG_ANALYZER_SECURITY_INSECUREAPI_RAND = YES
CLANG_ANALYZER_SECURITY_INSECUREAPI_STRCPY = YES
diff --git a/Configurations/ConfigSwift.xcconfig b/Configurations/ConfigSwift.xcconfig
new file mode 100644
index 00000000..8e0862f9
--- /dev/null
+++ b/Configurations/ConfigSwift.xcconfig
@@ -0,0 +1 @@
+SWIFT_VERSION = 3.0
diff --git a/Configurations/ConfigSwiftDebug.xcconfig b/Configurations/ConfigSwiftDebug.xcconfig
new file mode 100644
index 00000000..4a437b26
--- /dev/null
+++ b/Configurations/ConfigSwiftDebug.xcconfig
@@ -0,0 +1 @@
+SWIFT_OPTIMIZATION_LEVEL = -Onone
diff --git a/Configurations/ConfigSwiftRelease.xcconfig b/Configurations/ConfigSwiftRelease.xcconfig
new file mode 100644
index 00000000..05d2efe9
--- /dev/null
+++ b/Configurations/ConfigSwiftRelease.xcconfig
@@ -0,0 +1 @@
+SWIFT_OPTIMIZATION_LEVEL = -Ofast
diff --git a/Configurations/ConfigUITest.xcconfig b/Configurations/ConfigUITest.xcconfig
index 7b1706bd..badc3e13 100644
--- a/Configurations/ConfigUITest.xcconfig
+++ b/Configurations/ConfigUITest.xcconfig
@@ -1,5 +1,7 @@
// UI Test only
+#include "ConfigSwift.xcconfig"
+
INFOPLIST_FILE = UITests/UITests-Info.plist
WRAPPER_EXTENSION = xctest
MACOSX_DEPLOYMENT_TARGET = 10.11
diff --git a/Configurations/ConfigUITestDebug.xcconfig b/Configurations/ConfigUITestDebug.xcconfig
index 464bf485..486dab5b 100644
--- a/Configurations/ConfigUITestDebug.xcconfig
+++ b/Configurations/ConfigUITestDebug.xcconfig
@@ -1 +1,2 @@
#include "ConfigUITest.xcconfig"
+#include "ConfigSwiftDebug.xcconfig"
diff --git a/Configurations/ConfigUITestRelease.xcconfig b/Configurations/ConfigUITestRelease.xcconfig
index 464bf485..f8ae8bbf 100644
--- a/Configurations/ConfigUITestRelease.xcconfig
+++ b/Configurations/ConfigUITestRelease.xcconfig
@@ -1 +1,2 @@
#include "ConfigUITest.xcconfig"
+#include "ConfigSwiftRelease.xcconfig"
diff --git a/Configurations/ConfigUnitTest.xcconfig b/Configurations/ConfigUnitTest.xcconfig
index 36dc8857..f9e7cea3 100644
--- a/Configurations/ConfigUnitTest.xcconfig
+++ b/Configurations/ConfigUnitTest.xcconfig
@@ -1,5 +1,7 @@
// Unit Test only
+#include "ConfigSwift.xcconfig"
+
INFOPLIST_FILE = Tests/SparkleTests-Info.plist
WRAPPER_EXTENSION = xctest
OTHER_CFLAGS = $(inherited) -iframework"$(DEVELOPER_FRAMEWORKS_DIR)" -iframework"$(PLATFORM_DIR)/Developer/Library/Frameworks"
diff --git a/Configurations/ConfigUnitTestDebug.xcconfig b/Configurations/ConfigUnitTestDebug.xcconfig
index e2481b5e..869437db 100644
--- a/Configurations/ConfigUnitTestDebug.xcconfig
+++ b/Configurations/ConfigUnitTestDebug.xcconfig
@@ -1 +1,2 @@
#include "ConfigUnitTest.xcconfig"
+#include "ConfigSwiftDebug.xcconfig"
diff --git a/Configurations/ConfigUnitTestRelease.xcconfig b/Configurations/ConfigUnitTestRelease.xcconfig
index e2481b5e..e89e456c 100644
--- a/Configurations/ConfigUnitTestRelease.xcconfig
+++ b/Configurations/ConfigUnitTestRelease.xcconfig
@@ -1 +1,2 @@
#include "ConfigUnitTest.xcconfig"
+#include "ConfigSwiftRelease.xcconfig"
diff --git a/Makefile-icon b/Makefile-icon
new file mode 100644
index 00000000..7a04bb84
--- /dev/null
+++ b/Makefile-icon
@@ -0,0 +1,24 @@
+# To update the icon run make -f Makefile-icon
+# Requires:
+# autoconf, automake, libtool, pkg-config, pngquant
+
+ICONDIR=./Resources/Images.xcassets/AppIcon.appiconset
+OPTIMIZEDICONS=$(ICONDIR)/optimized_16x16.png $(ICONDIR)/optimized_32x32.png $(ICONDIR)/optimized_128x128.png $(ICONDIR)/optimized_512x512.png
+DESTICON=Resources/AppIcon.icns
+
+all: $(DESTICON)
+
+libicns:
+ git clone https://github.com/pornel/libicns.git
+
+libicns/Makefile: libicns
+ ( cd libicns && autoreconf -vif && ./configure )
+
+libicns/icnsutils/png2icns: libicns/Makefile
+ ( cd libicns && make -j8 )
+
+optimized_%.png: icon_%.png
+ pngquant -s1 -f -o $@ $<
+
+$(DESTICON): libicns/icnsutils/png2icns $(OPTIMIZEDICONS)
+ ./libicns/icnsutils/png2icns $@ $(OPTIMIZEDICONS)
diff --git a/README.markdown b/README.markdown
index 9df7c0aa..0e9ac10d 100644
--- a/README.markdown
+++ b/README.markdown
@@ -1,4 +1,4 @@
-# Sparkle [](https://travis-ci.org/sparkle-project/Sparkle) [](https://github.com/Carthage/Carthage) []()
+# Sparkle [](https://travis-ci.org/sparkle-project/Sparkle) [](https://github.com/Carthage/Carthage) []()
An easy-to-use software update framework for Cocoa developers.
@@ -54,4 +54,4 @@ We pledge to have an open and welcoming environment. See our [Code of Conduct](C
## Project Sponsor
-[MaxCDN](https://www.maxcdn.com/?utm_source=sparkle-github&utm_medium=link&utm_campaign=readme-footer)
+[StackPath](https://www.stackpath.com/?utm_source=sparkle-github&utm_medium=link&utm_campaign=readme-footer)
diff --git a/Resources/AppIcon.icns b/Resources/AppIcon.icns
new file mode 100644
index 00000000..7f2a571c
Binary files /dev/null and b/Resources/AppIcon.icns differ
diff --git a/Sparkle.xcodeproj/project.pbxproj b/Sparkle.xcodeproj/project.pbxproj
index 222d5366..861dad5b 100644
--- a/Sparkle.xcodeproj/project.pbxproj
+++ b/Sparkle.xcodeproj/project.pbxproj
@@ -26,7 +26,6 @@
/* Begin PBXBuildFile section */
1420DF50196247F900203BB0 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 1420DF4F196247F900203BB0 /* Images.xcassets */; };
- 1420DF51196247F900203BB0 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 1420DF4F196247F900203BB0 /* Images.xcassets */; };
142E0E0019A6954400E4312B /* Sparkle.framework in Copy Frameworks */ = {isa = PBXBuildFile; fileRef = 8DC2EF5B0486A6940098B216 /* Sparkle.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
142E0E0219A6A14700E4312B /* Sparkle.framework in Copy Files */ = {isa = PBXBuildFile; fileRef = 8DC2EF5B0486A6940098B216 /* Sparkle.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
142E0E0419A6A26F00E4312B /* Autoupdate.app in CopyFiles */ = {isa = PBXBuildFile; fileRef = 55C14BB7136EEF1500649790 /* Autoupdate.app */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; };
@@ -78,6 +77,7 @@
5AD0FA7F1C73F2E2004BCEFF /* testappcast.xml in Resources */ = {isa = PBXBuildFile; fileRef = 5AD0FA7E1C73F2E2004BCEFF /* testappcast.xml */; };
5AE459001C34118500E3BB47 /* SUUpdaterTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 14950074195FDF5900BC5B5B /* SUUpdaterTest.m */; };
5AE459021C34118500E3BB47 /* SUVersionComparisonTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 61227A150DB548B800AB99EA /* SUVersionComparisonTest.m */; };
+ 5AE7E1111DC81AD3009C2C12 /* AppIcon.icns in Resources */ = {isa = PBXBuildFile; fileRef = 5AE7E10E1DC81ACA009C2C12 /* AppIcon.icns */; };
5AF6C74F1AEA46D10014A3AB /* test.sparkle_guided.pkg in Resources */ = {isa = PBXBuildFile; fileRef = 5AF6C74E1AEA46D10014A3AB /* test.sparkle_guided.pkg */; };
5AF6C7541AEA49840014A3AB /* SUInstallerTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 5AF6C74C1AEA40760014A3AB /* SUInstallerTest.m */; };
5AF9DC3C1981DBEE001EA135 /* SUDSAVerifierTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 5AF9DC3B1981DBEE001EA135 /* SUDSAVerifierTest.m */; };
@@ -167,7 +167,6 @@
61F83F720DBFE140006FDD30 /* SUBasicUpdateDriver.m in Sources */ = {isa = PBXBuildFile; fileRef = 61F83F700DBFE137006FDD30 /* SUBasicUpdateDriver.m */; };
61F83F740DBFE141006FDD30 /* SUBasicUpdateDriver.h in Headers */ = {isa = PBXBuildFile; fileRef = 61F83F6F0DBFE137006FDD30 /* SUBasicUpdateDriver.h */; settings = {ATTRIBUTES = (); }; };
61FA52880E2D9EA400EF58AD /* Sparkle.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8DC2EF5B0486A6940098B216 /* Sparkle.framework */; settings = {ATTRIBUTES = (Required, ); }; };
- 720B16441C66433D006985FB /* UITests-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = 720B16421C66433D006985FB /* UITests-Info.plist */; };
720B16451C66433D006985FB /* SUTestApplicationTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 720B16431C66433D006985FB /* SUTestApplicationTest.swift */; };
7210C7681B9A9A1500EB90AC /* SUUnarchiverTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7210C7671B9A9A1500EB90AC /* SUUnarchiverTest.swift */; };
721BC2111D1DFF05002BC71E /* SUFileOperationConstants.m in Sources */ = {isa = PBXBuildFile; fileRef = 722954C31D04E66F00ECF9CA /* SUFileOperationConstants.m */; };
@@ -538,6 +537,7 @@
55E6F33219EC9F6C00005E76 /* SUErrors.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUErrors.h; sourceTree = ""; };
5AA4DCD01C73E5510078F128 /* SUAppcastTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SUAppcastTest.swift; sourceTree = ""; };
5AD0FA7E1C73F2E2004BCEFF /* testappcast.xml */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = testappcast.xml; sourceTree = ""; };
+ 5AE7E10E1DC81ACA009C2C12 /* AppIcon.icns */ = {isa = PBXFileReference; lastKnownFileType = image.icns; path = AppIcon.icns; sourceTree = ""; };
5AEF45D9189D1CC90030D7DC /* tr */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = tr; path = tr.lproj/Sparkle.strings; sourceTree = ""; };
5AF6C74C1AEA40760014A3AB /* SUInstallerTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SUInstallerTest.m; sourceTree = ""; };
5AF6C74E1AEA46D10014A3AB /* test.sparkle_guided.pkg */ = {isa = PBXFileReference; lastKnownFileType = file; path = test.sparkle_guided.pkg; sourceTree = ""; };
@@ -678,6 +678,9 @@
722954C21D04E66F00ECF9CA /* SUFileOperationConstants.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUFileOperationConstants.h; sourceTree = ""; };
722954C31D04E66F00ECF9CA /* SUFileOperationConstants.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SUFileOperationConstants.m; sourceTree = ""; };
722954C81D04E89500ECF9CA /* ConfigFileop.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = ConfigFileop.xcconfig; sourceTree = ""; };
+ 722FB7471DD51331001D40CE /* ConfigSwift.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = ConfigSwift.xcconfig; sourceTree = ""; };
+ 722FB7481DD51350001D40CE /* ConfigSwiftDebug.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = ConfigSwiftDebug.xcconfig; sourceTree = ""; };
+ 722FB7491DD51350001D40CE /* ConfigSwiftRelease.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = ConfigSwiftRelease.xcconfig; sourceTree = ""; };
723A920D1D722438004A9DED /* SUSpotlightImporterTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SUSpotlightImporterTest.swift; sourceTree = ""; };
723B252B1CEAB3A600909873 /* bscommon.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = bscommon.c; sourceTree = ""; };
723B252C1CEAB3A600909873 /* bscommon.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = bscommon.h; sourceTree = ""; };
@@ -925,6 +928,7 @@
1420DF4F196247F900203BB0 /* Images.xcassets */,
14732BBC1960EFB500593899 /* README.markdown */,
14732BB91960EEEE00593899 /* SampleAppcast.xml */,
+ 5AE7E10E1DC81ACA009C2C12 /* AppIcon.icns */,
615AE3CF0D64DC40001CA7BD /* SUModelTranslation.plist */,
);
path = Resources;
@@ -1221,6 +1225,9 @@
729F10FE1C65A9B500DFCCC5 /* ConfigUITestCoverage.xcconfig */,
729F10FF1C65A9B500DFCCC5 /* ConfigUITestDebug.xcconfig */,
729F11001C65A9B500DFCCC5 /* ConfigUITestRelease.xcconfig */,
+ 722FB7471DD51331001D40CE /* ConfigSwift.xcconfig */,
+ 722FB7481DD51350001D40CE /* ConfigSwiftDebug.xcconfig */,
+ 722FB7491DD51350001D40CE /* ConfigSwiftRelease.xcconfig */,
14732BC91960F70A00593899 /* make-release-package.sh */,
14652F7919A93E5F00959E44 /* set-git-version-info.sh */,
146EC84E19A68CF8004A50C5 /* Sparkle.podspec */,
@@ -1461,10 +1468,11 @@
attributes = {
CLASSPREFIX = SU;
LastSwiftUpdateCheck = 0720;
- LastUpgradeCheck = 0720;
+ LastUpgradeCheck = 0800;
ORGANIZATIONNAME = "Sparkle Project";
TargetAttributes = {
612279D80DB5470200AB99EA = {
+ LastSwiftMigration = 0800;
TestTargetID = 8DC2EF4F0486A6940098B216;
};
722954B31D04ADAF00ECF9CA = {
@@ -1472,6 +1480,7 @@
};
726B2B5C1C645FC900388755 = {
CreatedOnToolsVersion = 7.2.1;
+ LastSwiftMigration = 0800;
TestTargetID = 61B5F90109C4CEE200B25A18;
};
};
@@ -1572,7 +1581,7 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
- 1420DF51196247F900203BB0 /* Images.xcassets in Resources */,
+ 5AE7E1111DC81AD3009C2C12 /* AppIcon.icns in Resources */,
55C14FC7136F05E100649790 /* Sparkle.strings in Resources */,
55C14BD9136EF00C00649790 /* SUStatus.xib in Resources */,
);
@@ -1597,7 +1606,6 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
- 720B16441C66433D006985FB /* UITests-Info.plist in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -2312,9 +2320,6 @@
isa = XCBuildConfiguration;
baseConfigurationReference = 729F10FF1C65A9B500DFCCC5 /* ConfigUITestDebug.xcconfig */;
buildSettings = {
- CLANG_ENABLE_MODULES = YES;
- LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
- SWIFT_OPTIMIZATION_LEVEL = "-Onone";
};
name = Debug;
};
@@ -2322,9 +2327,6 @@
isa = XCBuildConfiguration;
baseConfigurationReference = 729F10FE1C65A9B500DFCCC5 /* ConfigUITestCoverage.xcconfig */;
buildSettings = {
- CLANG_ENABLE_MODULES = YES;
- LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
- SWIFT_OPTIMIZATION_LEVEL = "-Onone";
};
name = Coverage;
};
@@ -2332,8 +2334,6 @@
isa = XCBuildConfiguration;
baseConfigurationReference = 729F11001C65A9B500DFCCC5 /* ConfigUITestRelease.xcconfig */;
buildSettings = {
- CLANG_ENABLE_MODULES = YES;
- LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
};
name = Release;
};
diff --git a/Sparkle.xcodeproj/xcshareddata/xcschemes/Distribution.xcscheme b/Sparkle.xcodeproj/xcshareddata/xcschemes/Distribution.xcscheme
index 0ac6a3dc..328e2254 100644
--- a/Sparkle.xcodeproj/xcshareddata/xcschemes/Distribution.xcscheme
+++ b/Sparkle.xcodeproj/xcshareddata/xcschemes/Distribution.xcscheme
@@ -1,6 +1,6 @@
MainMenu
NSPrincipalClass
NSApplication
+ CFBundleIconFile
+ ${ASSETCATALOG_COMPILER_APPICON_NAME}.icns
diff --git a/Sparkle/SUStatus.xib b/Sparkle/SUStatus.xib
index fca3d15d..d225d6c2 100644
--- a/Sparkle/SUStatus.xib
+++ b/Sparkle/SUStatus.xib
@@ -10,6 +10,7 @@
+
diff --git a/Sparkle/SUStatusController.h b/Sparkle/SUStatusController.h
index 8a279258..03407c87 100644
--- a/Sparkle/SUStatusController.h
+++ b/Sparkle/SUStatusController.h
@@ -15,6 +15,7 @@
@interface SUStatusController : SUWindowController
@property (weak) IBOutlet NSButton *actionButton;
@property (weak) IBOutlet NSProgressIndicator *progressBar;
+@property (weak) IBOutlet NSTextField *statusTextField;
@property (copy) NSString *statusText;
@property double progressValue;
diff --git a/Sparkle/SUStatusController.m b/Sparkle/SUStatusController.m
index 290bfeae..23363248 100644
--- a/Sparkle/SUStatusController.m
+++ b/Sparkle/SUStatusController.m
@@ -11,6 +11,7 @@
#import "SUAppcast.h"
#import "SUAppcastItem.h"
#import "SUVersionComparisonProtocol.h"
+#import "SUOperatingSystem.h"
#import "SUStatusController.h"
#import "SUHost.h"
@@ -28,6 +29,7 @@
@synthesize host;
@synthesize actionButton;
@synthesize progressBar;
+@synthesize statusTextField;
- (instancetype)initWithHost:(SUHost *)aHost
{
@@ -51,6 +53,13 @@
[[self window] center];
[[self window] setFrameAutosaveName:@"SUStatusFrame"];
[self.progressBar setUsesThreadedAnimation:YES];
+
+ if ([SUOperatingSystem isOperatingSystemAtLeastVersion:(NSOperatingSystemVersion){10, 11, 0}]) {
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wpartial-availability"
+ [self.statusTextField setFont:[NSFont monospacedDigitSystemFontOfSize:0 weight:NSFontWeightRegular]];
+#pragma clang diagnostic pop
+ }
}
- (NSString *)windowTitle
diff --git a/Sparkle/SUUIBasedUpdateDriver.m b/Sparkle/SUUIBasedUpdateDriver.m
index ccf02fbd..0a0ae572 100644
--- a/Sparkle/SUUIBasedUpdateDriver.m
+++ b/Sparkle/SUUIBasedUpdateDriver.m
@@ -182,8 +182,9 @@
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wpartial-availability"
- return [NSByteCountFormatter stringFromByteCount:value
- countStyle:NSByteCountFormatterCountStyleFile];
+ NSByteCountFormatter *formatter = [[NSByteCountFormatter alloc] init];
+ [formatter setZeroPadsFractionDigits:YES];
+ return [formatter stringFromByteCount:value];
#pragma clang diagnostic pop
}
diff --git a/Sparkle/SUUpdater.h b/Sparkle/SUUpdater.h
index a64253ce..ac7600eb 100644
--- a/Sparkle/SUUpdater.h
+++ b/Sparkle/SUUpdater.h
@@ -32,62 +32,148 @@ SU_EXPORT @interface SUUpdater : NSObject
@property (unsafe_unretained) IBOutlet id delegate;
+/*!
+ The shared updater for the main bundle.
+
+ This is equivalent to passing [NSBundle mainBundle] to SUUpdater::updaterForBundle:
+ */
+ (SUUpdater *)sharedUpdater;
+
+/*!
+ The shared updater for a specified bundle.
+
+ If an updater has already been initialized for the provided bundle, that shared instance will be returned.
+ */
+ (SUUpdater *)updaterForBundle:(NSBundle *)bundle;
+
+/*!
+ Designated initializer for SUUpdater.
+
+ If an updater has already been initialized for the provided bundle, that shared instance will be returned.
+ */
- (instancetype)initForBundle:(NSBundle *)bundle;
-@property (readonly, strong) NSBundle *hostBundle;
-@property (strong, readonly) NSBundle *sparkleBundle;
-
-@property BOOL automaticallyChecksForUpdates;
-
-@property NSTimeInterval updateCheckInterval;
-
/*!
- * The URL of the appcast used to download update information.
- *
- * This property must be called on the main thread.
- */
-@property (copy) NSURL *feedURL;
+ Explicitly checks for updates and displays a progress dialog while doing so.
-@property (nonatomic, copy) NSString *userAgentString;
+ This method is meant for a main menu item.
+ Connect any menu item to this action in Interface Builder,
+ and Sparkle will check for updates and report back its findings verbosely
+ when it is invoked.
-@property (copy) NSDictionary *httpHeaders;
-
-@property BOOL sendsSystemProfile;
-
-@property BOOL automaticallyDownloadsUpdates;
-
-@property (nonatomic, copy) NSString *decryptionPassword;
-
-/*!
- Explicitly checks for updates and displays a progress dialog while doing so.
-
- This method is meant for a main menu item.
- Connect any menu item to this action in Interface Builder,
- and Sparkle will check for updates and report back its findings verbosely
- when it is invoked.
+ This will find updates that the user has opted into skipping.
*/
- (IBAction)checkForUpdates:(id)sender;
/*!
- The menu item validation used for the -checkForUpdates: action
+ The menu item validation used for the -checkForUpdates: action
*/
- (BOOL)validateMenuItem:(NSMenuItem *)menuItem;
/*!
- Checks for updates, but does not display any UI unless an update is found.
+ Checks for updates, but does not display any UI unless an update is found.
- This is meant for programmatically initating a check for updates. That is,
- it will display no UI unless it actually finds an update, in which case it
- proceeds as usual.
+ This is meant for programmatically initating a check for updates. That is,
+ it will display no UI unless it actually finds an update, in which case it
+ proceeds as usual.
- If the fully automated updating is turned on, however, this will invoke that
- behavior, and if an update is found, it will be downloaded and prepped for
- installation.
+ If automatic downloading of updates it turned on and allowed, however,
+ this will invoke that behavior, and if an update is found, it will be downloaded
+ in the background silently and will be prepped for installation.
+
+ This will not find updates that the user has opted into skipping.
*/
- (void)checkForUpdatesInBackground;
+/*!
+ A property indicating whether or not to check for updates automatically.
+
+ Setting this property will persist in the host bundle's user defaults.
+ The update schedule cycle will be reset in a short delay after the property's new value is set.
+ This is to allow reverting this property without kicking off a schedule change immediately
+ */
+@property BOOL automaticallyChecksForUpdates;
+
+/*!
+ A property indicating whether or not updates can be automatically downloaded in the background.
+
+ Note that automatic downloading of updates can be disallowed by the developer
+ or by the user's system if silent updates cannot be done (eg: if they require authentication).
+ In this case, -automaticallyDownloadsUpdates will return NO regardless of how this property is set.
+
+ Setting this property will persist in the host bundle's user defaults.
+ */
+@property BOOL automaticallyDownloadsUpdates;
+
+/*!
+ A property indicating the current automatic update check interval.
+
+ Setting this property will persist in the host bundle's user defaults.
+ The update schedule cycle will be reset in a short delay after the property's new value is set.
+ This is to allow reverting this property without kicking off a schedule change immediately
+ */
+@property NSTimeInterval updateCheckInterval;
+
+/*!
+ Begins a "probing" check for updates which will not actually offer to
+ update to that version.
+
+ However, the delegate methods
+ SUUpdaterDelegate::updater:didFindValidUpdate: and
+ SUUpdaterDelegate::updaterDidNotFindUpdate: will be called,
+ so you can use that information in your UI.
+
+ Updates that have been skipped by the user will not be found.
+ */
+- (void)checkForUpdateInformation;
+
+/*!
+ The URL of the appcast used to download update information.
+
+ Setting this property will persist in the host bundle's user defaults.
+ If you don't want persistence, you may want to consider instead implementing
+ SUUpdaterDelegate::feedURLStringForUpdater: or SUUpdaterDelegate::feedParametersForUpdater:sendingSystemProfile:
+
+ This property must be called on the main thread.
+ */
+@property (copy) NSURL *feedURL;
+
+/*!
+ The host bundle that is being updated.
+ */
+@property (readonly, strong) NSBundle *hostBundle;
+
+/*!
+ The bundle this class (SUUpdater) is loaded into.
+ */
+@property (strong, readonly) NSBundle *sparkleBundle;
+
+/*!
+ The user agent used when checking for updates.
+
+ The default implementation can be overrided.
+ */
+@property (nonatomic, copy) NSString *userAgentString;
+
+/*!
+ The HTTP headers used when checking for updates.
+
+ The keys of this dictionary are HTTP header fields (NSString) and values are corresponding values (NSString)
+ */
+@property (copy) NSDictionary *httpHeaders;
+
+/*!
+ A property indicating whether or not the user's system profile information is sent when checking for updates.
+
+ Setting this property will persist in the host bundle's user defaults.
+ */
+@property BOOL sendsSystemProfile;
+
+/*!
+ A property indicating the decryption password used for extracting updates shipped as Apple Disk Images (dmg)
+ */
+@property (nonatomic, copy) NSString *decryptionPassword;
+
/*!
Checks for updates and, if available, immediately downloads and installs them.
A progress dialog is shown but the user will never be prompted to read the
@@ -95,6 +181,9 @@ SU_EXPORT @interface SUUpdater : NSObject
You may want to respond to the userDidCancelDownload delegate method in case
the user clicks the "Cancel" button while the update is downloading.
+
+ If you are writing a UI-less background application, you probably want to instead use
+ SUUpdaterDelegate::updater:willInstallUpdateOnQuit:immediateInstallationInvocation:
*/
- (void)installUpdatesIfAvailable;
@@ -105,17 +194,6 @@ SU_EXPORT @interface SUUpdater : NSObject
*/
@property (readonly, copy) NSDate *lastUpdateCheckDate;
-/*!
- Begins a "probing" check for updates which will not actually offer to
- update to that version.
-
- However, the delegate methods
- SUUpdaterDelegate::updater:didFindValidUpdate: and
- SUUpdaterDelegate::updaterDidNotFindUpdate: will be called,
- so you can use that information in your UI.
- */
-- (void)checkForUpdateInformation;
-
/*!
Appropriately schedules or cancels the update checking timer according to
the preferences for time interval and automatic checks.
@@ -125,6 +203,12 @@ SU_EXPORT @interface SUUpdater : NSObject
*/
- (void)resetUpdateCycle;
+/*!
+ A property indicating whether or not an update is in progress.
+
+ Note this property is not indicative of whether or not user initiated updates can be performed.
+ Use SUUpdater::validateMenuItem: for that instead.
+ */
@property (readonly) BOOL updateInProgress;
@end
@@ -181,6 +265,9 @@ SU_EXPORT extern NSString *const SUUpdaterAppcastNotificationKey;
Override this to dynamically specify the entire URL.
+ An alternative may be to use SUUpdaterDelegate::feedParametersForUpdater:sendingSystemProfile:
+ and let the server handle what kind of feed to provide.
+
\param updater The SUUpdater instance.
*/
- (NSString *)feedURLStringForUpdater:(SUUpdater *)updater;
@@ -347,6 +434,8 @@ SU_EXPORT extern NSString *const SUUpdaterAppcastNotificationKey;
/*!
Called when an update is scheduled to be silently installed on quit.
+ This is after an update has been automatically downloaded in the background.
+ (i.e. SUUpdater::automaticallyDownloadsUpdates is YES)
\param updater The SUUpdater instance.
\param item The appcast item corresponding to the update that is proposed to be installed.
diff --git a/Sparkle/SUUpdater.m b/Sparkle/SUUpdater.m
index 8be9ac3b..9a0a0d5a 100644
--- a/Sparkle/SUUpdater.m
+++ b/Sparkle/SUUpdater.m
@@ -59,6 +59,15 @@ NSString *const SUUpdaterAppcastNotificationKey = @"SUUpdaterAppCastNotification
static NSMutableDictionary *sharedUpdaters = nil;
static NSString *const SUUpdaterDefaultsObservationContext = @"SUUpdaterDefaultsObservationContext";
+#ifdef DEBUG
++ (void)load
+{
+ // Debug builds have different configurations for update check intervals
+ // We're using NSLog instead of SULog here because we don't want to start Sparkle's logger here
+ NSLog(@"WARNING: This is running a Debug build of Sparkle; don't use this in production!");
+}
+#endif
+
+ (SUUpdater *)sharedUpdater
{
return [self updaterForBundle:[NSBundle mainBundle]];
diff --git a/Tests/SUAppcastTest.swift b/Tests/SUAppcastTest.swift
index 113ce751..c5250a60 100644
--- a/Tests/SUAppcastTest.swift
+++ b/Tests/SUAppcastTest.swift
@@ -13,12 +13,12 @@ class SUAppcastTest: XCTestCase {
func testParseAppcast() {
let appcast = SUAppcast();
- let testFile = NSBundle(forClass: SUAppcastTest.self).pathForResource("testappcast", ofType: "xml")!;
- let testFileUrl = NSURL(fileURLWithPath: testFile);
+ let testFile = Bundle(for: SUAppcastTest.self).path(forResource: "testappcast", ofType: "xml")!;
+ let testFileUrl = URL(fileURLWithPath: testFile);
XCTAssertNotNil(testFileUrl);
do {
- let items = try appcast.parseAppcastItemsFromXMLFile(testFileUrl) as! [SUAppcastItem];
+ let items = try appcast.parseAppcastItems(fromXMLFile: testFileUrl) as! [SUAppcastItem];
XCTAssertEqual(4, items.count);
@@ -41,20 +41,20 @@ class SUAppcastTest: XCTestCase {
// Test best appcast item & a delta update item
var deltaItem: SUAppcastItem? = nil
- let bestAppcastItem = SUBasicUpdateDriver.bestItemFromAppcastItems(items, getDeltaItem: &deltaItem, withHostVersion: "1.0", comparator: SUStandardVersionComparator.defaultComparator())
+ let bestAppcastItem = SUBasicUpdateDriver.bestItem(fromAppcastItems: items, getDeltaItem: &deltaItem, withHostVersion: "1.0", comparator: SUStandardVersionComparator.default())
XCTAssertEqual(bestAppcastItem, items[1])
XCTAssertEqual(deltaItem!.fileURL.lastPathComponent, "3.0_from_1.0.patch")
// Test latest delta update item available
var latestDeltaItem: SUAppcastItem? = nil
- SUBasicUpdateDriver.bestItemFromAppcastItems(items, getDeltaItem: &latestDeltaItem, withHostVersion: "2.0", comparator: SUStandardVersionComparator.defaultComparator())
+ SUBasicUpdateDriver.bestItem(fromAppcastItems: items, getDeltaItem: &latestDeltaItem, withHostVersion: "2.0", comparator: SUStandardVersionComparator.default())
XCTAssertEqual(latestDeltaItem!.fileURL.lastPathComponent, "3.0_from_2.0.patch")
// Test a delta item that does not exist
var nonexistantDeltaItem: SUAppcastItem? = nil
- SUBasicUpdateDriver.bestItemFromAppcastItems(items, getDeltaItem: &nonexistantDeltaItem, withHostVersion: "2.1", comparator: SUStandardVersionComparator.defaultComparator())
+ SUBasicUpdateDriver.bestItem(fromAppcastItems: items, getDeltaItem: &nonexistantDeltaItem, withHostVersion: "2.1", comparator: SUStandardVersionComparator.default())
XCTAssertNil(nonexistantDeltaItem)
} catch let err as NSError {
@@ -65,12 +65,12 @@ class SUAppcastTest: XCTestCase {
func testNamespaces() {
let appcast = SUAppcast();
- let testFile = NSBundle(forClass: SUAppcastTest.self).pathForResource("testnamespaces", ofType: "xml")!;
- let testFileUrl = NSURL(fileURLWithPath: testFile);
+ let testFile = Bundle(for: SUAppcastTest.self).path(forResource: "testnamespaces", ofType: "xml")!;
+ let testFileUrl = URL(fileURLWithPath: testFile);
XCTAssertNotNil(testFileUrl);
do {
- let items = try appcast.parseAppcastItemsFromXMLFile(testFileUrl) as! [SUAppcastItem];
+ let items = try appcast.parseAppcastItems(fromXMLFile: testFileUrl) as! [SUAppcastItem];
XCTAssertEqual(2, items.count);
diff --git a/Tests/SUFileManagerTest.swift b/Tests/SUFileManagerTest.swift
index bfb6a41f..fe5cd6d7 100644
--- a/Tests/SUFileManagerTest.swift
+++ b/Tests/SUFileManagerTest.swift
@@ -10,180 +10,180 @@ import XCTest
class SUFileManagerTest: XCTestCase
{
- func makeTempFiles(testBlock: (SUFileManager, NSURL, NSURL, NSURL, NSURL, NSURL, NSURL) -> Void)
+ func makeTempFiles(_ testBlock: (SUFileManager, URL, URL, URL, URL, URL, URL) -> Void)
{
- let fileManager = SUFileManager.defaultManager()
+ let fileManager = SUFileManager.default()
- let tempDirectoryURL = try! fileManager.makeTemporaryDirectoryWithPreferredName("Sparkle Unit Test Data", appropriateForDirectoryURL: NSURL(fileURLWithPath: NSHomeDirectory()))
+ let tempDirectoryURL = try! fileManager?.makeTemporaryDirectory(withPreferredName: "Sparkle Unit Test Data", appropriateForDirectoryURL: URL(fileURLWithPath: NSHomeDirectory()))
defer {
- try! fileManager.removeItemAtURL(tempDirectoryURL)
+ try! fileManager?.removeItem(at: tempDirectoryURL)
}
- let ordinaryFileURL = tempDirectoryURL.URLByAppendingPathComponent("a file written by sparkles unit tests")
- try! "foo".dataUsingEncoding(NSUTF8StringEncoding)!.writeToURL(ordinaryFileURL, options: .DataWritingAtomic)
+ 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.URLByAppendingPathComponent("a directory written by sparkles unit tests")
- try! NSFileManager.defaultManager().createDirectoryAtURL(directoryURL, withIntermediateDirectories: false, attributes: nil)
+ let directoryURL = tempDirectoryURL?.appendingPathComponent("a directory written by sparkles unit tests")
+ try! FileManager.default.createDirectory(at: directoryURL!, withIntermediateDirectories: false, attributes: nil)
- let fileInDirectoryURL = directoryURL.URLByAppendingPathComponent("a file inside a directory written by sparkles unit tests")
- try! "bar baz".dataUsingEncoding(NSUTF8StringEncoding)!.writeToURL(fileInDirectoryURL, options: .DataWritingAtomic)
+ 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.URLByAppendingPathComponent("symlink test")
- try! NSFileManager.defaultManager().createSymbolicLinkAtURL(validSymlinkURL, withDestinationURL: directoryURL)
+ let validSymlinkURL = tempDirectoryURL?.appendingPathComponent("symlink test")
+ try! FileManager.default.createSymbolicLink(at: validSymlinkURL!, withDestinationURL: directoryURL!)
- let invalidSymlinkURL = tempDirectoryURL.URLByAppendingPathComponent("symlink test 2")
- try! NSFileManager.defaultManager().createSymbolicLinkAtURL(invalidSymlinkURL, withDestinationURL: tempDirectoryURL.URLByAppendingPathComponent("does not exist"))
+ 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)
+ testBlock(fileManager!, tempDirectoryURL!, ordinaryFileURL!, directoryURL!, fileInDirectoryURL!, validSymlinkURL!, invalidSymlinkURL!)
}
func testMoveFiles()
{
makeTempFiles() { fileManager, rootURL, ordinaryFileURL, directoryURL, fileInDirectoryURL, validSymlinkURL, invalidSymlinkURL in
- XCTAssertNil(try? fileManager.moveItemAtURL(ordinaryFileURL, toURL: directoryURL))
- XCTAssertNil(try? fileManager.moveItemAtURL(ordinaryFileURL, toURL: directoryURL.URLByAppendingPathComponent("foo").URLByAppendingPathComponent("bar")))
- XCTAssertNil(try? fileManager.moveItemAtURL(rootURL.URLByAppendingPathComponent("does not exist"), toURL: directoryURL))
+ 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.URLByDeletingLastPathComponent?.URLByAppendingPathComponent("new file"))!
- try! fileManager.moveItemAtURL(ordinaryFileURL, toURL: newFileURL)
- XCTAssertFalse(fileManager._itemExistsAtURL(ordinaryFileURL))
- XCTAssertTrue(fileManager._itemExistsAtURL(newFileURL))
+ 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.URLByDeletingLastPathComponent?.URLByAppendingPathComponent("new symlink"))!
- try! fileManager.moveItemAtURL(validSymlinkURL, toURL: newValidSymlinkURL)
- XCTAssertFalse(fileManager._itemExistsAtURL(validSymlinkURL))
- XCTAssertTrue(fileManager._itemExistsAtURL(newValidSymlinkURL))
- XCTAssertTrue(fileManager._itemExistsAtURL(directoryURL))
+ 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.URLByDeletingLastPathComponent?.URLByAppendingPathComponent("new invalid symlink"))!
- try! fileManager.moveItemAtURL(invalidSymlinkURL, toURL: newInvalidSymlinkURL)
- XCTAssertFalse(fileManager._itemExistsAtURL(invalidSymlinkURL))
- XCTAssertTrue(fileManager._itemExistsAtURL(newValidSymlinkURL))
+ 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.URLByDeletingLastPathComponent?.URLByAppendingPathComponent("new directory"))!
- try! fileManager.moveItemAtURL(directoryURL, toURL: newDirectoryURL)
- XCTAssertFalse(fileManager._itemExistsAtURL(directoryURL))
- XCTAssertTrue(fileManager._itemExistsAtURL(newDirectoryURL))
- XCTAssertFalse(fileManager._itemExistsAtURL(fileInDirectoryURL))
- XCTAssertTrue(fileManager._itemExistsAtURL(newDirectoryURL.URLByAppendingPathComponent(fileInDirectoryURL.lastPathComponent!)))
+ let newDirectoryURL = (ordinaryFileURL.deletingLastPathComponent().appendingPathComponent("new directory"))
+ try! fileManager.moveItem(at: directoryURL, to: newDirectoryURL)
+ XCTAssertFalse(fileManager._itemExists(at: directoryURL))
+ XCTAssertTrue(fileManager._itemExists(at: newDirectoryURL))
+ XCTAssertFalse(fileManager._itemExists(at: fileInDirectoryURL))
+ XCTAssertTrue(fileManager._itemExists(at: newDirectoryURL.appendingPathComponent(fileInDirectoryURL.lastPathComponent)))
}
}
func testMoveFilesToTrash()
{
makeTempFiles() { fileManager, rootURL, ordinaryFileURL, directoryURL, fileInDirectoryURL, validSymlinkURL, invalidSymlinkURL in
- XCTAssertNil(try? fileManager.moveItemAtURLToTrash(rootURL.URLByAppendingPathComponent("does not exist")))
+ XCTAssertNil(try? fileManager.moveItemAtURL(toTrash: rootURL.appendingPathComponent("does not exist")))
- let trashURL = try! NSFileManager.defaultManager().URLForDirectory(.TrashDirectory, inDomain: .UserDomainMask, appropriateForURL: nil, create: false)
+ let trashURL = try! FileManager.default.url(for: .trashDirectory, in: .userDomainMask, appropriateFor: nil, create: false)
- try! fileManager.moveItemAtURLToTrash(ordinaryFileURL)
- XCTAssertFalse(fileManager._itemExistsAtURL(ordinaryFileURL))
+ try! fileManager.moveItemAtURL(toTrash: ordinaryFileURL)
+ XCTAssertFalse(fileManager._itemExists(at: ordinaryFileURL))
- let ordinaryFileTrashURL = trashURL.URLByAppendingPathComponent(ordinaryFileURL.lastPathComponent!)
- XCTAssertTrue(fileManager._itemExistsAtURL(ordinaryFileTrashURL))
- try! fileManager.removeItemAtURL(ordinaryFileTrashURL)
+ let ordinaryFileTrashURL = trashURL.appendingPathComponent(ordinaryFileURL.lastPathComponent)
+ XCTAssertTrue(fileManager._itemExists(at: ordinaryFileTrashURL))
+ try! fileManager.removeItem(at: ordinaryFileTrashURL)
- let validSymlinkTrashURL = trashURL.URLByAppendingPathComponent(validSymlinkURL.lastPathComponent!)
- try! fileManager.moveItemAtURLToTrash(validSymlinkURL)
- XCTAssertTrue(fileManager._itemExistsAtURL(validSymlinkTrashURL))
- XCTAssertTrue(fileManager._itemExistsAtURL(directoryURL))
- try! fileManager.removeItemAtURL(validSymlinkTrashURL)
+ let validSymlinkTrashURL = trashURL.appendingPathComponent(validSymlinkURL.lastPathComponent)
+ try! fileManager.moveItemAtURL(toTrash: validSymlinkURL)
+ XCTAssertTrue(fileManager._itemExists(at: validSymlinkTrashURL))
+ XCTAssertTrue(fileManager._itemExists(at: directoryURL))
+ try! fileManager.removeItem(at: validSymlinkTrashURL)
- try! fileManager.moveItemAtURLToTrash(directoryURL)
- XCTAssertFalse(fileManager._itemExistsAtURL(directoryURL))
- XCTAssertFalse(fileManager._itemExistsAtURL(fileInDirectoryURL))
+ try! fileManager.moveItemAtURL(toTrash: directoryURL)
+ XCTAssertFalse(fileManager._itemExists(at: directoryURL))
+ XCTAssertFalse(fileManager._itemExists(at: fileInDirectoryURL))
- let directoryTrashURL = trashURL.URLByAppendingPathComponent(directoryURL.lastPathComponent!)
- XCTAssertTrue(fileManager._itemExistsAtURL(directoryTrashURL))
- XCTAssertTrue(fileManager._itemExistsAtURL(directoryTrashURL.URLByAppendingPathComponent(fileInDirectoryURL.lastPathComponent!)))
+ let directoryTrashURL = trashURL.appendingPathComponent(directoryURL.lastPathComponent)
+ XCTAssertTrue(fileManager._itemExists(at: directoryTrashURL))
+ XCTAssertTrue(fileManager._itemExists(at: directoryTrashURL.appendingPathComponent(fileInDirectoryURL.lastPathComponent)))
- try! fileManager.removeItemAtURL(directoryTrashURL)
+ try! fileManager.removeItem(at: directoryTrashURL)
}
}
func testCopyFiles()
{
makeTempFiles() { fileManager, rootURL, ordinaryFileURL, directoryURL, fileInDirectoryURL, validSymlinkURL, invalidSymlinkURL in
- XCTAssertNil(try? fileManager.copyItemAtURL(ordinaryFileURL, toURL: directoryURL))
- XCTAssertNil(try? fileManager.copyItemAtURL(ordinaryFileURL, toURL: directoryURL.URLByAppendingPathComponent("foo").URLByAppendingPathComponent("bar")))
- XCTAssertNil(try? fileManager.copyItemAtURL(rootURL.URLByAppendingPathComponent("does not exist"), toURL: directoryURL))
+ 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.URLByDeletingLastPathComponent?.URLByAppendingPathComponent("new file"))!
- try! fileManager.copyItemAtURL(ordinaryFileURL, toURL: newFileURL)
- XCTAssertTrue(fileManager._itemExistsAtURL(ordinaryFileURL))
- XCTAssertTrue(fileManager._itemExistsAtURL(newFileURL))
+ 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.URLByDeletingLastPathComponent?.URLByAppendingPathComponent("new symlink file"))!
- try! fileManager.copyItemAtURL(invalidSymlinkURL, toURL: newSymlinkURL)
- XCTAssertTrue(fileManager._itemExistsAtURL(newSymlinkURL))
+ let newSymlinkURL = (ordinaryFileURL.deletingLastPathComponent().appendingPathComponent("new symlink file"))
+ try! fileManager.copyItem(at: invalidSymlinkURL, to: newSymlinkURL)
+ XCTAssertTrue(fileManager._itemExists(at: newSymlinkURL))
- let newDirectoryURL = (ordinaryFileURL.URLByDeletingLastPathComponent?.URLByAppendingPathComponent("new directory"))!
- try! fileManager.copyItemAtURL(directoryURL, toURL: newDirectoryURL)
- XCTAssertTrue(fileManager._itemExistsAtURL(directoryURL))
- XCTAssertTrue(fileManager._itemExistsAtURL(newDirectoryURL))
- XCTAssertTrue(fileManager._itemExistsAtURL(fileInDirectoryURL))
- XCTAssertTrue(fileManager._itemExistsAtURL(newDirectoryURL.URLByAppendingPathComponent(fileInDirectoryURL.lastPathComponent!)))
+ let newDirectoryURL = (ordinaryFileURL.deletingLastPathComponent().appendingPathComponent("new directory"))
+ try! fileManager.copyItem(at: directoryURL, to: newDirectoryURL)
+ XCTAssertTrue(fileManager._itemExists(at: directoryURL))
+ XCTAssertTrue(fileManager._itemExists(at: newDirectoryURL))
+ XCTAssertTrue(fileManager._itemExists(at: fileInDirectoryURL))
+ XCTAssertTrue(fileManager._itemExists(at: newDirectoryURL.appendingPathComponent(fileInDirectoryURL.lastPathComponent)))
}
}
func testRemoveFiles()
{
makeTempFiles() { fileManager, rootURL, ordinaryFileURL, directoryURL, fileInDirectoryURL, validSymlinkURL, invalidSymlinkURL in
- XCTAssertNil(try? fileManager.removeItemAtURL(rootURL.URLByAppendingPathComponent("does not exist")))
+ XCTAssertNil(try? fileManager.removeItem(at: rootURL.appendingPathComponent("does not exist")))
- try! fileManager.removeItemAtURL(ordinaryFileURL)
- XCTAssertFalse(fileManager._itemExistsAtURL(ordinaryFileURL))
+ try! fileManager.removeItem(at: ordinaryFileURL)
+ XCTAssertFalse(fileManager._itemExists(at: ordinaryFileURL))
- try! fileManager.removeItemAtURL(validSymlinkURL)
- XCTAssertFalse(fileManager._itemExistsAtURL(validSymlinkURL))
- XCTAssertTrue(fileManager._itemExistsAtURL(directoryURL))
+ try! fileManager.removeItem(at: validSymlinkURL)
+ XCTAssertFalse(fileManager._itemExists(at: validSymlinkURL))
+ XCTAssertTrue(fileManager._itemExists(at: directoryURL))
- try! fileManager.removeItemAtURL(directoryURL)
- XCTAssertFalse(fileManager._itemExistsAtURL(directoryURL))
- XCTAssertFalse(fileManager._itemExistsAtURL(fileInDirectoryURL))
+ 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
- try! fileManager.releaseItemFromQuarantineAtRootURL(ordinaryFileURL)
- try! fileManager.releaseItemFromQuarantineAtRootURL(directoryURL)
- try! fileManager.releaseItemFromQuarantineAtRootURL(validSymlinkURL)
+ try! fileManager.releaseItemFromQuarantine(atRootURL: ordinaryFileURL)
+ try! fileManager.releaseItemFromQuarantine(atRootURL: directoryURL)
+ try! fileManager.releaseItemFromQuarantine(atRootURL: validSymlinkURL)
- let quarantineData = "does not really matter what is here".cStringUsingEncoding(NSUTF8StringEncoding)!
+ 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)
+ XCTAssertEqual(0, setxattr(ordinaryFileURL.path, SUAppleQuarantineIdentifier, quarantineData, quarantineDataLength, 0, XATTR_CREATE))
+ XCTAssertGreaterThan(getxattr(ordinaryFileURL.path, SUAppleQuarantineIdentifier, nil, 0, 0, XATTR_NOFOLLOW), 0)
- try! fileManager.releaseItemFromQuarantineAtRootURL(ordinaryFileURL)
- XCTAssertEqual(-1, getxattr(ordinaryFileURL.path!, SUAppleQuarantineIdentifier, nil, 0, 0, XATTR_NOFOLLOW))
+ 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(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)
+ 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.releaseItemFromQuarantineAtRootURL(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: 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.releaseItemFromQuarantineAtRootURL(directoryURL)
+ 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))
+ 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
+ func groupIDAtPath(_ path: String) -> gid_t
{
- let attributes = try! NSFileManager.defaultManager().attributesOfItemAtPath(path)
- let groupID = attributes[NSFileGroupOwnerAccountID] as! NSNumber
- return groupID.unsignedIntValue
+ 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
@@ -191,126 +191,126 @@ class SUFileManagerTest: XCTestCase
func testAlterFilesGroupID()
{
makeTempFiles() { fileManager, rootURL, ordinaryFileURL, directoryURL, fileInDirectoryURL, validSymlinkURL, invalidSymlinkURL in
- XCTAssertNil(try? fileManager.changeOwnerAndGroupOfItemAtRootURL(ordinaryFileURL, toMatchURL: rootURL.URLByAppendingPathComponent("does not exist")))
+ XCTAssertNil(try? fileManager.changeOwnerAndGroupOfItem(atRootURL: ordinaryFileURL, toMatch: rootURL.appendingPathComponent("does not exist")))
- XCTAssertNil(try? fileManager.changeOwnerAndGroupOfItemAtRootURL(rootURL.URLByAppendingPathComponent("does not exist"), toMatchURL: ordinaryFileURL))
+ XCTAssertNil(try? fileManager.changeOwnerAndGroupOfItem(atRootURL: rootURL.appendingPathComponent("does not exist"), toMatch: ordinaryFileURL))
let everyoneGroup = getgrnam("everyone")
- let everyoneGroupID = everyoneGroup.memory.gr_gid
+ let everyoneGroupID = everyoneGroup?.pointee.gr_gid
let staffGroup = getgrnam("staff")
- let staffGroupID = staffGroup.memory.gr_gid
+ 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!))
- XCTAssertEqual(staffGroupID, self.groupIDAtPath(validSymlinkURL.path!))
+ XCTAssertEqual(staffGroupID, self.groupIDAtPath(ordinaryFileURL.path))
+ XCTAssertEqual(staffGroupID, self.groupIDAtPath(directoryURL.path))
+ XCTAssertEqual(staffGroupID, self.groupIDAtPath(fileInDirectoryURL.path))
+ XCTAssertEqual(staffGroupID, self.groupIDAtPath(validSymlinkURL.path))
- try! fileManager.changeOwnerAndGroupOfItemAtRootURL(fileInDirectoryURL, toMatchURL: ordinaryFileURL)
- try! fileManager.changeOwnerAndGroupOfItemAtRootURL(ordinaryFileURL, toMatchURL: ordinaryFileURL)
- try! fileManager.changeOwnerAndGroupOfItemAtRootURL(validSymlinkURL, toMatchURL: ordinaryFileURL)
+ 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(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!))
+ XCTAssertEqual(0, chown(ordinaryFileURL.path, getuid(), everyoneGroupID!))
+ XCTAssertEqual(everyoneGroupID, self.groupIDAtPath(ordinaryFileURL.path))
- try! fileManager.changeOwnerAndGroupOfItemAtRootURL(fileInDirectoryURL, toMatchURL: ordinaryFileURL)
- XCTAssertEqual(everyoneGroupID, self.groupIDAtPath(fileInDirectoryURL.path!))
+ try! fileManager.changeOwnerAndGroupOfItem(atRootURL: fileInDirectoryURL, toMatch: ordinaryFileURL)
+ XCTAssertEqual(everyoneGroupID, self.groupIDAtPath(fileInDirectoryURL.path))
- try! fileManager.changeOwnerAndGroupOfItemAtRootURL(fileInDirectoryURL, toMatchURL: directoryURL)
- XCTAssertEqual(staffGroupID, self.groupIDAtPath(fileInDirectoryURL.path!))
+ try! fileManager.changeOwnerAndGroupOfItem(atRootURL: fileInDirectoryURL, toMatch: directoryURL)
+ XCTAssertEqual(staffGroupID, self.groupIDAtPath(fileInDirectoryURL.path))
- try! fileManager.changeOwnerAndGroupOfItemAtRootURL(validSymlinkURL, toMatchURL: ordinaryFileURL)
- XCTAssertEqual(everyoneGroupID, self.groupIDAtPath(validSymlinkURL.path!))
+ try! fileManager.changeOwnerAndGroupOfItem(atRootURL: validSymlinkURL, toMatch: ordinaryFileURL)
+ XCTAssertEqual(everyoneGroupID, self.groupIDAtPath(validSymlinkURL.path))
- try! fileManager.changeOwnerAndGroupOfItemAtRootURL(directoryURL, toMatchURL: ordinaryFileURL)
- XCTAssertEqual(everyoneGroupID, self.groupIDAtPath(directoryURL.path!))
- XCTAssertEqual(everyoneGroupID, self.groupIDAtPath(fileInDirectoryURL.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
- XCTAssertNil(try? fileManager.updateModificationAndAccessTimeOfItemAtURL(rootURL.URLByAppendingPathComponent("does not exist")))
+ XCTAssertNil(try? fileManager.updateModificationAndAccessTimeOfItem(at: rootURL.appendingPathComponent("does not exist")))
- let oldOrdinaryFileAttributes = try! NSFileManager.defaultManager().attributesOfItemAtPath(ordinaryFileURL.path!)
- let oldDirectoryAttributes = try! NSFileManager.defaultManager().attributesOfItemAtPath(directoryURL.path!)
- let oldValidSymlinkAttributes = try! NSFileManager.defaultManager().attributesOfItemAtPath(validSymlinkURL.path!)
+ 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.updateModificationAndAccessTimeOfItemAtURL(ordinaryFileURL)
- try! fileManager.updateModificationAndAccessTimeOfItemAtURL(directoryURL)
- try! fileManager.updateModificationAndAccessTimeOfItemAtURL(validSymlinkURL)
+ try! fileManager.updateModificationAndAccessTimeOfItem(at: ordinaryFileURL)
+ try! fileManager.updateModificationAndAccessTimeOfItem(at: directoryURL)
+ try! fileManager.updateModificationAndAccessTimeOfItem(at: validSymlinkURL)
- let newOrdinaryFileAttributes = try! NSFileManager.defaultManager().attributesOfItemAtPath(ordinaryFileURL.path!)
- XCTAssertGreaterThan((newOrdinaryFileAttributes[NSFileModificationDate] as! NSDate).timeIntervalSinceDate(oldOrdinaryFileAttributes[NSFileModificationDate] as! NSDate), 0)
+ 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! NSFileManager.defaultManager().attributesOfItemAtPath(directoryURL.path!)
- XCTAssertGreaterThan((newDirectoryAttributes[NSFileModificationDate] as! NSDate).timeIntervalSinceDate(oldDirectoryAttributes[NSFileModificationDate] as! NSDate), 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! NSFileManager.defaultManager().attributesOfItemAtPath(validSymlinkURL.path!)
- XCTAssertGreaterThan((newSymlinkAttributes[NSFileModificationDate] as! NSDate).timeIntervalSinceDate(oldValidSymlinkAttributes[NSFileModificationDate] as! NSDate), 0)
+ let newSymlinkAttributes = try! FileManager.default.attributesOfItem(atPath: validSymlinkURL.path)
+ XCTAssertGreaterThan((newSymlinkAttributes[FileAttributeKey.modificationDate] as! Date).timeIntervalSince(oldValidSymlinkAttributes[FileAttributeKey.modificationDate] as! Date), 0)
}
}
func testFileExists()
{
makeTempFiles() { fileManager, rootURL, ordinaryFileURL, directoryURL, fileInDirectoryURL, validSymlinkURL, invalidSymlinkURL in
- XCTAssertTrue(fileManager._itemExistsAtURL(ordinaryFileURL))
- XCTAssertTrue(fileManager._itemExistsAtURL(directoryURL))
- XCTAssertFalse(fileManager._itemExistsAtURL(rootURL.URLByAppendingPathComponent("does not exist")))
+ 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._itemExistsAtURL(ordinaryFileURL, isDirectory: &isOrdinaryFileDirectory) && !isOrdinaryFileDirectory)
+ XCTAssertTrue(fileManager._itemExists(at: ordinaryFileURL, isDirectory: &isOrdinaryFileDirectory) && !isOrdinaryFileDirectory.boolValue)
var isDirectoryADirectory: ObjCBool = false
- XCTAssertTrue(fileManager._itemExistsAtURL(directoryURL, isDirectory: &isDirectoryADirectory) && isDirectoryADirectory)
+ XCTAssertTrue(fileManager._itemExists(at: directoryURL, isDirectory: &isDirectoryADirectory) && isDirectoryADirectory.boolValue)
- XCTAssertFalse(fileManager._itemExistsAtURL(rootURL.URLByAppendingPathComponent("does not exist"), isDirectory: nil))
+ XCTAssertFalse(fileManager._itemExists(at: rootURL.appendingPathComponent("does not exist"), isDirectory: nil))
- XCTAssertTrue(fileManager._itemExistsAtURL(validSymlinkURL))
+ XCTAssertTrue(fileManager._itemExists(at: validSymlinkURL))
var validSymlinkIsADirectory: ObjCBool = false
- XCTAssertTrue(fileManager._itemExistsAtURL(validSymlinkURL, isDirectory: &validSymlinkIsADirectory) && !validSymlinkIsADirectory)
+ 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._itemExistsAtURL(invalidSymlinkURL))
+ XCTAssertTrue(fileManager._itemExists(at: invalidSymlinkURL))
var invalidSymlinkIsADirectory: ObjCBool = false
- XCTAssertTrue(fileManager._itemExistsAtURL(invalidSymlinkURL, isDirectory: &invalidSymlinkIsADirectory) && !invalidSymlinkIsADirectory)
+ XCTAssertTrue(fileManager._itemExists(at: invalidSymlinkURL, isDirectory: &invalidSymlinkIsADirectory) && !invalidSymlinkIsADirectory.boolValue)
}
}
func testMakeDirectory()
{
makeTempFiles() { fileManager, rootURL, ordinaryFileURL, directoryURL, fileInDirectoryURL, validSymlinkURL, invalidSymlinkURL in
- XCTAssertNil(try? fileManager.makeDirectoryAtURL(ordinaryFileURL))
- XCTAssertNil(try? fileManager.makeDirectoryAtURL(directoryURL))
+ XCTAssertNil(try? fileManager.makeDirectory(at: ordinaryFileURL))
+ XCTAssertNil(try? fileManager.makeDirectory(at: directoryURL))
- XCTAssertNil(try? fileManager.makeDirectoryAtURL(rootURL.URLByAppendingPathComponent("this should").URLByAppendingPathComponent("be a failure")))
+ XCTAssertNil(try? fileManager.makeDirectory(at: rootURL.appendingPathComponent("this should").appendingPathComponent("be a failure")))
- let newDirectoryURL = rootURL.URLByAppendingPathComponent("new test directory")
- XCTAssertFalse(fileManager._itemExistsAtURL(newDirectoryURL))
- try! fileManager.makeDirectoryAtURL(newDirectoryURL)
+ let newDirectoryURL = rootURL.appendingPathComponent("new test directory")
+ XCTAssertFalse(fileManager._itemExists(at: newDirectoryURL))
+ try! fileManager.makeDirectory(at: newDirectoryURL)
var isDirectory: ObjCBool = false
- XCTAssertTrue(fileManager._itemExistsAtURL(newDirectoryURL, isDirectory: &isDirectory))
+ XCTAssertTrue(fileManager._itemExists(at: newDirectoryURL, isDirectory: &isDirectory))
- try! fileManager.removeItemAtURL(directoryURL)
- XCTAssertNil(try? fileManager.makeDirectoryAtURL(validSymlinkURL))
+ try! fileManager.removeItem(at: directoryURL)
+ XCTAssertNil(try? fileManager.makeDirectory(at: validSymlinkURL))
}
}
func testAcquireBadAuthorization()
{
- let fileManager = SUFileManager.defaultManager()
- XCTAssertNil(try? fileManager._acquireAuthorization())
+ let fileManager = SUFileManager.default()
+ XCTAssertNil(try? fileManager?._acquireAuthorization())
}
}
diff --git a/Tests/SUSpotlightImporterTest.swift b/Tests/SUSpotlightImporterTest.swift
index 84f684cd..3c086e0a 100644
--- a/Tests/SUSpotlightImporterTest.swift
+++ b/Tests/SUSpotlightImporterTest.swift
@@ -12,49 +12,49 @@ class SUSpotlightImporterTest: XCTestCase
{
func testUpdatingSpotlightBundles()
{
- let fileManager = SUFileManager.defaultManager()
- let tempDirectoryURL = try! fileManager.makeTemporaryDirectoryWithPreferredName("Sparkle Unit Test Data", appropriateForDirectoryURL: NSURL(fileURLWithPath: NSHomeDirectory()))
+ let fileManager = SUFileManager.default()
+ let tempDirectoryURL = try! fileManager?.makeTemporaryDirectory(withPreferredName: "Sparkle Unit Test Data", appropriateForDirectoryURL: URL(fileURLWithPath: NSHomeDirectory()))
- let bundleDirectory = tempDirectoryURL.URLByAppendingPathComponent("bundle.app")
- try! fileManager.makeDirectoryAtURL(bundleDirectory)
+ let bundleDirectory = tempDirectoryURL?.appendingPathComponent("bundle.app")
+ try! fileManager?.makeDirectory(at: bundleDirectory)
- let innerDirectory = bundleDirectory.URLByAppendingPathComponent("foo")
- try! fileManager.makeDirectoryAtURL(innerDirectory)
- try! NSData().writeToURL(bundleDirectory.URLByAppendingPathComponent("bar"), options: .AtomicWrite)
+ let innerDirectory = bundleDirectory?.appendingPathComponent("foo")
+ try! fileManager?.makeDirectory(at: innerDirectory)
+ try! Data().write(to: (bundleDirectory?.appendingPathComponent("bar"))!, options: .atomicWrite)
- let importerDirectory = innerDirectory.URLByAppendingPathComponent("baz.mdimporter")
+ let importerDirectory = innerDirectory?.appendingPathComponent("baz.mdimporter")
- try! fileManager.makeDirectoryAtURL(importerDirectory)
- try! fileManager.makeDirectoryAtURL(innerDirectory.URLByAppendingPathComponent("flag"))
+ try! fileManager?.makeDirectory(at: importerDirectory)
+ try! fileManager?.makeDirectory(at: innerDirectory?.appendingPathComponent("flag"))
- try! NSData().writeToURL(importerDirectory.URLByAppendingPathComponent("file"), options: .AtomicWrite)
+ try! Data().write(to: (importerDirectory?.appendingPathComponent("file"))!, options: .atomicWrite)
- let oldFooDirectoryAttributes = try! NSFileManager.defaultManager().attributesOfItemAtPath(innerDirectory.path!)
- let oldBarFileAttributes = try! NSFileManager.defaultManager().attributesOfItemAtPath(bundleDirectory.URLByAppendingPathComponent("bar").path!)
- let oldImporterAttributes = try! NSFileManager.defaultManager().attributesOfItemAtPath(importerDirectory.path!)
- let oldFlagAttributes = try! NSFileManager.defaultManager().attributesOfItemAtPath(innerDirectory.URLByAppendingPathComponent("flag").path!)
- let oldFileInImporterAttributes = try! NSFileManager.defaultManager().attributesOfItemAtPath(importerDirectory.URLByAppendingPathComponent("file").path!)
+ 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.updateSpotlightImportersAtBundlePath(bundleDirectory.path!)
+ SUBinaryDeltaUnarchiver.updateSpotlightImporters(atBundlePath: bundleDirectory!.path)
- let newFooDirectoryAttributes = try! NSFileManager.defaultManager().attributesOfItemAtPath(innerDirectory.path!)
- XCTAssertEqual((newFooDirectoryAttributes[NSFileModificationDate] as! NSDate).timeIntervalSinceDate(oldFooDirectoryAttributes[NSFileModificationDate] as! NSDate), 0)
+ 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! NSFileManager.defaultManager().attributesOfItemAtPath(bundleDirectory.URLByAppendingPathComponent("bar").path!)
- XCTAssertEqual((newBarFileAttributes[NSFileModificationDate] as! NSDate).timeIntervalSinceDate(oldBarFileAttributes[NSFileModificationDate] as! NSDate), 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! NSFileManager.defaultManager().attributesOfItemAtPath(importerDirectory.path!)
- XCTAssertGreaterThan((newImporterAttributes[NSFileModificationDate] as! NSDate).timeIntervalSinceDate(oldImporterAttributes[NSFileModificationDate] as! NSDate), 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! NSFileManager.defaultManager().attributesOfItemAtPath(innerDirectory.URLByAppendingPathComponent("flag").path!)
- XCTAssertEqual((newFlagAttributes[NSFileModificationDate] as! NSDate).timeIntervalSinceDate(oldFlagAttributes[NSFileModificationDate] as! NSDate), 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! NSFileManager.defaultManager().attributesOfItemAtPath(importerDirectory.URLByAppendingPathComponent("file").path!)
- XCTAssertEqual((newFileInImporterAttributes[NSFileModificationDate] as! NSDate).timeIntervalSinceDate(oldFileInImporterAttributes[NSFileModificationDate] as! NSDate), 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.removeItemAtURL(tempDirectoryURL)
+ try! fileManager?.removeItem(at: tempDirectoryURL)
}
}
diff --git a/Tests/SUUnarchiverTest.swift b/Tests/SUUnarchiverTest.swift
index b81ffc38..4e70bba8 100644
--- a/Tests/SUUnarchiverTest.swift
+++ b/Tests/SUUnarchiverTest.swift
@@ -14,52 +14,52 @@ class SUUnarchiverTest: XCTestCase, SUUnarchiverDelegate
var unarchivedExpectation: XCTestExpectation? = nil
var unarchivedResult: Bool = false
- func unarchiver(unarchiver: SUUnarchiver!, extractedProgress progress: Double)
+ func unarchiver(_ unarchiver: SUUnarchiver!, extractedProgress progress: Double)
{
}
- func unarchiverDidFail(unarchiver: SUUnarchiver!)
+ func unarchiverDidFail(_ unarchiver: SUUnarchiver!)
{
self.unarchivedResult = false
self.unarchivedExpectation!.fulfill()
}
- func unarchiverDidFinish(unarchiver: SUUnarchiver!)
+ func unarchiverDidFinish(_ unarchiver: SUUnarchiver!)
{
self.unarchivedResult = true
self.unarchivedExpectation!.fulfill()
}
- func unarchiveTestAppWithExtension(archiveExtension: String)
+ func unarchiveTestAppWithExtension(_ archiveExtension: String)
{
let appName = "SparkleTestCodeSignApp"
- let archiveResourceURL = NSBundle(forClass: self.dynamicType).URLForResource(appName, withExtension: archiveExtension)!
+ let archiveResourceURL = Bundle(for: type(of: self)).url(forResource: appName, withExtension: archiveExtension)!
- let fileManager = NSFileManager.defaultManager()
+ let fileManager = FileManager.default
- let tempDirectoryURL = try! fileManager.URLForDirectory(.ItemReplacementDirectory, inDomain: .UserDomainMask, appropriateForURL: NSURL(fileURLWithPath: NSHomeDirectory()), create: true)
+ let tempDirectoryURL = try! fileManager.url(for: .itemReplacementDirectory, in: .userDomainMask, appropriateFor: URL(fileURLWithPath: NSHomeDirectory()), create: true)
defer {
- try! fileManager.removeItemAtURL(tempDirectoryURL)
+ try! fileManager.removeItem(at: tempDirectoryURL)
}
- let tempArchiveURL = tempDirectoryURL.URLByAppendingPathComponent(archiveResourceURL.lastPathComponent!)
- let extractedAppURL = tempDirectoryURL.URLByAppendingPathComponent(appName).URLByAppendingPathExtension("app")
+ let tempArchiveURL = tempDirectoryURL.appendingPathComponent(archiveResourceURL.lastPathComponent)
+ let extractedAppURL = tempDirectoryURL.appendingPathComponent(appName).appendingPathExtension("app")
- try! fileManager.copyItemAtURL(archiveResourceURL, toURL: tempArchiveURL)
+ try! fileManager.copyItem(at: archiveResourceURL, to: tempArchiveURL)
- self.unarchivedExpectation = super.expectationWithDescription("Unarchived Application (format: \(archiveExtension))")
+ self.unarchivedExpectation = super.expectation(description: "Unarchived Application (format: \(archiveExtension))")
- let unarchiver = SUUnarchiver(forPath: tempArchiveURL.path!, updatingHostBundlePath: nil, withPassword: self.password)
+ let unarchiver = SUUnarchiver(forPath: tempArchiveURL.path, updatingHostBundlePath: nil, withPassword: self.password)
- unarchiver.delegate = self
- unarchiver.start()
+ unarchiver?.delegate = self
+ unarchiver?.start()
- super.waitForExpectationsWithTimeout(7.0, handler: nil)
+ super.waitForExpectations(timeout: 7.0, handler: nil)
XCTAssertTrue(self.unarchivedResult)
- XCTAssertTrue(fileManager.fileExistsAtPath(extractedAppURL.path!))
+ XCTAssertTrue(fileManager.fileExists(atPath: extractedAppURL.path))
- XCTAssertEqual("6a60ab31430cfca8fb499a884f4a29f73e59b472", hashOfTree(extractedAppURL.path!))
+ XCTAssertEqual("6a60ab31430cfca8fb499a884f4a29f73e59b472", hashOfTree(extractedAppURL.path))
}
func testUnarchivingZip()
diff --git a/UITests/SUTestApplicationTest.swift b/UITests/SUTestApplicationTest.swift
index e5163fe3..72cd02fb 100644
--- a/UITests/SUTestApplicationTest.swift
+++ b/UITests/SUTestApplicationTest.swift
@@ -10,14 +10,14 @@ import XCTest
class SUTestApplicationTest: XCTestCase
{
- var testApplicationURL: NSURL? = nil
- var testApplicationBackupURL: NSURL? = nil
- var tempDirectoryURL: NSURL? = nil
+ var testApplicationURL: URL? = nil
+ var testApplicationBackupURL: URL? = nil
+ var tempDirectoryURL: URL? = nil
func runningTestApplication() -> NSRunningApplication
{
// TODO: don't hardcode bundle ID?
- let runningApplications = NSRunningApplication.runningApplicationsWithBundleIdentifier("org.sparkle-project.SparkleTestApp")
+ let runningApplications = NSRunningApplication.runningApplications(withBundleIdentifier: "org.sparkle-project.SparkleTestApp")
XCTAssertEqual(runningApplications.count, 1, "More than one or zero running instances of the Test Application are found")
return runningApplications[0]
}
@@ -35,11 +35,11 @@ class SUTestApplicationTest: XCTestCase
// When a successful test is over we'll revert the update
let testApplicationURL = self.runningTestApplication().bundleURL!
- let tempDirectoryURL = try! NSFileManager.defaultManager().URLForDirectory(.ItemReplacementDirectory, inDomain: NSSearchPathDomainMask.UserDomainMask, appropriateForURL: testApplicationURL, create: true)
+ let tempDirectoryURL = try! FileManager.default.url(for: .itemReplacementDirectory, in: FileManager.SearchPathDomainMask.userDomainMask, appropriateFor: testApplicationURL, create: true)
- let testApplicationBackupURL = tempDirectoryURL.URLByAppendingPathComponent(testApplicationURL.lastPathComponent!)
+ let testApplicationBackupURL = tempDirectoryURL.appendingPathComponent(testApplicationURL.lastPathComponent)
- try! NSFileManager.defaultManager().copyItemAtURL(testApplicationURL, toURL: testApplicationBackupURL)
+ try! FileManager.default.copyItem(at: testApplicationURL, to: testApplicationBackupURL)
self.testApplicationURL = testApplicationURL
self.testApplicationBackupURL = testApplicationBackupURL
@@ -58,16 +58,16 @@ class SUTestApplicationTest: XCTestCase
// Revert our update with the original test application
var resultingURL: NSURL? = nil
- try! NSFileManager.defaultManager().replaceItemAtURL(self.testApplicationURL!, withItemAtURL: self.testApplicationBackupURL!, backupItemName: nil, options: .UsingNewMetadataOnly, resultingItemURL: &resultingURL)
+ try! FileManager.default.replaceItem(at: self.testApplicationURL!, withItemAt: self.testApplicationBackupURL!, backupItemName: nil, options: .usingNewMetadataOnly, resultingItemURL: &resultingURL)
do {
- try NSFileManager.defaultManager().removeItemAtURL(self.tempDirectoryURL!)
+ 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, "Test application was replaced, but at a different location")
+ XCTAssertEqual(self.testApplicationURL, resultingURL as URL?, "Test application was replaced, but at a different location")
super.tearDown()
}
@@ -91,7 +91,7 @@ class SUTestApplicationTest: XCTestCase
// 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().active)
+ XCTAssertTrue(self.runningTestApplication().isActive)
// Grab another XCUIApplication instance rather than using the old one, just in case
let updatedApp = XCUIApplication()