Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9646b0b790 | ||
|
|
afb524a46a | ||
|
|
56ac1c931b | ||
|
|
3a788e9546 | ||
|
|
0b2f37beb9 | ||
|
|
353a5635e1 | ||
|
|
35dfed44de | ||
|
|
3680b0bb67 | ||
|
|
209d6db3a1 | ||
|
|
bb7af6145f | ||
|
|
77fd19a134 | ||
|
|
38a70c61c4 | ||
|
|
d2fd67ac84 | ||
|
|
f911c29bf0 | ||
|
|
63052aa3d1 | ||
|
|
eb28fe7ebd | ||
|
|
06c6a3b7f2 | ||
|
|
d4843c90e8 | ||
|
|
5ba0b2d656 | ||
|
|
482301aa0d | ||
|
|
87dfb72484 | ||
|
|
ea07f716b8 | ||
|
|
e7786dde97 | ||
|
|
b02a65974d | ||
|
|
6017c982c5 | ||
|
|
836c6ef09e | ||
|
|
ab4a058ac4 | ||
|
|
da9e48cf29 | ||
|
|
08aed29870 | ||
|
|
f31921e775 | ||
|
|
578ba9adaf | ||
|
|
efac6b053d | ||
|
|
e978cb0a3a | ||
|
|
b780b476c6 | ||
|
|
ba75b79a97 | ||
|
|
f9043aa0e6 | ||
|
|
5890ec6cfe | ||
|
|
fef73cc297 | ||
|
|
c7a8d5d42a | ||
|
|
9e9fef0d51 | ||
|
|
509df736bc | ||
|
|
063056e193 | ||
|
|
d1908b1645 | ||
|
|
06a1ab8787 | ||
|
|
cd478a4c48 | ||
|
|
acbd622369 | ||
|
|
817bbc46b1 | ||
|
|
dbc9123dce | ||
|
|
c2cb3094af | ||
|
|
65931f6277 | ||
|
|
0f6697214d | ||
|
|
3c78139ec8 | ||
|
|
5c921de24f | ||
|
|
a715babce3 | ||
|
|
fd68e649db | ||
|
|
186cfa8486 | ||
|
|
c5bc6fe95b | ||
|
|
285cd3063f | ||
|
|
8a4f4677bd | ||
|
|
57122a40e6 | ||
|
|
e2fca42f6c | ||
|
|
443a6064b3 | ||
|
|
86754e0537 | ||
|
|
78a940fcf4 | ||
|
|
4029788163 | ||
|
|
16cd57b8eb | ||
|
|
a5687d9c1d | ||
|
|
e93888ad3f | ||
|
|
7aaf002651 | ||
|
|
742648a166 | ||
|
|
c1f9fcb456 | ||
|
|
47d56a5485 | ||
|
|
498ed027dd | ||
|
|
31d03b314d | ||
|
|
8bbe487c86 | ||
|
|
4d6eeb363c | ||
|
|
419b6aabef | ||
|
|
54522aa725 | ||
|
|
d374d99e51 | ||
|
|
33de6ed878 | ||
|
|
0c40d99740 | ||
|
|
bcab57d8f5 | ||
|
|
2ca0a739e5 | ||
|
|
9895f123a7 | ||
|
|
87dfe0a4ed | ||
|
|
08434edf79 | ||
|
|
695e05eba4 | ||
|
|
b9a8adba73 | ||
|
|
91f504ed9f | ||
|
|
6033bd4228 | ||
|
|
3de3b11523 | ||
|
|
707f86a2f4 | ||
|
|
e9817380d2 | ||
|
|
21999e4a75 | ||
|
|
616cc70775 | ||
|
|
09d98932d9 | ||
|
|
3b8513546e | ||
|
|
5589a604b8 | ||
|
|
44b027a178 | ||
|
|
2dfc8494d7 | ||
|
|
729087f696 | ||
|
|
7656128c55 | ||
|
|
5fe670ce05 | ||
|
|
d700b69072 | ||
|
|
ddde2822fa | ||
|
|
a7d11f88c7 | ||
|
|
e7ed4aa32f | ||
|
|
090285ec7e | ||
|
|
bc99dbd560 | ||
|
|
fbd90763f9 | ||
|
|
f88439923f | ||
|
|
8f4ab3eb56 | ||
|
|
f216ef7a13 | ||
|
|
1db20c4882 | ||
|
|
0a6de47783 | ||
|
|
2a1760a5a9 | ||
|
|
65238c35a9 | ||
|
|
5e4e904efd | ||
|
|
4d6d766a21 | ||
|
|
2cb531066c | ||
|
|
e41fbdee49 | ||
|
|
c2672cf89c | ||
|
|
a8d96e0dce | ||
|
|
979ab661de | ||
|
|
21657c9fb1 |
No files matched your search
@@ -1,3 +1,19 @@
|
||||
# 1.10.0
|
||||
|
||||
* Massive improvements to the BinaryDelta tool (Zorg)
|
||||
- Ability to track file permissions (Zorg)
|
||||
- Nicely formatted log output (Zorg)
|
||||
- Numerous bug fixes in handling of symlinks, empty directories, case-insensitive names, etc. (Zorg)
|
||||
- Refactored and modernized code (Zorg)
|
||||
- libxar is no longer weak-linked (C.W. Betts)
|
||||
* Double-check the code signature of the the app after installation (Isaac Wankerl)
|
||||
* Added headless guided package installation (Graham Miln)
|
||||
* Added ability to inject custom HTTP headers in appcast request (Mattias Gunneras)
|
||||
* Changes to make unarching more reliable (Zorg, Kornel Lesiński)
|
||||
* Have Sparkle build a framework module (C.W. Betts)
|
||||
* Stdout used for non error outputs (JDuquennoy)
|
||||
* French locale update (Kent Sutherland)
|
||||
|
||||
# 1.9.0
|
||||
|
||||
* Added SUUpdater delegate method for failures. (Benjamin Gordon)
|
||||
|
||||
@@ -15,7 +15,7 @@ SPARKLE_AUTOMATED_DOWNGRADES = 0
|
||||
SPARKLE_NORMALIZE_INSTALLED_APPLICATION_NAME = 0
|
||||
|
||||
SPARKLE_VERSION_MAJOR = 1
|
||||
SPARKLE_VERSION_MINOR = 9
|
||||
SPARKLE_VERSION_MINOR = 10
|
||||
SPARKLE_VERSION_PATCH = 0
|
||||
SPARKLE_VERSION = $(SPARKLE_VERSION_MAJOR).$(SPARKLE_VERSION_MINOR).$(SPARKLE_VERSION_PATCH)
|
||||
|
||||
@@ -35,6 +35,7 @@ CLANG_ENABLE_OBJC_ARC = YES
|
||||
CLANG_ANALYZER_SECURITY_FLOATLOOPCOUNTER = YES
|
||||
CLANG_ANALYZER_SECURITY_INSECUREAPI_RAND = YES
|
||||
CLANG_ANALYZER_SECURITY_INSECUREAPI_STRCPY = YES
|
||||
CLANG_ENABLE_MODULES = YES
|
||||
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES
|
||||
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES
|
||||
CLANG_WARN_DOCUMENTATION_COMMENTS = YES
|
||||
@@ -73,4 +74,4 @@ GCC_WARN_UNUSED_VARIABLE = YES
|
||||
WARNING_CFLAGS_EXTRA = -Wno-custom-atomic-properties -Wno-implicit-atomic-properties
|
||||
|
||||
// Turn on all warnings, then disable a few which are almost impossible to avoid
|
||||
WARNING_CFLAGS = -Wall -Weverything -Wno-empty-translation-unit -Wno-unused-macros -Wno-gnu-statement-expression -Wno-receiver-is-weak -Wno-arc-repeated-use-of-weak -Wno-auto-import $(WARNING_CFLAGS_EXTRA)
|
||||
WARNING_CFLAGS = -Wall -Weverything -Wno-empty-translation-unit -Wno-unused-macros -Wno-gnu-statement-expression -Wno-receiver-is-weak -Wno-arc-repeated-use-of-weak -Wno-auto-import -Wno-cstring-format-directive $(WARNING_CFLAGS_EXTRA)
|
||||
@@ -10,3 +10,4 @@ INFOPLIST_FILE = Sparkle/Sparkle-Info.plist
|
||||
GCC_PREPROCESSOR_DEFINITIONS = $(inherited) BUILDING_SPARKLE=1
|
||||
OTHER_LDFLAGS = -Wl,-U,_NSURLQuarantinePropertiesKey
|
||||
SKIP_INSTALL = YES
|
||||
DEFINES_MODULE = YES
|
||||
@@ -1,2 +1,4 @@
|
||||
#include "ConfigFramework.xcconfig"
|
||||
|
||||
// Unit tests need access to non-public classes
|
||||
GCC_SYMBOLS_PRIVATE_EXTERN = NO
|
||||
@@ -4,4 +4,5 @@ INFOPLIST_FILE = Sparkle/Autoupdate/Autoupdate-Info.plist
|
||||
PRODUCT_NAME = $(SPARKLE_RELAUNCH_TOOL_NAME)
|
||||
SKIP_INSTALL = YES
|
||||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon
|
||||
CLANG_ENABLE_MODULES = NO
|
||||
OTHER_LDFLAGS = -Wl,-U,_NSURLQuarantinePropertiesKey
|
||||
@@ -30,6 +30,9 @@ EXTERNAL LICENSES
|
||||
bspatch.c and bsdiff.c, from bsdiff 4.3 <http://www.daemonology.net/bsdiff/>:
|
||||
Copyright (c) 2003-2005 Colin Percival.
|
||||
|
||||
sais.c and sais.c, from sais-lite (2010/08/07) <https://sites.google.com/site/yuta256/sais>:
|
||||
Copyright (c) 2008-2010 Yuta Mori.
|
||||
|
||||
SUDSAVerifier.m:
|
||||
Copyright (c) 2011 Mark Hamlin.
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
An easy-to-use software update framework for Cocoa developers.
|
||||
|
||||

|
||||
<img src="Resources/Screenshot.png" width="715" alt="Sparkle shows familiar update window with release notes">
|
||||
|
||||
## Changes since 1.5b
|
||||
|
||||
|
||||
|
Before Width: | Height: | Size: 24 KiB After Width: | Height: | Size: 15 KiB |
|
Before Width: | Height: | Size: 55 KiB After Width: | Height: | Size: 37 KiB |
|
Before Width: | Height: | Size: 3.9 KiB After Width: | Height: | Size: 754 B |
|
Before Width: | Height: | Size: 5.7 KiB After Width: | Height: | Size: 2.1 KiB |
|
Before Width: | Height: | Size: 55 KiB After Width: | Height: | Size: 37 KiB |
|
Before Width: | Height: | Size: 5.7 KiB After Width: | Height: | Size: 2.1 KiB |
|
Before Width: | Height: | Size: 11 KiB After Width: | Height: | Size: 5.9 KiB |
|
Before Width: | Height: | Size: 215 KiB After Width: | Height: | Size: 44 KiB |
|
Before Width: | Height: | Size: 17 KiB After Width: | Height: | Size: 11 KiB |
@@ -1,6 +1,6 @@
|
||||
Pod::Spec.new do |s|
|
||||
s.name = "Sparkle"
|
||||
s.version = "1.8.0"
|
||||
s.version = "1.9.0"
|
||||
s.summary = "A software update framework for OS X"
|
||||
s.description = "Sparkle is an easy-to-use software update framework for Cocoa developers."
|
||||
s.homepage = "http://sparkle-project.org"
|
||||
|
||||
@@ -34,9 +34,7 @@
|
||||
14652F7C19A9725300959E44 /* SUBinaryDeltaCommon.m in Sources */ = {isa = PBXBuildFile; fileRef = 5D06E8E20FD68CC7005AE3F6 /* SUBinaryDeltaCommon.m */; };
|
||||
14652F7D19A9726700959E44 /* SUBinaryDeltaApply.m in Sources */ = {isa = PBXBuildFile; fileRef = 5D06E8E00FD68CC7005AE3F6 /* SUBinaryDeltaApply.m */; };
|
||||
14652F7E19A9728A00959E44 /* bspatch.c in Sources */ = {isa = PBXBuildFile; fileRef = 5D06E8DC0FD68CB9005AE3F6 /* bspatch.c */; settings = {COMPILER_FLAGS = "-w"; }; };
|
||||
14652F7F19A973F900959E44 /* SUDSAVerifier.m in Sources */ = {isa = PBXBuildFile; fileRef = 61299A2E09CA2DAB00B7442F /* SUDSAVerifier.m */; };
|
||||
14652F8019A9740F00959E44 /* Security.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 61B5F8F609C4CEB300B25A18 /* Security.framework */; };
|
||||
14652F8119A9744200959E44 /* SUBinaryDeltaCommon.m in Sources */ = {isa = PBXBuildFile; fileRef = 5D06E8E20FD68CC7005AE3F6 /* SUBinaryDeltaCommon.m */; };
|
||||
14652F8219A9746000959E44 /* SULog.m in Sources */ = {isa = PBXBuildFile; fileRef = 55C14F05136EF6DB00649790 /* SULog.m */; };
|
||||
14652F8419A978C200959E44 /* SUExport.h in Headers */ = {isa = PBXBuildFile; fileRef = 14652F8319A9759F00959E44 /* SUExport.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
14732BC01960F2C200593899 /* test_app_only_dsa_pub.pem in Resources */ = {isa = PBXBuildFile; fileRef = 14732BBF1960F0AC00593899 /* test_app_only_dsa_pub.pem */; };
|
||||
@@ -49,7 +47,6 @@
|
||||
14950071195FCE3D00BC5B5B /* AppKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0867D6A5FE840307C02AAC07 /* AppKit.framework */; };
|
||||
14950072195FCE4B00BC5B5B /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0867D69BFE84028FC02AAC07 /* Foundation.framework */; };
|
||||
14950073195FCE4E00BC5B5B /* AppKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0867D6A5FE840307C02AAC07 /* AppKit.framework */; };
|
||||
14950075195FDF5900BC5B5B /* SUUpdaterTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 14950074195FDF5900BC5B5B /* SUUpdaterTest.m */; };
|
||||
14958C6E19AEBC950061B14F /* signed-test-file.txt in Resources */ = {isa = PBXBuildFile; fileRef = 14958C6B19AEBC530061B14F /* signed-test-file.txt */; };
|
||||
14958C6F19AEBC980061B14F /* test-pubkey.pem in Resources */ = {isa = PBXBuildFile; fileRef = 14958C6C19AEBC610061B14F /* test-pubkey.pem */; };
|
||||
3772FEA913DE0B6B00F79537 /* SUVersionDisplayProtocol.h in Headers */ = {isa = PBXBuildFile; fileRef = 3772FEA813DE0B6B00F79537 /* SUVersionDisplayProtocol.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
@@ -76,6 +73,10 @@
|
||||
55C14F9A136F045400649790 /* Security.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 61B5F8F609C4CEB300B25A18 /* Security.framework */; };
|
||||
55C14FC7136F05E100649790 /* Sparkle.strings in Resources */ = {isa = PBXBuildFile; fileRef = 61AAE8220A321A7F00D8810D /* Sparkle.strings */; };
|
||||
55E6F33319EC9F6C00005E76 /* SUErrors.h in Headers */ = {isa = PBXBuildFile; fileRef = 55E6F33219EC9F6C00005E76 /* SUErrors.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
5AF6C1E51AE86A410014A3AB /* SUPipedUnarchiverTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 5AF6C1EA1AE870A90014A3AB /* SUPipedUnarchiverTest.m */; };
|
||||
5AF6C1E91AE86E270014A3AB /* test archive.zip in Resources */ = {isa = PBXBuildFile; fileRef = 5AF6C1E81AE86E270014A3AB /* test archive.zip */; };
|
||||
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 */; };
|
||||
5D06E8E90FD68CDB005AE3F6 /* bsdiff.c in Sources */ = {isa = PBXBuildFile; fileRef = 5D06E8DB0FD68CB9005AE3F6 /* bsdiff.c */; settings = {COMPILER_FLAGS = "-w"; }; };
|
||||
5D06E8EA0FD68CDB005AE3F6 /* SUBinaryDeltaTool.m in Sources */ = {isa = PBXBuildFile; fileRef = 5D06E8E30FD68CC7005AE3F6 /* SUBinaryDeltaTool.m */; };
|
||||
@@ -107,13 +108,12 @@
|
||||
61180BCB0D64138900B4E0D1 /* SUWindowController.m in Sources */ = {isa = PBXBuildFile; fileRef = 61180BC90D64138900B4E0D1 /* SUWindowController.m */; };
|
||||
6120721209CC5C4B007FE0F6 /* SUAutomaticUpdateAlert.h in Headers */ = {isa = PBXBuildFile; fileRef = 6120721009CC5C4B007FE0F6 /* SUAutomaticUpdateAlert.h */; settings = {ATTRIBUTES = (); }; };
|
||||
6120721309CC5C4B007FE0F6 /* SUAutomaticUpdateAlert.m in Sources */ = {isa = PBXBuildFile; fileRef = 6120721109CC5C4B007FE0F6 /* SUAutomaticUpdateAlert.m */; };
|
||||
61227A160DB548B800AB99EA /* SUVersionComparisonTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 61227A150DB548B800AB99EA /* SUVersionComparisonTest.m */; };
|
||||
61299A2F09CA2DAB00B7442F /* SUDSAVerifier.h in Headers */ = {isa = PBXBuildFile; fileRef = 61299A2D09CA2DAB00B7442F /* SUDSAVerifier.h */; settings = {ATTRIBUTES = (); }; };
|
||||
61299A3009CA2DAB00B7442F /* SUDSAVerifier.m in Sources */ = {isa = PBXBuildFile; fileRef = 61299A2E09CA2DAB00B7442F /* SUDSAVerifier.m */; settings = {COMPILER_FLAGS = "-Wno-deprecated-declarations"; }; };
|
||||
61299A4A09CA2DD000B7442F /* SUPlainInstallerInternals.h in Headers */ = {isa = PBXBuildFile; fileRef = 6129984309C9E2DA00B7442F /* SUPlainInstallerInternals.h */; settings = {ATTRIBUTES = (); }; };
|
||||
61299A5C09CA6D4500B7442F /* SUConstants.h in Headers */ = {isa = PBXBuildFile; fileRef = 61299A5B09CA6D4500B7442F /* SUConstants.h */; settings = {ATTRIBUTES = (); }; };
|
||||
61299A6009CA6EB100B7442F /* SUConstants.m in Sources */ = {isa = PBXBuildFile; fileRef = 61299A5F09CA6EB100B7442F /* SUConstants.m */; };
|
||||
61299A8D09CA790200B7442F /* SUUnarchiver.h in Headers */ = {isa = PBXBuildFile; fileRef = 61299A8B09CA790200B7442F /* SUUnarchiver.h */; settings = {ATTRIBUTES = (); }; };
|
||||
61299A8D09CA790200B7442F /* SUUnarchiver.h in Headers */ = {isa = PBXBuildFile; fileRef = 61299A8B09CA790200B7442F /* SUUnarchiver.h */; settings = {ATTRIBUTES = (Private, ); }; };
|
||||
61299A8E09CA790200B7442F /* SUUnarchiver.m in Sources */ = {isa = PBXBuildFile; fileRef = 61299A8C09CA790200B7442F /* SUUnarchiver.m */; };
|
||||
61299B3609CB04E000B7442F /* Sparkle.h in Headers */ = {isa = PBXBuildFile; fileRef = 61299B3509CB04E000B7442F /* Sparkle.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
612DCBAF0D488BC60015DBEA /* SUUpdatePermissionPrompt.h in Headers */ = {isa = PBXBuildFile; fileRef = 612DCBAD0D488BC60015DBEA /* SUUpdatePermissionPrompt.h */; settings = {ATTRIBUTES = (); }; };
|
||||
@@ -167,6 +167,20 @@
|
||||
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, ); }; };
|
||||
721CF1A71AD7643600D9AC09 /* bsdiff.c in Sources */ = {isa = PBXBuildFile; fileRef = 5D06E8DB0FD68CB9005AE3F6 /* bsdiff.c */; };
|
||||
721CF1A81AD7644100D9AC09 /* bspatch.c in Sources */ = {isa = PBXBuildFile; fileRef = 5D06E8DC0FD68CB9005AE3F6 /* bspatch.c */; };
|
||||
721CF1A91AD7644C00D9AC09 /* sais.c in Sources */ = {isa = PBXBuildFile; fileRef = 7223E7611AD1AEFF008E3161 /* sais.c */; };
|
||||
721CF1AA1AD7647000D9AC09 /* libxar.1.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 5D1AF5890FD7678C0065DB48 /* libxar.1.dylib */; };
|
||||
721CF1AB1AD764EB00D9AC09 /* libbz2.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 5D06E8FB0FD68D61005AE3F6 /* libbz2.dylib */; };
|
||||
7223E7631AD1AEFF008E3161 /* sais.c in Sources */ = {isa = PBXBuildFile; fileRef = 7223E7611AD1AEFF008E3161 /* sais.c */; };
|
||||
7268AC631AD634C200C3E0C1 /* SUBinaryDeltaCreate.m in Sources */ = {isa = PBXBuildFile; fileRef = 7268AC621AD634C200C3E0C1 /* SUBinaryDeltaCreate.m */; };
|
||||
72D4DAA11AD7632900B211E2 /* SUBinaryDeltaCreate.m in Sources */ = {isa = PBXBuildFile; fileRef = 7268AC621AD634C200C3E0C1 /* SUBinaryDeltaCreate.m */; };
|
||||
767B61AC1972D488004E0C3C /* SUGuidedPackageInstaller.h in Headers */ = {isa = PBXBuildFile; fileRef = 767B61AA1972D488004E0C3C /* SUGuidedPackageInstaller.h */; };
|
||||
767B61AD1972D488004E0C3C /* SUGuidedPackageInstaller.m in Sources */ = {isa = PBXBuildFile; fileRef = 767B61AB1972D488004E0C3C /* SUGuidedPackageInstaller.m */; };
|
||||
767B61AE1972D488004E0C3C /* SUGuidedPackageInstaller.m in Sources */ = {isa = PBXBuildFile; fileRef = 767B61AB1972D488004E0C3C /* SUGuidedPackageInstaller.m */; };
|
||||
F8761EB11ADC5068000C9034 /* SUCodeSigningVerifierTest.m in Sources */ = {isa = PBXBuildFile; fileRef = F8761EB01ADC5068000C9034 /* SUCodeSigningVerifierTest.m */; };
|
||||
F8761EB31ADC50EB000C9034 /* SparkleTestCodeSignApp.zip in Resources */ = {isa = PBXBuildFile; fileRef = F8761EB21ADC50EB000C9034 /* SparkleTestCodeSignApp.zip */; };
|
||||
F8761EB61ADC5E7A000C9034 /* SUCodeSigningVerifier.m in Sources */ = {isa = PBXBuildFile; fileRef = 61B078CD15A5FB6100600039 /* SUCodeSigningVerifier.m */; };
|
||||
/* End PBXBuildFile section */
|
||||
|
||||
/* Begin PBXContainerItemProxy section */
|
||||
@@ -401,6 +415,10 @@
|
||||
55C14F31136EFC2400649790 /* SystemConfiguration.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SystemConfiguration.framework; path = System/Library/Frameworks/SystemConfiguration.framework; sourceTree = SDKROOT; };
|
||||
55E6F33219EC9F6C00005E76 /* SUErrors.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUErrors.h; sourceTree = "<group>"; };
|
||||
5AEF45D9189D1CC90030D7DC /* tr */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = tr; path = tr.lproj/Sparkle.strings; sourceTree = "<group>"; };
|
||||
5AF6C1E81AE86E270014A3AB /* test archive.zip */ = {isa = PBXFileReference; lastKnownFileType = archive.zip; path = "test archive.zip"; sourceTree = "<group>"; };
|
||||
5AF6C1EA1AE870A90014A3AB /* SUPipedUnarchiverTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SUPipedUnarchiverTest.m; sourceTree = "<group>"; };
|
||||
5AF6C74C1AEA40760014A3AB /* SUInstallerTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SUInstallerTest.m; sourceTree = "<group>"; };
|
||||
5AF6C74E1AEA46D10014A3AB /* test.sparkle_guided.pkg */ = {isa = PBXFileReference; lastKnownFileType = file; path = test.sparkle_guided.pkg; sourceTree = "<group>"; };
|
||||
5AF9DC3B1981DBEE001EA135 /* SUDSAVerifierTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SUDSAVerifierTest.m; sourceTree = "<group>"; };
|
||||
5D06E8D00FD68C7C005AE3F6 /* BinaryDelta */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = BinaryDelta; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
5D06E8DB0FD68CB9005AE3F6 /* bsdiff.c */ = {isa = PBXFileReference; comments = "-Wno-shorten-64-to-32"; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = bsdiff.c; sourceTree = "<group>"; };
|
||||
@@ -531,8 +549,16 @@
|
||||
61F614540E24A12D009F47E7 /* it */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.strings; name = it; path = it.lproj/Sparkle.strings; sourceTree = "<group>"; };
|
||||
61F83F6F0DBFE137006FDD30 /* SUBasicUpdateDriver.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUBasicUpdateDriver.h; sourceTree = "<group>"; };
|
||||
61F83F700DBFE137006FDD30 /* SUBasicUpdateDriver.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SUBasicUpdateDriver.m; sourceTree = "<group>"; };
|
||||
7223E7611AD1AEFF008E3161 /* sais.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = sais.c; sourceTree = "<group>"; };
|
||||
7223E7621AD1AEFF008E3161 /* sais.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = sais.h; sourceTree = "<group>"; };
|
||||
7268AC621AD634C200C3E0C1 /* SUBinaryDeltaCreate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SUBinaryDeltaCreate.m; sourceTree = "<group>"; };
|
||||
7268AC641AD634E400C3E0C1 /* SUBinaryDeltaCreate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUBinaryDeltaCreate.h; sourceTree = "<group>"; };
|
||||
767B61AA1972D488004E0C3C /* SUGuidedPackageInstaller.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUGuidedPackageInstaller.h; sourceTree = "<group>"; };
|
||||
767B61AB1972D488004E0C3C /* SUGuidedPackageInstaller.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SUGuidedPackageInstaller.m; sourceTree = "<group>"; };
|
||||
8DC2EF5A0486A6940098B216 /* Sparkle-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "Sparkle-Info.plist"; sourceTree = "<group>"; };
|
||||
8DC2EF5B0486A6940098B216 /* Sparkle.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Sparkle.framework; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
F8761EB01ADC5068000C9034 /* SUCodeSigningVerifierTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SUCodeSigningVerifierTest.m; sourceTree = "<group>"; };
|
||||
F8761EB21ADC50EB000C9034 /* SparkleTestCodeSignApp.zip */ = {isa = PBXFileReference; lastKnownFileType = archive.zip; path = SparkleTestCodeSignApp.zip; sourceTree = "<group>"; };
|
||||
FA1941CA0D94A70100DD942E /* ConfigFrameworkDebug.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = ConfigFrameworkDebug.xcconfig; sourceTree = "<group>"; };
|
||||
FA1941CB0D94A70100DD942E /* ConfigTestAppDebug.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = ConfigTestAppDebug.xcconfig; sourceTree = "<group>"; };
|
||||
FA1941CC0D94A70100DD942E /* ConfigCommonRelease.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = ConfigCommonRelease.xcconfig; sourceTree = "<group>"; };
|
||||
@@ -581,8 +607,10 @@
|
||||
files = (
|
||||
14732BD119610A1200593899 /* AppKit.framework in Frameworks */,
|
||||
14732BD019610A0D00593899 /* Foundation.framework in Frameworks */,
|
||||
61FA52880E2D9EA400EF58AD /* Sparkle.framework in Frameworks */,
|
||||
721CF1AB1AD764EB00D9AC09 /* libbz2.dylib in Frameworks */,
|
||||
721CF1AA1AD7647000D9AC09 /* libxar.1.dylib in Frameworks */,
|
||||
14652F8019A9740F00959E44 /* Security.framework in Frameworks */,
|
||||
61FA52880E2D9EA400EF58AD /* Sparkle.framework in Frameworks */,
|
||||
14732BD319610A1800593899 /* XCTest.framework in Frameworks */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
@@ -702,6 +730,8 @@
|
||||
5D06E8DB0FD68CB9005AE3F6 /* bsdiff.c */,
|
||||
5D06E8DC0FD68CB9005AE3F6 /* bspatch.c */,
|
||||
611142E810FB1BE5009810AA /* bspatch.h */,
|
||||
7223E7611AD1AEFF008E3161 /* sais.c */,
|
||||
7223E7621AD1AEFF008E3161 /* sais.h */,
|
||||
);
|
||||
path = bsdiff;
|
||||
sourceTree = "<group>";
|
||||
@@ -758,7 +788,10 @@
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
14958C6B19AEBC530061B14F /* signed-test-file.txt */,
|
||||
F8761EB21ADC50EB000C9034 /* SparkleTestCodeSignApp.zip */,
|
||||
5AF6C1E81AE86E270014A3AB /* test archive.zip */,
|
||||
14958C6C19AEBC610061B14F /* test-pubkey.pem */,
|
||||
5AF6C74E1AEA46D10014A3AB /* test.sparkle_guided.pkg */,
|
||||
);
|
||||
path = Resources;
|
||||
sourceTree = "<group>";
|
||||
@@ -779,6 +812,8 @@
|
||||
5D06E8E00FD68CC7005AE3F6 /* SUBinaryDeltaApply.m */,
|
||||
5D06E8E10FD68CC7005AE3F6 /* SUBinaryDeltaCommon.h */,
|
||||
5D06E8E20FD68CC7005AE3F6 /* SUBinaryDeltaCommon.m */,
|
||||
7268AC641AD634E400C3E0C1 /* SUBinaryDeltaCreate.h */,
|
||||
7268AC621AD634C200C3E0C1 /* SUBinaryDeltaCreate.m */,
|
||||
5D06E8E30FD68CC7005AE3F6 /* SUBinaryDeltaTool.m */,
|
||||
5D06E9370FD69271005AE3F6 /* SUBinaryDeltaUnarchiver.h */,
|
||||
5D06E9380FD69271005AE3F6 /* SUBinaryDeltaUnarchiver.m */,
|
||||
@@ -804,12 +839,15 @@
|
||||
61227A100DB5484000AB99EA /* Tests */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
14958C7019AEBE350061B14F /* Resources */,
|
||||
612279DA0DB5470200AB99EA /* SparkleTests-Info.plist */,
|
||||
142E0E0819A83AAC00E4312B /* SUBinaryDeltaTest.m */,
|
||||
F8761EB01ADC5068000C9034 /* SUCodeSigningVerifierTest.m */,
|
||||
5AF9DC3B1981DBEE001EA135 /* SUDSAVerifierTest.m */,
|
||||
5AF6C74C1AEA40760014A3AB /* SUInstallerTest.m */,
|
||||
5AF6C1EA1AE870A90014A3AB /* SUPipedUnarchiverTest.m */,
|
||||
14950074195FDF5900BC5B5B /* SUUpdaterTest.m */,
|
||||
61227A150DB548B800AB99EA /* SUVersionComparisonTest.m */,
|
||||
14958C7019AEBE350061B14F /* Resources */,
|
||||
);
|
||||
path = Tests;
|
||||
sourceTree = "<group>";
|
||||
@@ -851,6 +889,8 @@
|
||||
618FA6DB0DB485440026945C /* Installation */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
767B61AA1972D488004E0C3C /* SUGuidedPackageInstaller.h */,
|
||||
767B61AB1972D488004E0C3C /* SUGuidedPackageInstaller.m */,
|
||||
618FA4FF0DAE88B40026945C /* SUInstaller.h */,
|
||||
618FA5000DAE88B40026945C /* SUInstaller.m */,
|
||||
618FA5200DAE8E8A0026945C /* SUPackageInstaller.h */,
|
||||
@@ -884,10 +924,10 @@
|
||||
61B5F91D09C4CF7F00B25A18 /* Test Application */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
14732BBF1960F0AC00593899 /* test_app_only_dsa_pub.pem */,
|
||||
61B5F92A09C4CFD800B25A18 /* InfoPlist.strings */,
|
||||
61B5F92409C4CFC900B25A18 /* main.m */,
|
||||
61B5F92C09C4CFD800B25A18 /* MainMenu.xib */,
|
||||
14732BBF1960F0AC00593899 /* test_app_only_dsa_pub.pem */,
|
||||
61B5F90409C4CEE200B25A18 /* TestApplication-Info.plist */,
|
||||
);
|
||||
name = "Test Application";
|
||||
@@ -986,9 +1026,11 @@
|
||||
5D06E9390FD69271005AE3F6 /* SUBinaryDeltaUnarchiver.h in Headers */,
|
||||
61B078CE15A5FB6100600039 /* SUCodeSigningVerifier.h in Headers */,
|
||||
61299A5C09CA6D4500B7442F /* SUConstants.h in Headers */,
|
||||
14652F8419A978C200959E44 /* SUExport.h in Headers */,
|
||||
6102FE4A0E07803800F85D09 /* SUDiskImageUnarchiver.h in Headers */,
|
||||
61299A2F09CA2DAB00B7442F /* SUDSAVerifier.h in Headers */,
|
||||
55E6F33319EC9F6C00005E76 /* SUErrors.h in Headers */,
|
||||
14652F8419A978C200959E44 /* SUExport.h in Headers */,
|
||||
767B61AC1972D488004E0C3C /* SUGuidedPackageInstaller.h in Headers */,
|
||||
61EF67590E25C5B400F754E0 /* SUHost.h in Headers */,
|
||||
618FA5010DAE88B40026945C /* SUInstaller.h in Headers */,
|
||||
55C14F06136EF6DB00649790 /* SULog.h in Headers */,
|
||||
@@ -1011,7 +1053,6 @@
|
||||
6158A1C5137904B300487EC1 /* SUUpdater_Private.h in Headers */,
|
||||
61A354550DF113C70076ECB1 /* SUUserInitiatedUpdateDriver.h in Headers */,
|
||||
61A2259E0D1C495D00430CCD /* SUVersionComparisonProtocol.h in Headers */,
|
||||
55E6F33319EC9F6C00005E76 /* SUErrors.h in Headers */,
|
||||
3772FEA913DE0B6B00F79537 /* SUVersionDisplayProtocol.h in Headers */,
|
||||
61180BCA0D64138900B4E0D1 /* SUWindowController.h in Headers */,
|
||||
);
|
||||
@@ -1160,7 +1201,7 @@
|
||||
isa = PBXProject;
|
||||
attributes = {
|
||||
CLASSPREFIX = SU;
|
||||
LastUpgradeCheck = 0610;
|
||||
LastUpgradeCheck = 0630;
|
||||
ORGANIZATIONNAME = "Sparkle Project";
|
||||
TargetAttributes = {
|
||||
612279D80DB5470200AB99EA = {
|
||||
@@ -1237,8 +1278,11 @@
|
||||
isa = PBXResourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
14958C6F19AEBC980061B14F /* test-pubkey.pem in Resources */,
|
||||
14958C6E19AEBC950061B14F /* signed-test-file.txt in Resources */,
|
||||
F8761EB31ADC50EB000C9034 /* SparkleTestCodeSignApp.zip in Resources */,
|
||||
5AF6C1E91AE86E270014A3AB /* test archive.zip in Resources */,
|
||||
14958C6F19AEBC980061B14F /* test-pubkey.pem in Resources */,
|
||||
5AF6C74F1AEA46D10014A3AB /* test.sparkle_guided.pkg in Resources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
@@ -1256,10 +1300,10 @@
|
||||
isa = PBXResourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
14732BC01960F2C200593899 /* test_app_only_dsa_pub.pem in Resources */,
|
||||
1420DF50196247F900203BB0 /* Images.xcassets in Resources */,
|
||||
61B5F92E09C4CFD800B25A18 /* InfoPlist.strings in Resources */,
|
||||
61B5F92F09C4CFD800B25A18 /* MainMenu.xib in Resources */,
|
||||
14732BC01960F2C200593899 /* test_app_only_dsa_pub.pem in Resources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
@@ -1365,7 +1409,9 @@
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
55C14BD4136EEFCE00649790 /* Autoupdate.m in Sources */,
|
||||
F8761EB61ADC5E7A000C9034 /* SUCodeSigningVerifier.m in Sources */,
|
||||
55C14F00136EF6B700649790 /* SUConstants.m in Sources */,
|
||||
767B61AE1972D488004E0C3C /* SUGuidedPackageInstaller.m in Sources */,
|
||||
55C14F0C136EF6EA00649790 /* SUHost.m in Sources */,
|
||||
55C14F0D136EF6F200649790 /* SUInstaller.m in Sources */,
|
||||
55C14F08136EF6DB00649790 /* SULog.m in Sources */,
|
||||
@@ -1385,8 +1431,10 @@
|
||||
files = (
|
||||
5D06E8E90FD68CDB005AE3F6 /* bsdiff.c in Sources */,
|
||||
14652F7E19A9728A00959E44 /* bspatch.c in Sources */,
|
||||
7223E7631AD1AEFF008E3161 /* sais.c in Sources */,
|
||||
14652F7D19A9726700959E44 /* SUBinaryDeltaApply.m in Sources */,
|
||||
14652F7C19A9725300959E44 /* SUBinaryDeltaCommon.m in Sources */,
|
||||
7268AC631AD634C200C3E0C1 /* SUBinaryDeltaCreate.m in Sources */,
|
||||
5D06E8EA0FD68CDB005AE3F6 /* SUBinaryDeltaTool.m in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
@@ -1395,13 +1443,16 @@
|
||||
isa = PBXSourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
14652F8119A9744200959E44 /* SUBinaryDeltaCommon.m in Sources */,
|
||||
14652F7F19A973F900959E44 /* SUDSAVerifier.m in Sources */,
|
||||
14652F8219A9746000959E44 /* SULog.m in Sources */,
|
||||
5AF9DC3C1981DBEE001EA135 /* SUDSAVerifierTest.m in Sources */,
|
||||
721CF1A71AD7643600D9AC09 /* bsdiff.c in Sources */,
|
||||
721CF1A81AD7644100D9AC09 /* bspatch.c in Sources */,
|
||||
721CF1A91AD7644C00D9AC09 /* sais.c in Sources */,
|
||||
72D4DAA11AD7632900B211E2 /* SUBinaryDeltaCreate.m in Sources */,
|
||||
142E0E0919A83AAC00E4312B /* SUBinaryDeltaTest.m in Sources */,
|
||||
14950075195FDF5900BC5B5B /* SUUpdaterTest.m in Sources */,
|
||||
61227A160DB548B800AB99EA /* SUVersionComparisonTest.m in Sources */,
|
||||
F8761EB11ADC5068000C9034 /* SUCodeSigningVerifierTest.m in Sources */,
|
||||
5AF9DC3C1981DBEE001EA135 /* SUDSAVerifierTest.m in Sources */,
|
||||
5AF6C7541AEA49840014A3AB /* SUInstallerTest.m in Sources */,
|
||||
14652F8219A9746000959E44 /* SULog.m in Sources */,
|
||||
5AF6C1E51AE86A410014A3AB /* SUPipedUnarchiverTest.m in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
@@ -1431,6 +1482,7 @@
|
||||
61299A6009CA6EB100B7442F /* SUConstants.m in Sources */,
|
||||
6102FE4B0E07803800F85D09 /* SUDiskImageUnarchiver.m in Sources */,
|
||||
61299A3009CA2DAB00B7442F /* SUDSAVerifier.m in Sources */,
|
||||
767B61AD1972D488004E0C3C /* SUGuidedPackageInstaller.m in Sources */,
|
||||
61EF67560E25B58D00F754E0 /* SUHost.m in Sources */,
|
||||
618FA5020DAE88B40026945C /* SUInstaller.m in Sources */,
|
||||
55C14F07136EF6DB00649790 /* SULog.m in Sources */,
|
||||
@@ -1722,7 +1774,6 @@
|
||||
isa = XCBuildConfiguration;
|
||||
baseConfigurationReference = FA1941CA0D94A70100DD942E /* ConfigFrameworkDebug.xcconfig */;
|
||||
buildSettings = {
|
||||
DEFINES_MODULE = YES;
|
||||
};
|
||||
name = Debug;
|
||||
};
|
||||
@@ -1730,7 +1781,6 @@
|
||||
isa = XCBuildConfiguration;
|
||||
baseConfigurationReference = FA1941D50D94A70100DD942E /* ConfigFrameworkRelease.xcconfig */;
|
||||
buildSettings = {
|
||||
DEFINES_MODULE = YES;
|
||||
};
|
||||
name = Release;
|
||||
};
|
||||
@@ -1738,7 +1788,6 @@
|
||||
isa = XCBuildConfiguration;
|
||||
baseConfigurationReference = FA1941CF0D94A70100DD942E /* ConfigCommonDebug.xcconfig */;
|
||||
buildSettings = {
|
||||
CLANG_ENABLE_MODULES = YES;
|
||||
};
|
||||
name = Debug;
|
||||
};
|
||||
@@ -1746,7 +1795,6 @@
|
||||
isa = XCBuildConfiguration;
|
||||
baseConfigurationReference = FA1941CC0D94A70100DD942E /* ConfigCommonRelease.xcconfig */;
|
||||
buildSettings = {
|
||||
CLANG_ENABLE_MODULES = YES;
|
||||
};
|
||||
name = Release;
|
||||
};
|
||||
@@ -1754,7 +1802,6 @@
|
||||
isa = XCBuildConfiguration;
|
||||
baseConfigurationReference = FA1941D30D94A70100DD942E /* ConfigRelaunchDebug.xcconfig */;
|
||||
buildSettings = {
|
||||
CLANG_ENABLE_MODULES = NO;
|
||||
};
|
||||
name = Debug;
|
||||
};
|
||||
@@ -1762,7 +1809,6 @@
|
||||
isa = XCBuildConfiguration;
|
||||
baseConfigurationReference = FA1941D40D94A70100DD942E /* ConfigRelaunchRelease.xcconfig */;
|
||||
buildSettings = {
|
||||
CLANG_ENABLE_MODULES = NO;
|
||||
};
|
||||
name = Release;
|
||||
};
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Scheme
|
||||
LastUpgradeVersion = "0610"
|
||||
LastUpgradeVersion = "0630"
|
||||
version = "1.3">
|
||||
<BuildAction
|
||||
parallelizeBuildables = "YES"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Scheme
|
||||
LastUpgradeVersion = "0610"
|
||||
LastUpgradeVersion = "0630"
|
||||
version = "2.0">
|
||||
<BuildAction
|
||||
parallelizeBuildables = "YES"
|
||||
|
||||
@@ -18,7 +18,7 @@ static const NSTimeInterval SUInstallationTimeLimit = 5;
|
||||
*/
|
||||
static const NSTimeInterval SUParentQuitCheckInterval = .25;
|
||||
|
||||
@interface TerminationListener : NSObject <SUInstallerDelegate>
|
||||
@interface TerminationListener : NSObject
|
||||
|
||||
@property (copy) NSString *hostpath;
|
||||
@property (copy) NSString *executablepath;
|
||||
@@ -158,40 +158,37 @@ static const NSTimeInterval SUParentQuitCheckInterval = .25;
|
||||
|
||||
[self.statusController close]; // If there's an existing status controller, close it before we release our strong reference to it.
|
||||
self.statusController = statusCtl; // Keep a strong reference to the status controller, or else it might get prematurely deallocated.
|
||||
}
|
||||
}
|
||||
|
||||
[SUInstaller installFromUpdateFolder:self.folderpath
|
||||
overHost:self.host
|
||||
installationPath:self.installationPath
|
||||
delegate:self
|
||||
versionComparator:[SUStandardVersionComparator defaultComparator]];
|
||||
}
|
||||
|
||||
- (void)installerFinishedForHost:(SUHost *)__unused aHost
|
||||
{
|
||||
[self relaunch];
|
||||
}
|
||||
|
||||
- (void)installerForHost:(SUHost *)__unused host failedWithError:(NSError *)error __attribute__((noreturn))
|
||||
{
|
||||
if (self.shouldShowUI)
|
||||
NSRunAlertPanel(@"", @"%@", @"OK", @"", @"", [error localizedDescription]);
|
||||
exit(EXIT_FAILURE);
|
||||
versionComparator:[SUStandardVersionComparator defaultComparator]
|
||||
completionHandler:^(NSError *error) {
|
||||
if (error) {
|
||||
if (self.shouldShowUI) {
|
||||
NSRunAlertPanel(@"", @"%@", @"OK", @"", @"", [error localizedDescription]);
|
||||
}
|
||||
exit(EXIT_FAILURE);
|
||||
} else {
|
||||
[self relaunch];
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
int main(int __unused argc, const char __unused *argv[])
|
||||
{
|
||||
@autoreleasepool {
|
||||
@autoreleasepool
|
||||
{
|
||||
NSArray *args = [[NSProcessInfo processInfo] arguments];
|
||||
if (args.count < 5 || args.count > 7) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
BOOL shouldShowUI = (args.count > 6) ? [args[6] boolValue] : YES;
|
||||
if (shouldShowUI)
|
||||
{
|
||||
if (shouldShowUI) {
|
||||
[[NSApplication sharedApplication] activateIgnoringOtherApps:YES];
|
||||
}
|
||||
|
||||
@@ -204,9 +201,9 @@ int main(int __unused argc, const char __unused *argv[])
|
||||
shouldShowUI:shouldShowUI
|
||||
selfPath:[[NSBundle mainBundle] bundlePath]];
|
||||
|
||||
[termListen class];
|
||||
[[NSApplication sharedApplication] run];
|
||||
|
||||
// Ensure termListen is not deallocated by ARC before caling -[NSApplication run]
|
||||
[termListen class];
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
|
||||
@@ -12,22 +12,15 @@
|
||||
#import <Foundation/NSURLDownload.h>
|
||||
#import "SUExport.h"
|
||||
|
||||
@protocol SUAppcastDelegate;
|
||||
|
||||
@class SUAppcastItem;
|
||||
SU_EXPORT @interface SUAppcast : NSObject <NSURLDownloadDelegate>
|
||||
SU_EXPORT @interface SUAppcast : NSObject<NSURLDownloadDelegate>
|
||||
|
||||
@property (weak) id<SUAppcastDelegate> delegate;
|
||||
@property (copy) NSString *userAgentString;
|
||||
@property (copy) NSDictionary *httpHeaders;
|
||||
|
||||
- (void)fetchAppcastFromURL:(NSURL *)url;
|
||||
- (void)fetchAppcastFromURL:(NSURL *)url completionBlock:(void (^)(NSError *))err;
|
||||
|
||||
@property (readonly, copy) NSArray *items;
|
||||
@end
|
||||
|
||||
@protocol SUAppcastDelegate <NSObject>
|
||||
- (void)appcastDidFinishLoading:(SUAppcast *)appcast;
|
||||
- (void)appcast:(SUAppcast *)appcast failedToLoadWithError:(NSError *)error;
|
||||
@end
|
||||
|
||||
#endif
|
||||
@@ -33,6 +33,7 @@
|
||||
@end
|
||||
|
||||
@interface SUAppcast () <NSURLDownloadDelegate>
|
||||
@property (strong) void (^completionBlock)(NSError *);
|
||||
@property (copy) NSString *downloadFilename;
|
||||
@property (strong) NSURLDownload *download;
|
||||
@property (copy) NSArray *items;
|
||||
@@ -43,18 +44,28 @@
|
||||
@implementation SUAppcast
|
||||
|
||||
@synthesize downloadFilename;
|
||||
@synthesize delegate;
|
||||
@synthesize completionBlock;
|
||||
@synthesize userAgentString;
|
||||
@synthesize httpHeaders;
|
||||
@synthesize download;
|
||||
@synthesize items;
|
||||
|
||||
- (void)fetchAppcastFromURL:(NSURL *)url
|
||||
- (void)fetchAppcastFromURL:(NSURL *)url completionBlock:(void (^)(NSError *))block
|
||||
{
|
||||
self.completionBlock = block;
|
||||
|
||||
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:30.0];
|
||||
if (self.userAgentString) {
|
||||
[request setValue:self.userAgentString forHTTPHeaderField:@"User-Agent"];
|
||||
}
|
||||
|
||||
if (self.httpHeaders) {
|
||||
for (NSString *key in self.httpHeaders) {
|
||||
id value = [self.httpHeaders objectForKey:key];
|
||||
[request setValue:value forHTTPHeaderField:key];
|
||||
}
|
||||
}
|
||||
|
||||
[request setValue:@"application/rss+xml,*/*;q=0.1" forHTTPHeaderField:@"Accept"];
|
||||
|
||||
self.download = [[NSURLDownload alloc] initWithRequest:request delegate:self];
|
||||
@@ -202,27 +213,23 @@
|
||||
}
|
||||
}
|
||||
|
||||
if ([appcastItems count])
|
||||
{
|
||||
if ([appcastItems count]) {
|
||||
NSSortDescriptor *sort = [[NSSortDescriptor alloc] initWithKey:@"date" ascending:NO];
|
||||
[appcastItems sortUsingDescriptors:@[sort]];
|
||||
self.items = appcastItems;
|
||||
}
|
||||
|
||||
if (failed)
|
||||
{
|
||||
if (failed) {
|
||||
[self reportError:[NSError errorWithDomain:SUSparkleErrorDomain code:SUAppcastParseError userInfo:@{ NSLocalizedDescriptionKey: SULocalizedString(@"An error occurred while parsing the update feed.", nil) }]];
|
||||
}
|
||||
else if ([self.delegate respondsToSelector:@selector(appcastDidFinishLoading:)])
|
||||
{
|
||||
[self.delegate appcastDidFinishLoading:self];
|
||||
} else {
|
||||
self.completionBlock(nil);
|
||||
self.completionBlock = nil;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)download:(NSURLDownload *)__unused aDownload didFailWithError:(NSError *)error
|
||||
{
|
||||
if (self.downloadFilename)
|
||||
{
|
||||
if (self.downloadFilename) {
|
||||
[[NSFileManager defaultManager] removeItemAtPath:self.downloadFilename error:nil];
|
||||
}
|
||||
self.downloadFilename = nil;
|
||||
@@ -237,10 +244,12 @@
|
||||
|
||||
- (void)reportError:(NSError *)error
|
||||
{
|
||||
if ([self.delegate respondsToSelector:@selector(appcast:failedToLoadWithError:)])
|
||||
{
|
||||
[self.delegate appcast:self failedToLoadWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SUAppcastError userInfo:@{NSLocalizedDescriptionKey: SULocalizedString(@"An error occurred in retrieving update information. Please try again later.", nil), NSLocalizedFailureReasonErrorKey: [error localizedDescription]}]];
|
||||
}
|
||||
self.completionBlock([NSError errorWithDomain:SUSparkleErrorDomain code:SUAppcastError userInfo:@{
|
||||
NSLocalizedDescriptionKey: SULocalizedString(@"An error occurred in retrieving update information. Please try again later.", nil),
|
||||
NSLocalizedFailureReasonErrorKey: [error localizedDescription],
|
||||
NSUnderlyingErrorKey: error,
|
||||
}]);
|
||||
self.completionBlock = nil;
|
||||
}
|
||||
|
||||
- (NSXMLNode *)bestNodeInNodes:(NSArray *)nodes
|
||||
|
||||
@@ -11,8 +11,6 @@
|
||||
|
||||
#import "SUWindowController.h"
|
||||
|
||||
@protocol SUAutomaticUpdateAlertDelegate;
|
||||
|
||||
typedef NS_ENUM(NSInteger, SUAutomaticInstallationChoice) {
|
||||
SUInstallNowChoice,
|
||||
SUInstallLaterChoice,
|
||||
@@ -22,15 +20,11 @@ typedef NS_ENUM(NSInteger, SUAutomaticInstallationChoice) {
|
||||
@class SUAppcastItem, SUHost;
|
||||
@interface SUAutomaticUpdateAlert : SUWindowController
|
||||
|
||||
- (instancetype)initWithAppcastItem:(SUAppcastItem *)item host:(SUHost *)hostBundle delegate:(id<SUAutomaticUpdateAlertDelegate>)delegate;
|
||||
- (instancetype)initWithAppcastItem:(SUAppcastItem *)item host:(SUHost *)hostBundle completionBlock:(void (^)(SUAutomaticInstallationChoice))c;
|
||||
- (IBAction)installNow:sender;
|
||||
- (IBAction)installLater:sender;
|
||||
- (IBAction)doNotInstall:sender;
|
||||
|
||||
@end
|
||||
|
||||
@protocol SUAutomaticUpdateAlertDelegate <NSObject>
|
||||
- (void)automaticUpdateAlert:(SUAutomaticUpdateAlert *)aua finishedWithChoice:(SUAutomaticInstallationChoice)choice;
|
||||
@end
|
||||
|
||||
#endif
|
||||
@@ -11,23 +11,22 @@
|
||||
#import "SUHost.h"
|
||||
|
||||
@interface SUAutomaticUpdateAlert ()
|
||||
@property (strong) void(^completionBlock)(SUAutomaticInstallationChoice);
|
||||
@property (strong) SUAppcastItem *updateItem;
|
||||
@property (weak) id<SUAutomaticUpdateAlertDelegate> delegate;
|
||||
@property (strong) SUHost *host;
|
||||
@end
|
||||
|
||||
@implementation SUAutomaticUpdateAlert
|
||||
@synthesize delegate;
|
||||
@synthesize host;
|
||||
@synthesize updateItem;
|
||||
@synthesize completionBlock;
|
||||
|
||||
- (instancetype)initWithAppcastItem:(SUAppcastItem *)item host:(SUHost *)aHost delegate:(id<SUAutomaticUpdateAlertDelegate>)del
|
||||
- (instancetype)initWithAppcastItem:(SUAppcastItem *)item host:(SUHost *)aHost completionBlock:(void (^)(SUAutomaticInstallationChoice))block
|
||||
{
|
||||
self = [super initWithHost:aHost windowNibName:@"SUAutomaticUpdateAlert"];
|
||||
if (self)
|
||||
{
|
||||
self = [super initWithWindowNibName:@"SUAutomaticUpdateAlert"];
|
||||
if (self) {
|
||||
self.updateItem = item;
|
||||
self.delegate = del;
|
||||
self.completionBlock = block;
|
||||
self.host = aHost;
|
||||
[self setShouldCascadeWindows:NO];
|
||||
[[self window] center];
|
||||
@@ -40,19 +39,22 @@
|
||||
- (IBAction)installNow:(id)__unused sender
|
||||
{
|
||||
[self close];
|
||||
[self.delegate automaticUpdateAlert:self finishedWithChoice:SUInstallNowChoice];
|
||||
self.completionBlock(SUInstallNowChoice);
|
||||
self.completionBlock = nil;
|
||||
}
|
||||
|
||||
- (IBAction)installLater:(id)__unused sender
|
||||
{
|
||||
[self close];
|
||||
[self.delegate automaticUpdateAlert:self finishedWithChoice:SUInstallLaterChoice];
|
||||
self.completionBlock(SUInstallLaterChoice);
|
||||
self.completionBlock = nil;
|
||||
}
|
||||
|
||||
- (IBAction)doNotInstall:(id)__unused sender
|
||||
{
|
||||
[self close];
|
||||
[self.delegate automaticUpdateAlert:self finishedWithChoice:SUDoNotInstallChoice];
|
||||
self.completionBlock(SUDoNotInstallChoice);
|
||||
self.completionBlock = nil;
|
||||
}
|
||||
|
||||
- (NSImage *)applicationIcon
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
#import "SUBasicUpdateDriver.h"
|
||||
#import "SUAutomaticUpdateAlert.h"
|
||||
|
||||
@interface SUAutomaticUpdateDriver : SUBasicUpdateDriver <SUUnarchiverDelegate, SUAutomaticUpdateAlertDelegate>
|
||||
@interface SUAutomaticUpdateDriver : SUBasicUpdateDriver <SUUnarchiverDelegate>
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@@ -42,13 +42,14 @@ static const NSTimeInterval SUAutomaticUpdatePromptImpatienceTimer = 60 * 60 * 2
|
||||
- (void)showUpdateAlert
|
||||
{
|
||||
self.interruptible = NO;
|
||||
self.alert = [[SUAutomaticUpdateAlert alloc] initWithAppcastItem:self.updateItem host:self.host delegate:self];
|
||||
self.alert = [[SUAutomaticUpdateAlert alloc] initWithAppcastItem:self.updateItem host:self.host completionBlock:^(SUAutomaticInstallationChoice choice) {
|
||||
[self automaticUpdateAlertFinishedWithChoice:choice];
|
||||
}];
|
||||
|
||||
// If the app is a menubar app or the like, we need to focus it first and alter the
|
||||
// update prompt to behave like a normal window. Otherwise if the window were hidden
|
||||
// there may be no way for the application to be activated to make it visible again.
|
||||
if ([self.host isBackgroundApplication])
|
||||
{
|
||||
if ([self.host isBackgroundApplication]) {
|
||||
[[self.alert window] setHidesOnDeactivate:NO];
|
||||
[NSApp activateIgnoringOtherApps:YES];
|
||||
}
|
||||
@@ -138,7 +139,7 @@ static const NSTimeInterval SUAutomaticUpdatePromptImpatienceTimer = 60 * 60 * 2
|
||||
[[NSNotificationCenter defaultCenter] removeObserver:self name:NSApplicationDidBecomeActiveNotification object:NSApp];
|
||||
}
|
||||
|
||||
- (void)automaticUpdateAlert:(SUAutomaticUpdateAlert *)__unused aua finishedWithChoice:(SUAutomaticInstallationChoice)choice
|
||||
- (void)automaticUpdateAlertFinishedWithChoice:(SUAutomaticInstallationChoice)choice
|
||||
{
|
||||
switch (choice)
|
||||
{
|
||||
@@ -161,8 +162,6 @@ static const NSTimeInterval SUAutomaticUpdatePromptImpatienceTimer = 60 * 60 * 2
|
||||
}
|
||||
}
|
||||
|
||||
- (BOOL)shouldInstallSynchronously { return self.postponingInstallation; }
|
||||
|
||||
- (void)installWithToolAndRelaunch:(BOOL)relaunch displayingUserInterface:(BOOL)showUI
|
||||
{
|
||||
if (relaunch) {
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
#import "SUAppcast.h"
|
||||
|
||||
@class SUAppcastItem, SUHost;
|
||||
@interface SUBasicUpdateDriver : SUUpdateDriver <NSURLDownloadDelegate, SUUnarchiverDelegate, SUAppcastDelegate>
|
||||
@interface SUBasicUpdateDriver : SUUpdateDriver <NSURLDownloadDelegate, SUUnarchiverDelegate>
|
||||
|
||||
@property (strong, readonly) SUAppcastItem *updateItem;
|
||||
@property (strong, readonly) NSURLDownload *download;
|
||||
|
||||
@@ -54,9 +54,15 @@
|
||||
|
||||
SUAppcast *appcast = [[SUAppcast alloc] init];
|
||||
|
||||
[appcast setDelegate:self];
|
||||
[appcast setUserAgentString:[self.updater userAgentString]];
|
||||
[appcast fetchAppcastFromURL:URL];
|
||||
[appcast setHttpHeaders:[self.updater httpHeaders]];
|
||||
[appcast fetchAppcastFromURL:URL completionBlock:^(NSError *error) {
|
||||
if (error) {
|
||||
[self abortUpdateWithError:error];
|
||||
} else {
|
||||
[self appcastDidFinishLoading:appcast];
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
||||
- (id<SUVersionComparison>)versionComparator
|
||||
@@ -136,12 +142,10 @@
|
||||
item = [updateEnumerator nextObject];
|
||||
} while (item && ![self hostSupportsItem:item]);
|
||||
|
||||
if (binaryDeltaSupported()) {
|
||||
SUAppcastItem *deltaUpdateItem = [item deltaUpdates][[self.host version]];
|
||||
if (deltaUpdateItem && [self hostSupportsItem:deltaUpdateItem]) {
|
||||
self.nonDeltaUpdateItem = item;
|
||||
item = deltaUpdateItem;
|
||||
}
|
||||
SUAppcastItem *deltaUpdateItem = [item deltaUpdates][[self.host version]];
|
||||
if (deltaUpdateItem && [self hostSupportsItem:deltaUpdateItem]) {
|
||||
self.nonDeltaUpdateItem = item;
|
||||
item = deltaUpdateItem;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -154,11 +158,6 @@
|
||||
}
|
||||
}
|
||||
|
||||
- (void)appcast:(SUAppcast *)__unused ac failedToLoadWithError:(NSError *)error
|
||||
{
|
||||
[self abortUpdateWithError:error];
|
||||
}
|
||||
|
||||
- (void)didFindValidUpdate
|
||||
{
|
||||
assert(self.updateItem);
|
||||
@@ -227,7 +226,7 @@
|
||||
if (newBundlePath) {
|
||||
if ([SUCodeSigningVerifier hostApplicationIsCodeSigned]) {
|
||||
NSError *error = nil;
|
||||
if ([SUCodeSigningVerifier codeSignatureIsValidAtPath:newBundlePath error:&error]) {
|
||||
if ([SUCodeSigningVerifier codeSignatureMatchesHostAndIsValidAtPath:newBundlePath error:&error]) {
|
||||
return YES;
|
||||
} else {
|
||||
SULog(@"Code signature check on update failed: %@. Sparkle will use DSA signature instead.", error);
|
||||
@@ -254,7 +253,10 @@
|
||||
|
||||
- (void)download:(NSURLDownload *)__unused download didFailWithError:(NSError *)error
|
||||
{
|
||||
[self abortUpdateWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SURelaunchError userInfo:@{NSLocalizedDescriptionKey: SULocalizedString(@"An error occurred while downloading the update. Please try again later.", nil), NSLocalizedFailureReasonErrorKey: [error localizedDescription]}]];
|
||||
[self abortUpdateWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SURelaunchError userInfo:@{
|
||||
NSLocalizedDescriptionKey: SULocalizedString(@"An error occurred while downloading the update. Please try again later.", nil),
|
||||
NSUnderlyingErrorKey: error,
|
||||
}]];
|
||||
}
|
||||
|
||||
- (BOOL)download:(NSURLDownload *)__unused download shouldDecodeSourceDataOfMIMEType:(NSString *)encodingType
|
||||
@@ -266,14 +268,13 @@
|
||||
|
||||
- (void)extractUpdate
|
||||
{
|
||||
SUUnarchiver *unarchiver = [SUUnarchiver unarchiverForPath:self.downloadPath updatingHost:self.host];
|
||||
if (!unarchiver)
|
||||
{
|
||||
SUUnarchiver *unarchiver = [SUUnarchiver unarchiverForPath:self.downloadPath updatingHostBundlePath:[[self.host bundle] bundlePath]];
|
||||
if (!unarchiver) {
|
||||
SULog(@"Error: No valid unarchiver for %@!", self.downloadPath);
|
||||
[self unarchiverDidFail:nil];
|
||||
return;
|
||||
}
|
||||
[unarchiver setDelegate:self];
|
||||
unarchiver.delegate = self;
|
||||
[unarchiver start];
|
||||
}
|
||||
|
||||
@@ -303,8 +304,6 @@
|
||||
[self abortUpdateWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SUUnarchivingError userInfo:@{ NSLocalizedDescriptionKey: SULocalizedString(@"An error occurred while extracting the archive. Please try again later.", nil) }]];
|
||||
}
|
||||
|
||||
- (BOOL)shouldInstallSynchronously { return NO; }
|
||||
|
||||
- (void)installWithToolAndRelaunch:(BOOL)relaunch
|
||||
{
|
||||
// Perhaps a poor assumption but: if we're not relaunching, we assume we shouldn't be showing any UI either. Because non-relaunching installations are kicked off without any user interaction, we shouldn't be interrupting them.
|
||||
@@ -356,27 +355,32 @@
|
||||
// Copy the relauncher into a temporary directory so we can get to it after the new version's installed.
|
||||
// Only the paranoid survive: if there's already a stray copy of relaunch there, we would have problems.
|
||||
NSString *const relaunchPathToCopy = [sparkleBundle pathForResource:[[sparkleBundle infoDictionary] objectForKey:SURelaunchToolNameKey] ofType:@"app"];
|
||||
if (relaunchPathToCopy != nil)
|
||||
{
|
||||
if (relaunchPathToCopy != nil) {
|
||||
NSString *targetPath = [self.host.appCachePath stringByAppendingPathComponent:[relaunchPathToCopy lastPathComponent]];
|
||||
// Only the paranoid survive: if there's already a stray copy of relaunch there, we would have problems.
|
||||
NSError *error = nil;
|
||||
[[NSFileManager defaultManager] createDirectoryAtPath:[targetPath stringByDeletingLastPathComponent] withIntermediateDirectories:YES attributes:@{} error:&error];
|
||||
|
||||
if ([SUPlainInstaller copyPathWithAuthentication:relaunchPathToCopy overPath:targetPath temporaryName:nil error:&error])
|
||||
if ([SUPlainInstaller copyPathWithAuthentication:relaunchPathToCopy overPath:targetPath temporaryName:nil error:&error]) {
|
||||
self.relaunchPath = targetPath;
|
||||
else
|
||||
[self abortUpdateWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SURelaunchError userInfo:@{NSLocalizedDescriptionKey: SULocalizedString(@"An error occurred while extracting the archive. Please try again later.", nil), NSLocalizedFailureReasonErrorKey: [NSString stringWithFormat:@"Couldn't copy relauncher (%@) to temporary path (%@)! %@", relaunchPathToCopy, targetPath, (error ? [error localizedDescription] : @"")]}]];
|
||||
} else {
|
||||
[self abortUpdateWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SURelaunchError userInfo:@{
|
||||
NSLocalizedDescriptionKey: SULocalizedString(@"An error occurred while extracting the archive. Please try again later.", nil),
|
||||
NSLocalizedFailureReasonErrorKey: [NSString stringWithFormat:@"Couldn't copy relauncher (%@) to temporary path (%@)! %@", relaunchPathToCopy, targetPath, (error ? [error localizedDescription] : @"")]
|
||||
}]];
|
||||
}
|
||||
}
|
||||
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:SUUpdaterWillRestartNotification object:self];
|
||||
if ([updaterDelegate respondsToSelector:@selector(updaterWillRelaunchApplication:)])
|
||||
[updaterDelegate updaterWillRelaunchApplication:self.updater];
|
||||
|
||||
if(!self.relaunchPath || ![[NSFileManager defaultManager] fileExistsAtPath:self.relaunchPath])
|
||||
{
|
||||
if (!self.relaunchPath || ![[NSFileManager defaultManager] fileExistsAtPath:self.relaunchPath]) {
|
||||
// Note that we explicitly use the host app's name here, since updating plugin for Mail relaunches Mail, not just the plugin.
|
||||
[self abortUpdateWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SURelaunchError userInfo:@{NSLocalizedDescriptionKey: [NSString stringWithFormat:SULocalizedString(@"An error occurred while relaunching %1$@, but the new version will be available next time you run %1$@.", nil), [self.host name]], NSLocalizedFailureReasonErrorKey: [NSString stringWithFormat:@"Couldn't find the relauncher (expected to find it at %@)", self.relaunchPath]}]];
|
||||
[self abortUpdateWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SURelaunchError userInfo:@{
|
||||
NSLocalizedDescriptionKey: [NSString stringWithFormat:SULocalizedString(@"An error occurred while relaunching %1$@, but the new version will be available next time you run %1$@.", nil), [self.host name]],
|
||||
NSLocalizedFailureReasonErrorKey: [NSString stringWithFormat:@"Couldn't find the relauncher (expected to find it at %@)", self.relaunchPath]
|
||||
}]];
|
||||
// We intentionally don't abandon the update here so that the host won't initiate another.
|
||||
return;
|
||||
}
|
||||
@@ -414,10 +418,16 @@
|
||||
|
||||
- (void)installerForHost:(SUHost *)aHost failedWithError:(NSError *)error
|
||||
{
|
||||
if (aHost != self.host) { return; }
|
||||
if (aHost != self.host) {
|
||||
return;
|
||||
}
|
||||
NSError *dontThrow = nil;
|
||||
[[NSFileManager defaultManager] removeItemAtPath:self.relaunchPath error:&dontThrow]; // Clean up the copied relauncher
|
||||
[self abortUpdateWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SUInstallationError userInfo:@{NSLocalizedDescriptionKey: SULocalizedString(@"An error occurred while installing the update. Please try again later.", nil), NSLocalizedFailureReasonErrorKey: [error localizedDescription]}]];
|
||||
[self abortUpdateWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SUInstallationError userInfo:@{
|
||||
NSLocalizedDescriptionKey: SULocalizedString(@"An error occurred while installing the update. Please try again later.", nil),
|
||||
NSLocalizedFailureReasonErrorKey: [error localizedDescription],
|
||||
NSUnderlyingErrorKey: error,
|
||||
}]];
|
||||
}
|
||||
|
||||
- (void)abortUpdate
|
||||
|
||||
@@ -10,6 +10,6 @@
|
||||
#define SUBINARYDELTAAPPLY_H
|
||||
|
||||
@class NSString;
|
||||
int applyBinaryDelta(NSString *source, NSString *destination, NSString *patchFile);
|
||||
int applyBinaryDelta(NSString *source, NSString *destination, NSString *patchFile, BOOL verbose);
|
||||
|
||||
#endif
|
||||
@@ -15,57 +15,125 @@
|
||||
#include <stdlib.h>
|
||||
#include <xar/xar.h>
|
||||
|
||||
static void applyBinaryDeltaToFile(xar_t x, xar_file_t file, NSString *sourceFilePath, NSString *destinationFilePath)
|
||||
static BOOL applyBinaryDeltaToFile(xar_t x, xar_file_t file, NSString *sourceFilePath, NSString *destinationFilePath)
|
||||
{
|
||||
NSString *patchFile = temporaryFilename(@"apply-binary-delta");
|
||||
xar_extract_tofile(x, file, [patchFile fileSystemRepresentation]);
|
||||
const char *argv[] = {"/usr/bin/bspatch", [sourceFilePath fileSystemRepresentation], [destinationFilePath fileSystemRepresentation], [patchFile fileSystemRepresentation]};
|
||||
bspatch(4, (char **)argv);
|
||||
BOOL success = (bspatch(4, (char **)argv) == 0);
|
||||
unlink([patchFile fileSystemRepresentation]);
|
||||
return success;
|
||||
}
|
||||
|
||||
int applyBinaryDelta(NSString *source, NSString *destination, NSString *patchFile)
|
||||
int applyBinaryDelta(NSString *source, NSString *destination, NSString *patchFile, BOOL verbose)
|
||||
{
|
||||
xar_t x = xar_open([patchFile UTF8String], READ);
|
||||
xar_t x = xar_open([patchFile fileSystemRepresentation], READ);
|
||||
if (!x) {
|
||||
fprintf(stderr, "Unable to open %s. Giving up.\n", [patchFile UTF8String]);
|
||||
fprintf(stderr, "Unable to open %s. Giving up.\n", [patchFile fileSystemRepresentation]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
SUBinaryDeltaMajorVersion majorDiffVersion = FIRST_DELTA_DIFF_MAJOR_VERSION;
|
||||
SUBinaryDeltaMinorVersion minorDiffVersion = FIRST_DELTA_DIFF_MINOR_VERSION;
|
||||
|
||||
NSString *expectedBeforeHash = nil;
|
||||
NSString *expectedAfterHash = nil;
|
||||
NSString *expectedBeforeHashv1 = nil;
|
||||
NSString *expectedAfterHashv1 = nil;
|
||||
|
||||
NSString *expectedNewBeforeHash = nil;
|
||||
NSString *expectedNewAfterHash = nil;
|
||||
|
||||
xar_subdoc_t subdoc;
|
||||
for (subdoc = xar_subdoc_first(x); subdoc; subdoc = xar_subdoc_next(subdoc)) {
|
||||
if (!strcmp(xar_subdoc_name(subdoc), "binary-delta-attributes")) {
|
||||
if (!strcmp(xar_subdoc_name(subdoc), BINARY_DELTA_ATTRIBUTES_KEY)) {
|
||||
const char *value = 0;
|
||||
xar_subdoc_prop_get(subdoc, "before-sha1", &value);
|
||||
|
||||
// available in version 2.0 or later
|
||||
xar_subdoc_prop_get(subdoc, MAJOR_DIFF_VERSION_KEY, &value);
|
||||
if (value)
|
||||
expectedBeforeHash = @(value);
|
||||
|
||||
xar_subdoc_prop_get(subdoc, "after-sha1", &value);
|
||||
majorDiffVersion = (SUBinaryDeltaMajorVersion)[@(value) intValue];
|
||||
|
||||
// available in version 2.0 or later
|
||||
xar_subdoc_prop_get(subdoc, MINOR_DIFF_VERSION_KEY, &value);
|
||||
if (value)
|
||||
expectedAfterHash = @(value);
|
||||
minorDiffVersion = (SUBinaryDeltaMinorVersion)[@(value) intValue];
|
||||
|
||||
// available in version 2.0 or later
|
||||
xar_subdoc_prop_get(subdoc, BEFORE_TREE_SHA1_KEY, &value);
|
||||
if (value)
|
||||
expectedNewBeforeHash = @(value);
|
||||
|
||||
// available in version 2.0 or later
|
||||
xar_subdoc_prop_get(subdoc, AFTER_TREE_SHA1_KEY, &value);
|
||||
if (value)
|
||||
expectedNewAfterHash = @(value);
|
||||
|
||||
// only available in version 1.0
|
||||
xar_subdoc_prop_get(subdoc, BEFORE_TREE_SHA1_OLD_KEY, &value);
|
||||
if (value)
|
||||
expectedBeforeHashv1 = @(value);
|
||||
|
||||
// only available in version 1.0
|
||||
xar_subdoc_prop_get(subdoc, AFTER_TREE_SHA1_OLD_KEY, &value);
|
||||
if (value)
|
||||
expectedAfterHashv1 = @(value);
|
||||
}
|
||||
}
|
||||
|
||||
if (majorDiffVersion < FIRST_DELTA_DIFF_MAJOR_VERSION) {
|
||||
fprintf(stderr, "Unable to identify diff-version %u in delta. Giving up.\n", majorDiffVersion);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (majorDiffVersion > LATEST_DELTA_DIFF_MAJOR_VERSION) {
|
||||
fprintf(stderr, "A later version is needed to apply this patch (on major version %u, but patch requests version %u).\n", LATEST_DELTA_DIFF_MAJOR_VERSION, majorDiffVersion);
|
||||
return 1;
|
||||
}
|
||||
|
||||
BOOL usesNewTreeHash = MAJOR_VERSION_IS_AT_LEAST(majorDiffVersion, SUBeigeMajorVersion);
|
||||
|
||||
NSString *expectedBeforeHash = usesNewTreeHash ? expectedNewBeforeHash : expectedBeforeHashv1;
|
||||
NSString *expectedAfterHash = usesNewTreeHash ? expectedNewAfterHash : expectedAfterHashv1;
|
||||
|
||||
if (!expectedBeforeHash || !expectedAfterHash) {
|
||||
fprintf(stderr, "Unable to find before-sha1 or after-sha1 metadata in delta. Giving up.\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
fprintf(stderr, "Verifying source... ");
|
||||
NSString *beforeHash = hashOfTree(source);
|
||||
|
||||
if (![beforeHash isEqualToString:expectedBeforeHash]) {
|
||||
fprintf(stderr, "Source doesn't have expected hash (%s != %s). Giving up.\n", [expectedBeforeHash UTF8String], [beforeHash UTF8String]);
|
||||
if (verbose) {
|
||||
fprintf(stderr, "Applying version %u.%u patch...\n", majorDiffVersion, minorDiffVersion);
|
||||
fprintf(stderr, "Verifying source...");
|
||||
}
|
||||
|
||||
NSString *beforeHash = hashOfTreeWithVersion(source, majorDiffVersion);
|
||||
if (!beforeHash) {
|
||||
fprintf(stderr, "\nUnable to calculate hash of tree %s\n", [source fileSystemRepresentation]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
fprintf(stderr, "\nCopying files... ");
|
||||
removeTree(destination);
|
||||
copyTree(source, destination);
|
||||
if (![beforeHash isEqualToString:expectedBeforeHash]) {
|
||||
fprintf(stderr, "\nSource doesn't have expected hash (%s != %s). Giving up.\n", [expectedBeforeHash UTF8String], [beforeHash UTF8String]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
fprintf(stderr, "\nPatching... ");
|
||||
if (verbose) {
|
||||
fprintf(stderr, "\nCopying files...");
|
||||
}
|
||||
|
||||
if (!removeTree(destination)) {
|
||||
fprintf(stderr, "\nFailed to remove %s\n", [destination fileSystemRepresentation]);
|
||||
return 1;
|
||||
}
|
||||
if (!copyTree(source, destination)) {
|
||||
fprintf(stderr, "\nFailed to copy %s to %s\n", [source fileSystemRepresentation], [destination fileSystemRepresentation]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
BOOL hasExtractKeyAvailable = MAJOR_VERSION_IS_AT_LEAST(majorDiffVersion, SUBeigeMajorVersion);
|
||||
|
||||
if (verbose) {
|
||||
fprintf(stderr, "\nPatching...");
|
||||
}
|
||||
NSFileManager *fileManager = [[NSFileManager alloc] init];
|
||||
xar_file_t file;
|
||||
xar_iter_t iter = xar_iter_new();
|
||||
for (file = xar_file_first(x, iter); file; file = xar_file_next(iter)) {
|
||||
@@ -73,29 +141,86 @@ int applyBinaryDelta(NSString *source, NSString *destination, NSString *patchFil
|
||||
NSString *sourceFilePath = [source stringByAppendingPathComponent:path];
|
||||
NSString *destinationFilePath = [destination stringByAppendingPathComponent:path];
|
||||
|
||||
// Don't use -[NSFileManager fileExistsAtPath:] because it will follow symbolic links
|
||||
BOOL fileExisted = verbose && [fileManager attributesOfItemAtPath:destinationFilePath error:nil];
|
||||
BOOL removedFile = NO;
|
||||
|
||||
const char *value;
|
||||
if (!xar_prop_get(file, "delete", &value) || !xar_prop_get(file, "delete-then-extract", &value)) {
|
||||
removeTree(destinationFilePath);
|
||||
if (!xar_prop_get(file, "delete", &value))
|
||||
if (!xar_prop_get(file, DELETE_KEY, &value) ||
|
||||
(!hasExtractKeyAvailable && !xar_prop_get(file, DELETE_THEN_EXTRACT_OLD_KEY, &value))) {
|
||||
if (!removeTree(destinationFilePath)) {
|
||||
fprintf(stderr, "\n%s or %s: failed to remove %s\n", DELETE_KEY, DELETE_THEN_EXTRACT_OLD_KEY, [destination fileSystemRepresentation]);
|
||||
return 1;
|
||||
}
|
||||
if (!hasExtractKeyAvailable && !xar_prop_get(file, DELETE_KEY, &value)) {
|
||||
if (verbose) {
|
||||
fprintf(stderr, "\n❌ %s %s", VERBOSE_DELETED, [path fileSystemRepresentation]);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
removedFile = YES;
|
||||
}
|
||||
|
||||
if (!xar_prop_get(file, "binary-delta", &value))
|
||||
applyBinaryDeltaToFile(x, file, sourceFilePath, destinationFilePath);
|
||||
else
|
||||
xar_extract_tofile(x, file, [destinationFilePath fileSystemRepresentation]);
|
||||
if (!xar_prop_get(file, BINARY_DELTA_KEY, &value)) {
|
||||
if (!applyBinaryDeltaToFile(x, file, sourceFilePath, destinationFilePath)) {
|
||||
fprintf(stderr, "\nUnable to patch %s to destination %s\n", [sourceFilePath fileSystemRepresentation], [destinationFilePath fileSystemRepresentation]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (verbose) {
|
||||
fprintf(stderr, "\n🔨 %s %s", VERBOSE_PATCHED, [path fileSystemRepresentation]);
|
||||
}
|
||||
} else if ((hasExtractKeyAvailable && !xar_prop_get(file, EXTRACT_KEY, &value)) ||
|
||||
(!hasExtractKeyAvailable && xar_prop_get(file, MODIFY_PERMISSIONS_KEY, &value))) { // extract and permission modifications don't coexist
|
||||
|
||||
if (xar_extract_tofile(x, file, [destinationFilePath fileSystemRepresentation]) != 0) {
|
||||
fprintf(stderr, "\nUnable to extract file to %s\n", [destinationFilePath fileSystemRepresentation]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (verbose) {
|
||||
if (fileExisted) {
|
||||
fprintf(stderr, "\n✏️ %s %s", VERBOSE_UPDATED, [path fileSystemRepresentation]);
|
||||
} else {
|
||||
fprintf(stderr, "\n✅ %s %s", VERBOSE_ADDED, [path fileSystemRepresentation]);
|
||||
}
|
||||
}
|
||||
} else if (verbose && removedFile) {
|
||||
fprintf(stderr, "\n❌ %s %s", VERBOSE_DELETED, [path fileSystemRepresentation]);
|
||||
}
|
||||
|
||||
if (!xar_prop_get(file, MODIFY_PERMISSIONS_KEY, &value)) {
|
||||
mode_t mode = (mode_t)[[NSString stringWithUTF8String:value] intValue];
|
||||
if (!modifyPermissions(destinationFilePath, mode)) {
|
||||
fprintf(stderr, "\nUnable to modify permissions (%s) on file %s\n", value, [destinationFilePath fileSystemRepresentation]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (verbose) {
|
||||
fprintf(stderr, "\n👮 %s %s (0%o)", VERBOSE_MODIFIED, [path fileSystemRepresentation], mode);
|
||||
}
|
||||
}
|
||||
}
|
||||
xar_close(x);
|
||||
|
||||
fprintf(stderr, "\nVerifying destination... ");
|
||||
NSString *afterHash = hashOfTree(destination);
|
||||
if (verbose) {
|
||||
fprintf(stderr, "\nVerifying destination...");
|
||||
}
|
||||
NSString *afterHash = hashOfTreeWithVersion(destination, majorDiffVersion);
|
||||
if (!afterHash) {
|
||||
fprintf(stderr, "\nUnable to calculate hash of tree %s\n", [destination fileSystemRepresentation]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (![afterHash isEqualToString:expectedAfterHash]) {
|
||||
fprintf(stderr, "Destination doesn't have expected hash (%s != %s). Giving up.\n", [expectedAfterHash UTF8String], [afterHash UTF8String]);
|
||||
fprintf(stderr, "\nDestination doesn't have expected hash (%s != %s). Giving up.\n", [expectedAfterHash UTF8String], [afterHash UTF8String]);
|
||||
removeTree(destination);
|
||||
return 1;
|
||||
}
|
||||
|
||||
fprintf(stderr, "\nDone!\n");
|
||||
if (verbose) {
|
||||
fprintf(stderr, "\nDone!\n");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -11,16 +11,71 @@
|
||||
|
||||
#include <fts.h>
|
||||
|
||||
#define PERMISSION_FLAGS (S_IRWXU | S_IRWXG | S_IRWXO | S_ISUID | S_ISGID | S_ISVTX)
|
||||
|
||||
#define IS_VALID_PERMISSIONS(mode) \
|
||||
(((mode & PERMISSION_FLAGS) == 0755) || ((mode & PERMISSION_FLAGS) == 0644))
|
||||
|
||||
#define BINARY_DELTA_ATTRIBUTES_KEY "binary-delta-attributes"
|
||||
#define MAJOR_DIFF_VERSION_KEY "major-version"
|
||||
#define MINOR_DIFF_VERSION_KEY "minor-version"
|
||||
#define BEFORE_TREE_SHA1_KEY "before-tree-sha1"
|
||||
#define AFTER_TREE_SHA1_KEY "after-tree-sha1"
|
||||
#define DELETE_KEY "delete"
|
||||
#define EXTRACT_KEY "extract"
|
||||
#define BINARY_DELTA_KEY "binary-delta"
|
||||
#define MODIFY_PERMISSIONS_KEY "mod-permissions"
|
||||
|
||||
// Properties no longer used in new patches
|
||||
#define DELETE_THEN_EXTRACT_OLD_KEY "delete-then-extract"
|
||||
#define BEFORE_TREE_SHA1_OLD_KEY "before-sha1"
|
||||
#define AFTER_TREE_SHA1_OLD_KEY "after-sha1"
|
||||
|
||||
#define VERBOSE_DELETED "Deleted" // file is deleted from the file system when applying a patch
|
||||
#define VERBOSE_REMOVED "Removed" // file is set to be removed when creating a patch
|
||||
#define VERBOSE_ADDED "Added" // file is added to the patch or file system
|
||||
#define VERBOSE_DIFFED "Diffed" // file is diffed when creating a patch
|
||||
#define VERBOSE_PATCHED "Patched" // file is patched when applying a patch
|
||||
#define VERBOSE_UPDATED "Updated" // file's contents are updated
|
||||
#define VERBOSE_MODIFIED "Modified" // file's metadata is modified
|
||||
|
||||
#define MAJOR_VERSION_IS_AT_LEAST(actualMajor, expectedMajor) (actualMajor >= expectedMajor)
|
||||
|
||||
// Each major version will be assigned a name of a color
|
||||
// Changes that break backwards compatibility will have different major versions
|
||||
// Changes that affect creating but not applying patches will have different minor versions
|
||||
|
||||
typedef NS_ENUM(uint16_t, SUBinaryDeltaMajorVersion)
|
||||
{
|
||||
SUAzureMajorVersion = 1,
|
||||
SUBeigeMajorVersion = 2
|
||||
};
|
||||
|
||||
// Only keep track of the latest minor version for each major version
|
||||
typedef NS_ENUM(uint16_t, SUBinaryDeltaMinorVersion)
|
||||
{
|
||||
SUAzureMinorVersion = 1,
|
||||
SUBeigeMinorVersion = 0,
|
||||
};
|
||||
|
||||
#define FIRST_DELTA_DIFF_MAJOR_VERSION SUAzureMajorVersion
|
||||
#define FIRST_DELTA_DIFF_MINOR_VERSION 0
|
||||
|
||||
#define LATEST_DELTA_DIFF_MAJOR_VERSION SUBeigeMajorVersion
|
||||
|
||||
@class NSString;
|
||||
@class NSData;
|
||||
|
||||
extern int binaryDeltaSupported(void);
|
||||
extern int compareFiles(const FTSENT **a, const FTSENT **b);
|
||||
extern NSData *hashOfFile(FTSENT *ent);
|
||||
extern NSData *hashOfFileContents(FTSENT *ent);
|
||||
extern NSString *hashOfTreeWithVersion(NSString *path, uint16_t majorVersion);
|
||||
extern NSString *hashOfTree(NSString *path);
|
||||
extern void removeTree(NSString *path);
|
||||
extern void copyTree(NSString *source, NSString *dest);
|
||||
extern BOOL removeTree(NSString *path);
|
||||
extern BOOL copyTree(NSString *source, NSString *dest);
|
||||
extern BOOL modifyPermissions(NSString *path, mode_t desiredPermissions);
|
||||
extern NSString *pathRelativeToDirectory(NSString *directory, NSString *path);
|
||||
NSString *temporaryFilename(NSString *base);
|
||||
NSString *temporaryDirectory(NSString *base);
|
||||
NSString *stringWithFileSystemRepresentation(const char*);
|
||||
SUBinaryDeltaMinorVersion latestMinorVersionForMajorVersion(SUBinaryDeltaMajorVersion majorVersion);
|
||||
#endif
|
||||
@@ -17,13 +17,6 @@
|
||||
#include <sys/stat.h>
|
||||
#include <xar/xar.h>
|
||||
|
||||
int binaryDeltaSupported(void)
|
||||
{
|
||||
// OS X 10.4 didn't include libxar, so we link against it weakly.
|
||||
// This checks whether libxar is available at runtime.
|
||||
return xar_close != 0;
|
||||
}
|
||||
|
||||
int compareFiles(const FTSENT **a, const FTSENT **b)
|
||||
{
|
||||
return strcoll((*a)->fts_name, (*b)->fts_name);
|
||||
@@ -42,6 +35,17 @@ NSString *stringWithFileSystemRepresentation(const char *input) {
|
||||
return [[NSFileManager defaultManager] stringWithFileSystemRepresentation:input length:strlen(input)];
|
||||
}
|
||||
|
||||
SUBinaryDeltaMinorVersion latestMinorVersionForMajorVersion(SUBinaryDeltaMajorVersion majorVersion)
|
||||
{
|
||||
switch (majorVersion) {
|
||||
case SUAzureMajorVersion:
|
||||
return SUAzureMinorVersion;
|
||||
case SUBeigeMajorVersion:
|
||||
return SUBeigeMinorVersion;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
NSString *temporaryFilename(NSString *base)
|
||||
{
|
||||
NSString *template = [NSTemporaryDirectory() stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.XXXXXXXXXX", base]];
|
||||
@@ -63,6 +67,22 @@ NSString *temporaryFilename(NSString *base)
|
||||
return stringWithFileSystemRepresentation(buffer);
|
||||
}
|
||||
|
||||
NSString *temporaryDirectory(NSString *base)
|
||||
{
|
||||
NSString *template = [NSTemporaryDirectory() stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.XXXXXXXXXX", base]];
|
||||
NSMutableData *data = [NSMutableData data];
|
||||
[data appendBytes:template.fileSystemRepresentation length:strlen(template.fileSystemRepresentation) + 1];
|
||||
|
||||
char *buffer = data.mutableBytes;
|
||||
char *templateResult = mkdtemp(buffer);
|
||||
if (templateResult == NULL) {
|
||||
perror("mkdtemp");
|
||||
return nil;
|
||||
}
|
||||
|
||||
return stringWithFileSystemRepresentation(templateResult);
|
||||
}
|
||||
|
||||
static void _hashOfBuffer(unsigned char *hash, const char* buffer, ssize_t bufferLength)
|
||||
{
|
||||
assert(bufferLength >= 0 && bufferLength <= UINT32_MAX);
|
||||
@@ -72,59 +92,57 @@ static void _hashOfBuffer(unsigned char *hash, const char* buffer, ssize_t buffe
|
||||
CC_SHA1_Final(hash, &hashContext);
|
||||
}
|
||||
|
||||
static void _hashOfFile(unsigned char* hash, FTSENT *ent)
|
||||
static BOOL _hashOfFileContents(unsigned char* hash, FTSENT *ent)
|
||||
{
|
||||
if (ent->fts_info == FTS_SL) {
|
||||
char linkDestination[MAXPATHLEN + 1];
|
||||
ssize_t linkDestinationLength = readlink(ent->fts_path, linkDestination, MAXPATHLEN);
|
||||
if (linkDestinationLength < 0) {
|
||||
perror("readlink");
|
||||
return;
|
||||
return NO;
|
||||
}
|
||||
|
||||
_hashOfBuffer(hash, linkDestination, linkDestinationLength);
|
||||
return;
|
||||
}
|
||||
|
||||
if (ent->fts_info == FTS_F) {
|
||||
} else if (ent->fts_info == FTS_F) {
|
||||
int fileDescriptor = open(ent->fts_path, O_RDONLY);
|
||||
if (fileDescriptor == -1) {
|
||||
perror("open");
|
||||
return;
|
||||
return NO;
|
||||
}
|
||||
|
||||
ssize_t fileSize = ent->fts_statp->st_size;
|
||||
if (fileSize == 0) {
|
||||
_hashOfBuffer(hash, NULL, 0);
|
||||
close(fileDescriptor);
|
||||
return;
|
||||
} else {
|
||||
void *buffer = mmap(0, (size_t)fileSize, PROT_READ, MAP_FILE | MAP_PRIVATE, fileDescriptor, 0);
|
||||
if (buffer == (void*)-1) {
|
||||
close(fileDescriptor);
|
||||
perror("mmap");
|
||||
return NO;
|
||||
}
|
||||
|
||||
_hashOfBuffer(hash, buffer, fileSize);
|
||||
munmap(buffer, (size_t)fileSize);
|
||||
}
|
||||
|
||||
void *buffer = mmap(0, (size_t)fileSize, PROT_READ, MAP_FILE | MAP_PRIVATE, fileDescriptor, 0);
|
||||
if (buffer == (void*)-1) {
|
||||
close(fileDescriptor);
|
||||
perror("mmap");
|
||||
return;
|
||||
}
|
||||
|
||||
_hashOfBuffer(hash, buffer, fileSize);
|
||||
munmap(buffer, (size_t)fileSize);
|
||||
close(fileDescriptor);
|
||||
return;
|
||||
}
|
||||
|
||||
if (ent->fts_info == FTS_D)
|
||||
} else if (ent->fts_info == FTS_D) {
|
||||
memset(hash, 0xdd, CC_SHA1_DIGEST_LENGTH);
|
||||
} else {
|
||||
return NO;
|
||||
}
|
||||
return YES;
|
||||
}
|
||||
|
||||
NSData *hashOfFile(FTSENT *ent)
|
||||
NSData *hashOfFileContents(FTSENT *ent)
|
||||
{
|
||||
unsigned char fileHash[CC_SHA1_DIGEST_LENGTH];
|
||||
_hashOfFile(fileHash, ent);
|
||||
if (!_hashOfFileContents(fileHash, ent)) {
|
||||
return nil;
|
||||
}
|
||||
return [NSData dataWithBytes:fileHash length:CC_SHA1_DIGEST_LENGTH];
|
||||
}
|
||||
|
||||
NSString *hashOfTree(NSString *path)
|
||||
NSString *hashOfTreeWithVersion(NSString *path, uint16_t majorVersion)
|
||||
{
|
||||
const char *sourcePaths[] = {[path fileSystemRepresentation], 0};
|
||||
FTS *fts = fts_open((char* const*)sourcePaths, FTS_PHYSICAL | FTS_NOCHDIR, compareFiles);
|
||||
@@ -138,16 +156,34 @@ NSString *hashOfTree(NSString *path)
|
||||
|
||||
FTSENT *ent = 0;
|
||||
while ((ent = fts_read(fts))) {
|
||||
if (ent->fts_info != FTS_F && ent->fts_info != FTS_SL)
|
||||
if (ent->fts_info != FTS_F && ent->fts_info != FTS_SL && ent->fts_info != FTS_D)
|
||||
continue;
|
||||
|
||||
if (ent->fts_info == FTS_D && !MAJOR_VERSION_IS_AT_LEAST(majorVersion, SUBeigeMajorVersion)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
NSString *relativePath = pathRelativeToDirectory(path, stringWithFileSystemRepresentation(ent->fts_path));
|
||||
if (relativePath.length == 0)
|
||||
continue;
|
||||
|
||||
unsigned char fileHash[CC_SHA1_DIGEST_LENGTH];
|
||||
_hashOfFile(fileHash, ent);
|
||||
if (!_hashOfFileContents(fileHash, ent)) {
|
||||
return nil;
|
||||
}
|
||||
CC_SHA1_Update(&hashContext, fileHash, sizeof(fileHash));
|
||||
|
||||
NSString *relativePath = pathRelativeToDirectory(path, stringWithFileSystemRepresentation(ent->fts_path));
|
||||
const char *relativePathBytes = [relativePath fileSystemRepresentation];
|
||||
CC_SHA1_Update(&hashContext, relativePathBytes, (CC_LONG)strlen(relativePathBytes));
|
||||
|
||||
if (MAJOR_VERSION_IS_AT_LEAST(majorVersion, SUBeigeMajorVersion)) {
|
||||
uint16_t mode = ent->fts_statp->st_mode;
|
||||
uint16_t type = ent->fts_info;
|
||||
uint16_t permissions = mode & PERMISSION_FLAGS;
|
||||
|
||||
CC_SHA1_Update(&hashContext, &type, sizeof(type));
|
||||
CC_SHA1_Update(&hashContext, &permissions, sizeof(permissions));
|
||||
}
|
||||
}
|
||||
fts_close(fts);
|
||||
|
||||
@@ -162,12 +198,41 @@ NSString *hashOfTree(NSString *path)
|
||||
return @(hexHash);
|
||||
}
|
||||
|
||||
void removeTree(NSString *path)
|
||||
extern NSString *hashOfTree(NSString *path)
|
||||
{
|
||||
[[NSFileManager defaultManager] removeItemAtPath:path error:nil];
|
||||
return hashOfTreeWithVersion(path, LATEST_DELTA_DIFF_MAJOR_VERSION);
|
||||
}
|
||||
|
||||
void copyTree(NSString *source, NSString *dest)
|
||||
BOOL removeTree(NSString *path)
|
||||
{
|
||||
[[NSFileManager defaultManager] copyItemAtPath:source toPath:dest error:nil];
|
||||
NSFileManager *fileManager = [NSFileManager defaultManager];
|
||||
// Don't use fileExistsForPath: because it will try to follow symbolic links
|
||||
if (![fileManager attributesOfItemAtPath:path error:nil]) {
|
||||
return YES;
|
||||
}
|
||||
return [fileManager removeItemAtPath:path error:nil];
|
||||
}
|
||||
|
||||
BOOL copyTree(NSString *source, NSString *dest)
|
||||
{
|
||||
return [[NSFileManager defaultManager] copyItemAtPath:source toPath:dest error:nil];
|
||||
}
|
||||
|
||||
BOOL modifyPermissions(NSString *path, mode_t desiredPermissions)
|
||||
{
|
||||
NSFileManager *fileManager = [NSFileManager defaultManager];
|
||||
NSDictionary *attributes = [fileManager attributesOfItemAtPath:path error:nil];
|
||||
if (!attributes) {
|
||||
return NO;
|
||||
}
|
||||
NSNumber *permissions = attributes[NSFilePosixPermissions];
|
||||
if (!permissions) {
|
||||
return NO;
|
||||
}
|
||||
mode_t newMode = ([permissions unsignedShortValue] & ~PERMISSION_FLAGS) | desiredPermissions;
|
||||
int (*changeModeFunc)(const char *, mode_t) = [attributes[NSFileType] isEqualToString:NSFileTypeSymbolicLink] ? lchmod : chmod;
|
||||
if (changeModeFunc([path fileSystemRepresentation], newMode) != 0) {
|
||||
return NO;
|
||||
}
|
||||
return YES;
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
//
|
||||
// SUBinaryDeltaCreate.m
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Mayur Pawashe on 4/9/15.
|
||||
// Copyright (c) 2015 Sparkle Project. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef SUBINARYDELTACREATE_H
|
||||
#define SUBINARYDELTACREATE_H
|
||||
|
||||
#import "SUBinaryDeltaCommon.h"
|
||||
|
||||
@class NSString;
|
||||
int createBinaryDelta(NSString *source, NSString *destination, NSString *patchFile, SUBinaryDeltaMajorVersion majorVersion, BOOL verbose);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,462 @@
|
||||
//
|
||||
// SUBinaryDeltaCreate.m
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Mayur Pawashe on 4/9/15.
|
||||
// Copyright (c) 2015 Sparkle Project. All rights reserved.
|
||||
//
|
||||
|
||||
#import "SUBinaryDeltaCreate.h"
|
||||
#import <Foundation/Foundation.h>
|
||||
#include "SUBinaryDeltaCommon.h"
|
||||
#import <CommonCrypto/CommonDigest.h>
|
||||
#include <fcntl.h>
|
||||
#include <fts.h>
|
||||
#include <libgen.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/param.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <xar/xar.h>
|
||||
|
||||
extern int bsdiff(int argc, const char **argv);
|
||||
|
||||
@interface CreateBinaryDeltaOperation : NSOperation
|
||||
@property (copy) NSString *relativePath;
|
||||
@property (strong) NSString *resultPath;
|
||||
@property (strong) NSNumber *oldPermissions;
|
||||
@property (strong) NSNumber *permissions;
|
||||
@property (strong) NSString *_fromPath;
|
||||
@property (strong) NSString *_toPath;
|
||||
- (id)initWithRelativePath:(NSString *)relativePath oldTree:(NSString *)oldTree newTree:(NSString *)newTree oldPermissions:(NSNumber *)oldPermissions newPermissions:(NSNumber *)permissions;
|
||||
@end
|
||||
|
||||
@implementation CreateBinaryDeltaOperation
|
||||
@synthesize relativePath = _relativePath;
|
||||
@synthesize resultPath = _resultPath;
|
||||
@synthesize oldPermissions = _oldPermissions;
|
||||
@synthesize permissions = _permissions;
|
||||
@synthesize _fromPath = _fromPath;
|
||||
@synthesize _toPath = _toPath;
|
||||
|
||||
- (id)initWithRelativePath:(NSString *)relativePath oldTree:(NSString *)oldTree newTree:(NSString *)newTree oldPermissions:(NSNumber *)oldPermissions newPermissions:(NSNumber *)permissions
|
||||
{
|
||||
if ((self = [super init])) {
|
||||
self.relativePath = relativePath;
|
||||
self.oldPermissions = oldPermissions;
|
||||
self.permissions = permissions;
|
||||
self._fromPath = [oldTree stringByAppendingPathComponent:relativePath];
|
||||
self._toPath = [newTree stringByAppendingPathComponent:relativePath];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)main
|
||||
{
|
||||
NSString *temporaryFile = temporaryFilename(@"BinaryDelta");
|
||||
const char *argv[] = {"/usr/bin/bsdiff", [self._fromPath fileSystemRepresentation], [self._toPath fileSystemRepresentation], [temporaryFile fileSystemRepresentation]};
|
||||
int result = bsdiff(4, argv);
|
||||
if (!result)
|
||||
self.resultPath = temporaryFile;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
#define INFO_HASH_KEY @"hash"
|
||||
#define INFO_TYPE_KEY @"type"
|
||||
#define INFO_PERMISSIONS_KEY @"permissions"
|
||||
#define INFO_SIZE_KEY @"size"
|
||||
|
||||
static NSDictionary *infoForFile(FTSENT *ent)
|
||||
{
|
||||
NSData *hash = hashOfFileContents(ent);
|
||||
if (!hash) {
|
||||
return nil;
|
||||
}
|
||||
|
||||
off_t size = (ent->fts_info != FTS_D) ? ent->fts_statp->st_size : 0;
|
||||
|
||||
assert(ent->fts_statp != NULL);
|
||||
|
||||
mode_t permissions = ent->fts_statp->st_mode & PERMISSION_FLAGS;
|
||||
|
||||
return @{INFO_HASH_KEY: hash, INFO_TYPE_KEY: @(ent->fts_info), INFO_PERMISSIONS_KEY : @(permissions), INFO_SIZE_KEY: @(size)};
|
||||
}
|
||||
|
||||
static bool aclExists(const FTSENT *ent)
|
||||
{
|
||||
// OS X does not currently support ACLs for symlinks
|
||||
if (ent->fts_info == FTS_SL) {
|
||||
return NO;
|
||||
}
|
||||
|
||||
acl_t acl = acl_get_link_np(ent->fts_path, ACL_TYPE_EXTENDED);
|
||||
if (acl != NULL) {
|
||||
acl_entry_t entry;
|
||||
int result = acl_get_entry(acl, ACL_FIRST_ENTRY, &entry);
|
||||
assert(acl_free((void *)acl) == 0);
|
||||
return (result == 0);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static NSString *absolutePath(NSString *path)
|
||||
{
|
||||
NSURL *url = [[NSURL alloc] initFileURLWithPath:path];
|
||||
return [[url absoluteURL] path];
|
||||
}
|
||||
|
||||
static NSString *temporaryPatchFile(NSString *patchFile)
|
||||
{
|
||||
NSString *path = absolutePath(patchFile);
|
||||
NSString *directory = [path stringByDeletingLastPathComponent];
|
||||
NSString *file = [path lastPathComponent];
|
||||
return [NSString stringWithFormat:@"%@/.%@.tmp", directory, file];
|
||||
}
|
||||
|
||||
#define MIN_FILE_SIZE_FOR_CREATING_DELTA 4096
|
||||
|
||||
static BOOL shouldSkipDeltaCompression(NSDictionary* originalInfo, NSDictionary *newInfo)
|
||||
{
|
||||
unsigned long long fileSize = [newInfo[INFO_SIZE_KEY] unsignedLongLongValue];
|
||||
if (fileSize < MIN_FILE_SIZE_FOR_CREATING_DELTA) {
|
||||
return YES;
|
||||
}
|
||||
|
||||
if (!originalInfo) {
|
||||
return YES;
|
||||
}
|
||||
|
||||
if ([originalInfo[INFO_TYPE_KEY] unsignedShortValue] != [newInfo[INFO_TYPE_KEY] unsignedShortValue]) {
|
||||
return YES;
|
||||
}
|
||||
|
||||
if ([originalInfo[INFO_HASH_KEY] isEqual:newInfo[INFO_HASH_KEY]]) {
|
||||
// this is possible if just the permissions have changed
|
||||
return YES;
|
||||
}
|
||||
|
||||
return NO;
|
||||
}
|
||||
|
||||
static BOOL shouldDeleteThenExtract(NSDictionary* originalInfo, NSDictionary *newInfo)
|
||||
{
|
||||
if (!originalInfo) {
|
||||
return NO;
|
||||
}
|
||||
|
||||
if ([originalInfo[INFO_TYPE_KEY] unsignedShortValue] != [newInfo[INFO_TYPE_KEY] unsignedShortValue]) {
|
||||
return YES;
|
||||
}
|
||||
|
||||
return NO;
|
||||
}
|
||||
|
||||
static BOOL shouldSkipExtracting(NSDictionary *originalInfo, NSDictionary *newInfo)
|
||||
{
|
||||
if (!originalInfo) {
|
||||
return NO;
|
||||
}
|
||||
|
||||
if ([originalInfo[INFO_TYPE_KEY] unsignedShortValue] != [newInfo[INFO_TYPE_KEY] unsignedShortValue]) {
|
||||
return NO;
|
||||
}
|
||||
|
||||
if (![originalInfo[INFO_HASH_KEY] isEqual:newInfo[INFO_HASH_KEY]]) {
|
||||
return NO;
|
||||
}
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
static BOOL shouldChangePermissions(NSDictionary *originalInfo, NSDictionary *newInfo)
|
||||
{
|
||||
if (!originalInfo) {
|
||||
return NO;
|
||||
}
|
||||
|
||||
if ([originalInfo[INFO_TYPE_KEY] unsignedShortValue] != [newInfo[INFO_TYPE_KEY] unsignedShortValue]) {
|
||||
return NO;
|
||||
}
|
||||
|
||||
if ([originalInfo[INFO_PERMISSIONS_KEY] unsignedShortValue] == [newInfo[INFO_PERMISSIONS_KEY] unsignedShortValue]) {
|
||||
return NO;
|
||||
}
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
int createBinaryDelta(NSString *source, NSString *destination, NSString *patchFile, SUBinaryDeltaMajorVersion majorVersion, BOOL verbose)
|
||||
{
|
||||
if (majorVersion < FIRST_DELTA_DIFF_MAJOR_VERSION) {
|
||||
fprintf(stderr, "Version provided (%u) is not valid\n", majorVersion);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (majorVersion > LATEST_DELTA_DIFF_MAJOR_VERSION) {
|
||||
fprintf(stderr, "This program is too old to create a version %u patch, or the version number provided is invalid\n", majorVersion);
|
||||
return 1;
|
||||
}
|
||||
|
||||
SUBinaryDeltaMinorVersion minorVersion = latestMinorVersionForMajorVersion(majorVersion);
|
||||
|
||||
NSMutableDictionary *originalTreeState = [NSMutableDictionary dictionary];
|
||||
|
||||
const char *sourcePaths[] = {[source fileSystemRepresentation], 0};
|
||||
FTS *fts = fts_open((char* const*)sourcePaths, FTS_PHYSICAL | FTS_NOCHDIR, compareFiles);
|
||||
if (!fts) {
|
||||
perror("fts_open");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (verbose) {
|
||||
fprintf(stderr, "Creating version %u.%u patch...\n", majorVersion, minorVersion);
|
||||
fprintf(stderr, "Processing %s...", [source fileSystemRepresentation]);
|
||||
}
|
||||
|
||||
FTSENT *ent = 0;
|
||||
while ((ent = fts_read(fts))) {
|
||||
if (ent->fts_info != FTS_F && ent->fts_info != FTS_SL && ent->fts_info != FTS_D) {
|
||||
continue;
|
||||
}
|
||||
|
||||
NSString *key = pathRelativeToDirectory(source, stringWithFileSystemRepresentation(ent->fts_path));
|
||||
if (![key length]) {
|
||||
continue;
|
||||
}
|
||||
|
||||
NSDictionary *info = infoForFile(ent);
|
||||
if (!info) {
|
||||
fprintf(stderr, "\nFailed to retrieve info for file %s\n", ent->fts_path);
|
||||
return 1;
|
||||
}
|
||||
originalTreeState[key] = info;
|
||||
|
||||
if (aclExists(ent)) {
|
||||
fprintf(stderr, "\nDiffing ACLs are not supported. Detected ACL in before-tree on file %s\n", ent->fts_path);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
fts_close(fts);
|
||||
|
||||
NSString *beforeHash = hashOfTreeWithVersion(source, majorVersion);
|
||||
|
||||
if (!beforeHash) {
|
||||
fprintf(stderr, "\nFailed to generate hash for tree %s\n", [source fileSystemRepresentation]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
NSMutableDictionary *newTreeState = [NSMutableDictionary dictionary];
|
||||
for (NSString *key in originalTreeState)
|
||||
{
|
||||
newTreeState[key] = [NSNull null];
|
||||
}
|
||||
|
||||
if (verbose) {
|
||||
fprintf(stderr, "\nProcessing %s...", [destination fileSystemRepresentation]);
|
||||
}
|
||||
|
||||
sourcePaths[0] = [destination fileSystemRepresentation];
|
||||
fts = fts_open((char* const*)sourcePaths, FTS_PHYSICAL | FTS_NOCHDIR, compareFiles);
|
||||
if (!fts) {
|
||||
perror("fts_open");
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
while ((ent = fts_read(fts))) {
|
||||
if (ent->fts_info != FTS_F && ent->fts_info != FTS_SL && ent->fts_info != FTS_D) {
|
||||
continue;
|
||||
}
|
||||
|
||||
NSString *key = pathRelativeToDirectory(destination, stringWithFileSystemRepresentation(ent->fts_path));
|
||||
if (![key length]) {
|
||||
continue;
|
||||
}
|
||||
|
||||
NSDictionary *info = infoForFile(ent);
|
||||
if (!info) {
|
||||
fprintf(stderr, "\nFailed to retrieve info from file %s\n", ent->fts_path);
|
||||
return 1;
|
||||
}
|
||||
|
||||
// We should validate permissions and ACLs even if we don't store the info in the diff in the case of ACLs,
|
||||
// or in the case of permissions if the patch version is 1
|
||||
|
||||
mode_t permissions = [info[INFO_PERMISSIONS_KEY] unsignedShortValue];
|
||||
if (!IS_VALID_PERMISSIONS(permissions)) {
|
||||
fprintf(stderr, "\nInvalid file permissions after-tree on file %s\nOnly permissions with modes 0755 and 0644 are supported\n", ent->fts_path);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (aclExists(ent)) {
|
||||
fprintf(stderr, "\nDiffing ACLs are not supported. Detected ACL in after-tree on file %s\n", ent->fts_path);
|
||||
return 1;
|
||||
}
|
||||
|
||||
NSDictionary *oldInfo = originalTreeState[key];
|
||||
|
||||
if ([info isEqual:oldInfo]) {
|
||||
[newTreeState removeObjectForKey:key];
|
||||
} else {
|
||||
newTreeState[key] = info;
|
||||
|
||||
if (oldInfo && [oldInfo[INFO_TYPE_KEY] unsignedShortValue] == FTS_D && [info[INFO_TYPE_KEY] unsignedShortValue] != FTS_D) {
|
||||
NSArray *parentPathComponents = key.pathComponents;
|
||||
|
||||
for (NSString *childPath in originalTreeState) {
|
||||
NSArray *childPathComponents = childPath.pathComponents;
|
||||
if (childPathComponents.count > parentPathComponents.count &&
|
||||
[parentPathComponents isEqualToArray:[childPathComponents subarrayWithRange:NSMakeRange(0, parentPathComponents.count)]]) {
|
||||
[newTreeState removeObjectForKey:childPath];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
fts_close(fts);
|
||||
|
||||
NSString *afterHash = hashOfTreeWithVersion(destination, majorVersion);
|
||||
if (!afterHash) {
|
||||
fprintf(stderr, "\nFailed to generate hash for tree %s\n", [destination fileSystemRepresentation]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (verbose) {
|
||||
fprintf(stderr, "\nGenerating delta...");
|
||||
}
|
||||
|
||||
NSString *temporaryFile = temporaryPatchFile(patchFile);
|
||||
xar_t x = xar_open([temporaryFile fileSystemRepresentation], WRITE);
|
||||
xar_opt_set(x, XAR_OPT_COMPRESSION, "bzip2");
|
||||
|
||||
xar_subdoc_t attributes = xar_subdoc_new(x, BINARY_DELTA_ATTRIBUTES_KEY);
|
||||
|
||||
xar_subdoc_prop_set(attributes, MAJOR_DIFF_VERSION_KEY, [[NSString stringWithFormat:@"%u", majorVersion] UTF8String]);
|
||||
xar_subdoc_prop_set(attributes, MINOR_DIFF_VERSION_KEY, [[NSString stringWithFormat:@"%u", minorVersion] UTF8String]);
|
||||
|
||||
// Version 1 patches don't have a major or minor version field, so we need to differentiate between the hash keys
|
||||
const char *beforeHashKey =
|
||||
MAJOR_VERSION_IS_AT_LEAST(majorVersion, SUBeigeMajorVersion) ? BEFORE_TREE_SHA1_KEY : BEFORE_TREE_SHA1_OLD_KEY;
|
||||
const char *afterHashKey =
|
||||
MAJOR_VERSION_IS_AT_LEAST(majorVersion, SUBeigeMajorVersion) ? AFTER_TREE_SHA1_KEY : AFTER_TREE_SHA1_OLD_KEY;
|
||||
|
||||
xar_subdoc_prop_set(attributes, beforeHashKey, [beforeHash UTF8String]);
|
||||
xar_subdoc_prop_set(attributes, afterHashKey, [afterHash UTF8String]);
|
||||
|
||||
NSOperationQueue *deltaQueue = [[NSOperationQueue alloc] init];
|
||||
NSMutableArray *deltaOperations = [NSMutableArray array];
|
||||
|
||||
// Sort the keys by preferring the ones from the original tree to appear first
|
||||
// We want to enforce deleting before extracting in the case paths differ only by case
|
||||
NSArray *keys = [[newTreeState allKeys] sortedArrayUsingComparator:^NSComparisonResult(NSString *key1, NSString *key2) {
|
||||
NSComparisonResult insensitiveCompareResult = [key1 caseInsensitiveCompare:key2];
|
||||
if (insensitiveCompareResult != NSOrderedSame) {
|
||||
return insensitiveCompareResult;
|
||||
}
|
||||
|
||||
return originalTreeState[key1] ? NSOrderedAscending : NSOrderedDescending;
|
||||
}];
|
||||
for (NSString* key in keys) {
|
||||
id value = [newTreeState valueForKey:key];
|
||||
|
||||
if ([value isEqual:[NSNull null]]) {
|
||||
xar_file_t newFile = xar_add_frombuffer(x, 0, [key fileSystemRepresentation], (char *)"", 1);
|
||||
assert(newFile);
|
||||
xar_prop_set(newFile, DELETE_KEY, "true");
|
||||
|
||||
if (verbose) {
|
||||
fprintf(stderr, "\n❌ %s %s", VERBOSE_REMOVED, [key fileSystemRepresentation]);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
NSDictionary *originalInfo = originalTreeState[key];
|
||||
NSDictionary *newInfo = newTreeState[key];
|
||||
if (shouldSkipDeltaCompression(originalInfo, newInfo)) {
|
||||
if (MAJOR_VERSION_IS_AT_LEAST(majorVersion, SUBeigeMajorVersion) && shouldSkipExtracting(originalInfo, newInfo)) {
|
||||
if (shouldChangePermissions(originalInfo, newInfo)) {
|
||||
xar_file_t newFile = xar_add_frombuffer(x, 0, [key fileSystemRepresentation], (char *)"", 1);
|
||||
assert(newFile);
|
||||
xar_prop_set(newFile, MODIFY_PERMISSIONS_KEY, [[NSString stringWithFormat:@"%u", [newInfo[INFO_PERMISSIONS_KEY] unsignedShortValue]] UTF8String]);
|
||||
|
||||
if (verbose) {
|
||||
fprintf(stderr, "\n👮 %s %s (0%o -> 0%o)", VERBOSE_MODIFIED, [key fileSystemRepresentation], [originalInfo[INFO_PERMISSIONS_KEY] unsignedShortValue], [newInfo[INFO_PERMISSIONS_KEY] unsignedShortValue]);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
NSString *path = [destination stringByAppendingPathComponent:key];
|
||||
xar_file_t newFile = xar_add_frompath(x, 0, [key fileSystemRepresentation], [path fileSystemRepresentation]);
|
||||
assert(newFile);
|
||||
|
||||
if (shouldDeleteThenExtract(originalInfo, newInfo)) {
|
||||
if (MAJOR_VERSION_IS_AT_LEAST(majorVersion, SUBeigeMajorVersion)) {
|
||||
xar_prop_set(newFile, DELETE_KEY, "true");
|
||||
} else {
|
||||
xar_prop_set(newFile, DELETE_THEN_EXTRACT_OLD_KEY, "true");
|
||||
}
|
||||
}
|
||||
|
||||
if (MAJOR_VERSION_IS_AT_LEAST(majorVersion, SUBeigeMajorVersion)) {
|
||||
xar_prop_set(newFile, EXTRACT_KEY, "true");
|
||||
}
|
||||
|
||||
if (verbose) {
|
||||
if (originalInfo) {
|
||||
fprintf(stderr, "\n✏️ %s %s", VERBOSE_UPDATED, [key fileSystemRepresentation]);
|
||||
} else {
|
||||
fprintf(stderr, "\n✅ %s %s", VERBOSE_ADDED, [key fileSystemRepresentation]);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
NSNumber *permissions =
|
||||
(MAJOR_VERSION_IS_AT_LEAST(majorVersion, SUBeigeMajorVersion) && shouldChangePermissions(originalInfo, newInfo)) ?
|
||||
newInfo[INFO_PERMISSIONS_KEY] :
|
||||
nil;
|
||||
CreateBinaryDeltaOperation *operation = [[CreateBinaryDeltaOperation alloc] initWithRelativePath:key oldTree:source newTree:destination oldPermissions:originalInfo[INFO_PERMISSIONS_KEY] newPermissions:permissions];
|
||||
[deltaQueue addOperation:operation];
|
||||
[deltaOperations addObject:operation];
|
||||
}
|
||||
}
|
||||
|
||||
[deltaQueue waitUntilAllOperationsAreFinished];
|
||||
|
||||
for (CreateBinaryDeltaOperation *operation in deltaOperations) {
|
||||
NSString *resultPath = [operation resultPath];
|
||||
if (!resultPath) {
|
||||
fprintf(stderr, "\nFailed to create patch from source %s and destination %s\n", [[operation relativePath] fileSystemRepresentation], [resultPath fileSystemRepresentation]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (verbose) {
|
||||
fprintf(stderr, "\n🔨 %s %s", VERBOSE_DIFFED, [[operation relativePath] fileSystemRepresentation]);
|
||||
}
|
||||
|
||||
xar_file_t newFile = xar_add_frompath(x, 0, [[operation relativePath] fileSystemRepresentation], [resultPath fileSystemRepresentation]);
|
||||
assert(newFile);
|
||||
xar_prop_set(newFile, BINARY_DELTA_KEY, "true");
|
||||
unlink([resultPath fileSystemRepresentation]);
|
||||
|
||||
if (operation.permissions) {
|
||||
xar_prop_set(newFile, MODIFY_PERMISSIONS_KEY, [[NSString stringWithFormat:@"%u", [operation.permissions unsignedShortValue]] UTF8String]);
|
||||
|
||||
if (verbose) {
|
||||
fprintf(stderr, "\n👮 %s %s (0%o -> 0%o)", VERBOSE_MODIFIED, [[operation relativePath] fileSystemRepresentation], operation.oldPermissions.unsignedShortValue, operation.permissions.unsignedShortValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
xar_close(x);
|
||||
|
||||
unlink([patchFile fileSystemRepresentation]);
|
||||
link([temporaryFile fileSystemRepresentation], [patchFile fileSystemRepresentation]);
|
||||
unlink([temporaryFile fileSystemRepresentation]);
|
||||
|
||||
if (verbose) {
|
||||
fprintf(stderr, "\nDone!\n");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -6,271 +6,213 @@
|
||||
// Copyright 2009 Mark Rowe. All rights reserved.
|
||||
//
|
||||
|
||||
#define _DARWIN_NO_64_BIT_INODE 1
|
||||
|
||||
#include "SUBinaryDeltaCommon.h"
|
||||
#include "SUBinaryDeltaApply.h"
|
||||
#include <CommonCrypto/CommonDigest.h>
|
||||
#include "SUBinaryDeltaCreate.h"
|
||||
#import "SUBinaryDeltaCommon.h"
|
||||
#include <Foundation/Foundation.h>
|
||||
#include <fcntl.h>
|
||||
#include <fts.h>
|
||||
#include <libgen.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/param.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <xar/xar.h>
|
||||
|
||||
extern int bsdiff(int argc, const char **argv);
|
||||
#define VERBOSE_FLAG @"--verbose"
|
||||
#define VERSION_FLAG @"--version"
|
||||
|
||||
@interface CreateBinaryDeltaOperation : NSOperation
|
||||
@property (copy) NSString *relativePath;
|
||||
@property (strong) NSString *resultPath;
|
||||
@property (strong) NSString *_fromPath;
|
||||
@property (strong) NSString *_toPath;
|
||||
- (id)initWithRelativePath:(NSString *)relativePath oldTree:(NSString *)oldTree newTree:(NSString *)newTree;
|
||||
@end
|
||||
#define CREATE_COMMAND @"create"
|
||||
#define APPLY_COMMAND @"apply"
|
||||
#define VERSION_COMMAND @"version"
|
||||
#define VERSION_ALTERNATE_COMMAND @"--version"
|
||||
|
||||
@implementation CreateBinaryDeltaOperation
|
||||
@synthesize relativePath = _relativePath;
|
||||
@synthesize resultPath = _resultPath;
|
||||
@synthesize _fromPath = _fromPath;
|
||||
@synthesize _toPath = _toPath;
|
||||
|
||||
- (id)initWithRelativePath:(NSString *)relativePath oldTree:(NSString *)oldTree newTree:(NSString *)newTree
|
||||
static void printUsage(NSString *programName)
|
||||
{
|
||||
if ((self = [super init])) {
|
||||
self.relativePath = relativePath;
|
||||
self._fromPath = [oldTree stringByAppendingPathComponent:relativePath];
|
||||
self._toPath = [newTree stringByAppendingPathComponent:relativePath];
|
||||
fprintf(stderr, "Usage:\n");
|
||||
fprintf(stderr, "%s create [--verbose] [--version=<version>] <before-tree> <after-tree> <patch-file>\n", [programName UTF8String]);
|
||||
fprintf(stderr, "%s apply [--verbose] <before-tree> <after-tree> <patch-file>\n", [programName UTF8String]);
|
||||
fprintf(stderr, "%s version [<patch-file>]\n", [programName UTF8String]);
|
||||
}
|
||||
|
||||
static int runCreateCommand(NSString *programName, NSArray *args)
|
||||
{
|
||||
if (args.count < 3 || args.count > 5) {
|
||||
printUsage(programName);
|
||||
return 1;
|
||||
}
|
||||
return self;
|
||||
|
||||
NSUInteger numberOflagsFound = 0;
|
||||
NSUInteger verboseIndex = [args indexOfObject:VERBOSE_FLAG];
|
||||
NSUInteger versionIndex = NSNotFound;
|
||||
for (NSUInteger argumentIndex = 0; argumentIndex < args.count; ++argumentIndex) {
|
||||
if ([args[argumentIndex] hasPrefix:VERSION_FLAG]) {
|
||||
versionIndex = argumentIndex;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (verboseIndex != NSNotFound) {
|
||||
++numberOflagsFound;
|
||||
}
|
||||
if (versionIndex != NSNotFound) {
|
||||
++numberOflagsFound;
|
||||
}
|
||||
|
||||
if (args.count - numberOflagsFound < 3) {
|
||||
printUsage(programName);
|
||||
return 1;
|
||||
}
|
||||
|
||||
BOOL verbose = (verboseIndex != NSNotFound);
|
||||
NSString *versionField = (versionIndex != NSNotFound) ? args[versionIndex] : nil;
|
||||
|
||||
NSArray *versionComponents = nil;
|
||||
if (versionField) {
|
||||
versionComponents = [versionField componentsSeparatedByString:@"="];
|
||||
if (versionComponents.count != 2) {
|
||||
printUsage(programName);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
SUBinaryDeltaMajorVersion patchVersion =
|
||||
!versionComponents ?
|
||||
LATEST_DELTA_DIFF_MAJOR_VERSION :
|
||||
(SUBinaryDeltaMajorVersion)[[versionComponents[1] componentsSeparatedByString:@"."][0] intValue]; // ignore minor version if provided
|
||||
|
||||
NSMutableArray *fileArgs = [NSMutableArray array];
|
||||
for (NSString *argument in args) {
|
||||
if (![argument hasPrefix:VERSION_FLAG] && ![argument isEqualToString:VERBOSE_FLAG]) {
|
||||
[fileArgs addObject:argument];
|
||||
}
|
||||
}
|
||||
|
||||
if (fileArgs.count != 3) {
|
||||
printUsage(programName);
|
||||
return 1;
|
||||
}
|
||||
|
||||
BOOL isDirectory;
|
||||
if (![[NSFileManager defaultManager] fileExistsAtPath:fileArgs[0] isDirectory:&isDirectory] || !isDirectory) {
|
||||
printUsage(programName);
|
||||
fprintf(stderr, "Error: before-tree must be a directory\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (![[NSFileManager defaultManager] fileExistsAtPath:fileArgs[1] isDirectory:&isDirectory] || !isDirectory) {
|
||||
printUsage(programName);
|
||||
fprintf(stderr, "Error: after-tree must be a directory\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
return createBinaryDelta(fileArgs[0], fileArgs[1], fileArgs[2], patchVersion, verbose);
|
||||
}
|
||||
|
||||
- (void)main
|
||||
static int runApplyCommand(NSString *programName, NSArray *args)
|
||||
{
|
||||
NSString *temporaryFile = temporaryFilename(@"BinaryDelta");
|
||||
const char *argv[] = {"/usr/bin/bsdiff", [self._fromPath fileSystemRepresentation], [self._toPath fileSystemRepresentation], [temporaryFile fileSystemRepresentation]};
|
||||
int result = bsdiff(4, argv);
|
||||
if (!result)
|
||||
self.resultPath = temporaryFile;
|
||||
if (args.count < 3 || args.count > 4) {
|
||||
printUsage(programName);
|
||||
return 1;
|
||||
}
|
||||
|
||||
BOOL verbose = [args containsObject:VERBOSE_FLAG];
|
||||
|
||||
if (args.count == 4 && !verbose) {
|
||||
printUsage(programName);
|
||||
return 1;
|
||||
}
|
||||
|
||||
NSMutableArray *fileArgs = [NSMutableArray array];
|
||||
for (NSString *argument in args) {
|
||||
if (![argument isEqualToString:VERBOSE_FLAG]) {
|
||||
[fileArgs addObject:argument];
|
||||
}
|
||||
}
|
||||
|
||||
if (fileArgs.count != 3) {
|
||||
printUsage(programName);
|
||||
return 1;
|
||||
}
|
||||
|
||||
BOOL isDirectory;
|
||||
if (![[NSFileManager defaultManager] fileExistsAtPath:fileArgs[0] isDirectory:&isDirectory] || !isDirectory) {
|
||||
printUsage(programName);
|
||||
fprintf(stderr, "Error: before-tree must be a directory\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (![[NSFileManager defaultManager] fileExistsAtPath:fileArgs[2] isDirectory:&isDirectory] || isDirectory) {
|
||||
printUsage(programName);
|
||||
fprintf(stderr, "Error: patch-file must be a file %d\n", isDirectory);
|
||||
return 1;
|
||||
}
|
||||
|
||||
return applyBinaryDelta(fileArgs[0], fileArgs[1], fileArgs[2], verbose);
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
static NSDictionary *infoForFile(FTSENT *ent)
|
||||
static int runVersionCommand(NSString *programName, NSArray *args)
|
||||
{
|
||||
NSData *hash = hashOfFile(ent);
|
||||
NSNumber *size = @0;
|
||||
if (ent->fts_info != FTS_D) {
|
||||
size = @(ent->fts_statp->st_size);
|
||||
}
|
||||
return @{@"hash": hash, @"type": @(ent->fts_info), @"size": size};
|
||||
}
|
||||
|
||||
static NSString *absolutePath(NSString *path)
|
||||
{
|
||||
NSURL *url = [[NSURL alloc] initFileURLWithPath:path];
|
||||
return [[url absoluteURL] path];
|
||||
}
|
||||
|
||||
static NSString *temporaryPatchFile(NSString *patchFile)
|
||||
{
|
||||
NSString *path = absolutePath(patchFile);
|
||||
NSString *directory = [path stringByDeletingLastPathComponent];
|
||||
NSString *file = [path lastPathComponent];
|
||||
return [NSString stringWithFormat:@"%@/.%@.tmp", directory, file];
|
||||
}
|
||||
|
||||
static BOOL shouldSkipDeltaCompression(NSString * __unused key, NSDictionary* originalInfo, NSDictionary *newInfo)
|
||||
{
|
||||
unsigned long long fileSize = [newInfo[@"size"] unsignedLongLongValue];
|
||||
if (fileSize < 4096) {
|
||||
return YES;
|
||||
}
|
||||
|
||||
if (!originalInfo) {
|
||||
return YES;
|
||||
}
|
||||
|
||||
if ([originalInfo[@"type"] unsignedShortValue] != [newInfo[@"type"] unsignedShortValue]) {
|
||||
return YES;
|
||||
}
|
||||
|
||||
return NO;
|
||||
}
|
||||
|
||||
static BOOL shouldDeleteThenExtract(NSString * __unused key, NSDictionary* originalInfo, NSDictionary *newInfo)
|
||||
{
|
||||
if (!originalInfo) {
|
||||
return NO;
|
||||
}
|
||||
|
||||
if ([originalInfo[@"type"] unsignedShortValue] != [newInfo[@"type"] unsignedShortValue]) {
|
||||
return YES;
|
||||
}
|
||||
|
||||
return NO;
|
||||
if (args.count > 1) {
|
||||
printUsage(programName);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (args.count == 0) {
|
||||
fprintf(stdout, "%u.%u\n", LATEST_DELTA_DIFF_MAJOR_VERSION, latestMinorVersionForMajorVersion(LATEST_DELTA_DIFF_MAJOR_VERSION));
|
||||
} else {
|
||||
NSString *patchFile = args[0];
|
||||
xar_t x = xar_open([patchFile fileSystemRepresentation], READ);
|
||||
if (!x) {
|
||||
fprintf(stderr, "Unable to open patch %s\n", [patchFile fileSystemRepresentation]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
SUBinaryDeltaMajorVersion majorDiffVersion = FIRST_DELTA_DIFF_MAJOR_VERSION;
|
||||
SUBinaryDeltaMinorVersion minorDiffVersion = FIRST_DELTA_DIFF_MINOR_VERSION;
|
||||
|
||||
xar_subdoc_t subdoc;
|
||||
for (subdoc = xar_subdoc_first(x); subdoc; subdoc = xar_subdoc_next(subdoc)) {
|
||||
if (!strcmp(xar_subdoc_name(subdoc), BINARY_DELTA_ATTRIBUTES_KEY)) {
|
||||
const char *value = 0;
|
||||
|
||||
// available in version 2.0 or later
|
||||
xar_subdoc_prop_get(subdoc, MAJOR_DIFF_VERSION_KEY, &value);
|
||||
if (value)
|
||||
majorDiffVersion = (SUBinaryDeltaMajorVersion)[@(value) intValue];
|
||||
|
||||
// available in version 2.0 or later
|
||||
xar_subdoc_prop_get(subdoc, MINOR_DIFF_VERSION_KEY, &value);
|
||||
if (value)
|
||||
minorDiffVersion = (SUBinaryDeltaMinorVersion)[@(value) intValue];
|
||||
}
|
||||
}
|
||||
|
||||
fprintf(stdout, "%u.%u\n", majorDiffVersion, minorDiffVersion);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(int __unused argc, char __unused *argv[])
|
||||
{
|
||||
@autoreleasepool {
|
||||
NSArray *args = [[NSProcessInfo processInfo] arguments];
|
||||
if (args.count != 5) {
|
||||
usage:
|
||||
fprintf(stderr, "Usage: BinaryDelta [create | apply] before-tree after-tree patch-file\n");
|
||||
NSString *programName = [args[0] lastPathComponent];
|
||||
|
||||
if (args.count < 2) {
|
||||
printUsage(programName);
|
||||
return 1;
|
||||
}
|
||||
|
||||
NSString *command = args[1];
|
||||
NSString *oldPath = args[2];
|
||||
NSString *newPath = args[3];
|
||||
NSString *patchFile = args[4];
|
||||
|
||||
BOOL isDirectory;
|
||||
[[NSFileManager defaultManager] fileExistsAtPath:oldPath isDirectory:&isDirectory];
|
||||
if (!isDirectory) {
|
||||
fprintf(stderr, "Usage: before-tree must be a directory\n");
|
||||
return 1;
|
||||
NSArray *commandArguments = [args subarrayWithRange:NSMakeRange(2, args.count - 2)];
|
||||
|
||||
int result;
|
||||
if ([command isEqualToString:CREATE_COMMAND]) {
|
||||
result = runCreateCommand(programName, commandArguments);
|
||||
} else if ([command isEqualToString:APPLY_COMMAND]) {
|
||||
result = runApplyCommand(programName, commandArguments);
|
||||
} else if ([command isEqualToString:VERSION_COMMAND] || [command isEqualToString:VERSION_ALTERNATE_COMMAND]) {
|
||||
result = runVersionCommand(programName, commandArguments);
|
||||
} else {
|
||||
result = 1;
|
||||
printUsage(programName);
|
||||
}
|
||||
|
||||
[[NSFileManager defaultManager] fileExistsAtPath:newPath isDirectory:&isDirectory];
|
||||
if (!isDirectory) {
|
||||
fprintf(stderr, "Usage: after-tree must be a directory\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if ([command isEqualToString:@"apply"]) {
|
||||
int result = applyBinaryDelta(oldPath, newPath, patchFile);
|
||||
return result;
|
||||
}
|
||||
if (![command isEqualToString:@"create"]) {
|
||||
goto usage;
|
||||
}
|
||||
|
||||
NSMutableDictionary *originalTreeState = [NSMutableDictionary dictionary];
|
||||
|
||||
const char *sourcePaths[] = {[oldPath fileSystemRepresentation], 0};
|
||||
FTS *fts = fts_open((char* const*)sourcePaths, FTS_PHYSICAL | FTS_NOCHDIR, compareFiles);
|
||||
if (!fts) {
|
||||
perror("fts_open");
|
||||
return 1;
|
||||
}
|
||||
|
||||
fprintf(stderr, "Processing %s...", [oldPath UTF8String]);
|
||||
FTSENT *ent = 0;
|
||||
while ((ent = fts_read(fts))) {
|
||||
if (ent->fts_info != FTS_F && ent->fts_info != FTS_SL && ent->fts_info != FTS_D) {
|
||||
continue;
|
||||
}
|
||||
|
||||
NSString *key = pathRelativeToDirectory(oldPath, stringWithFileSystemRepresentation(ent->fts_path));
|
||||
if (![key length]) {
|
||||
continue;
|
||||
}
|
||||
|
||||
NSDictionary *info = infoForFile(ent);
|
||||
originalTreeState[key] = info;
|
||||
}
|
||||
fts_close(fts);
|
||||
|
||||
NSString *beforeHash = hashOfTree(oldPath);
|
||||
|
||||
NSMutableDictionary *newTreeState = [NSMutableDictionary dictionary];
|
||||
for (NSString *key in originalTreeState)
|
||||
{
|
||||
newTreeState[key] = [NSNull null];
|
||||
}
|
||||
|
||||
fprintf(stderr, "\nProcessing %s... ", [newPath UTF8String]);
|
||||
sourcePaths[0] = [newPath fileSystemRepresentation];
|
||||
fts = fts_open((char* const*)sourcePaths, FTS_PHYSICAL | FTS_NOCHDIR, compareFiles);
|
||||
if (!fts) {
|
||||
perror("fts_open");
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
while ((ent = fts_read(fts))) {
|
||||
if (ent->fts_info != FTS_F && ent->fts_info != FTS_SL && ent->fts_info != FTS_D) {
|
||||
continue;
|
||||
}
|
||||
|
||||
NSString *key = pathRelativeToDirectory(newPath, stringWithFileSystemRepresentation(ent->fts_path));
|
||||
if (![key length]) {
|
||||
continue;
|
||||
}
|
||||
|
||||
NSDictionary *info = infoForFile(ent);
|
||||
NSDictionary *oldInfo = originalTreeState[key];
|
||||
|
||||
if ([info isEqual:oldInfo])
|
||||
[newTreeState removeObjectForKey:key];
|
||||
else
|
||||
newTreeState[key] = info;
|
||||
}
|
||||
fts_close(fts);
|
||||
|
||||
NSString *afterHash = hashOfTree(newPath);
|
||||
|
||||
fprintf(stderr, "\nGenerating delta... ");
|
||||
|
||||
NSString *temporaryFile = temporaryPatchFile(patchFile);
|
||||
xar_t x = xar_open([temporaryFile fileSystemRepresentation], WRITE);
|
||||
xar_opt_set(x, XAR_OPT_COMPRESSION, "bzip2");
|
||||
xar_subdoc_t attributes = xar_subdoc_new(x, "binary-delta-attributes");
|
||||
xar_subdoc_prop_set(attributes, "before-sha1", [beforeHash UTF8String]);
|
||||
xar_subdoc_prop_set(attributes, "after-sha1", [afterHash UTF8String]);
|
||||
|
||||
NSOperationQueue *deltaQueue = [[NSOperationQueue alloc] init];
|
||||
NSMutableArray *deltaOperations = [NSMutableArray array];
|
||||
|
||||
NSArray *keys = [[newTreeState allKeys] sortedArrayUsingSelector:@selector(compare:)];
|
||||
for (NSString* key in keys) {
|
||||
id value = [newTreeState valueForKey:key];
|
||||
|
||||
if ([value isEqual:[NSNull null]]) {
|
||||
xar_file_t newFile = xar_add_frombuffer(x, 0, [key fileSystemRepresentation], (char *)"", 1);
|
||||
assert(newFile);
|
||||
xar_prop_set(newFile, "delete", "true");
|
||||
continue;
|
||||
}
|
||||
|
||||
NSDictionary *originalInfo = originalTreeState[key];
|
||||
NSDictionary *newInfo = newTreeState[key];
|
||||
if (shouldSkipDeltaCompression(key, originalInfo, newInfo)) {
|
||||
NSString *path = [newPath stringByAppendingPathComponent:key];
|
||||
xar_file_t newFile = xar_add_frompath(x, 0, [key fileSystemRepresentation], [path fileSystemRepresentation]);
|
||||
assert(newFile);
|
||||
if (shouldDeleteThenExtract(key, originalInfo, newInfo)) {
|
||||
xar_prop_set(newFile, "delete-then-extract", "true");
|
||||
}
|
||||
} else {
|
||||
CreateBinaryDeltaOperation *operation = [[CreateBinaryDeltaOperation alloc] initWithRelativePath:key oldTree:oldPath newTree:newPath];
|
||||
[deltaQueue addOperation:operation];
|
||||
[deltaOperations addObject:operation];
|
||||
}
|
||||
}
|
||||
|
||||
[deltaQueue waitUntilAllOperationsAreFinished];
|
||||
|
||||
for (CreateBinaryDeltaOperation *operation in deltaOperations) {
|
||||
NSString *resultPath = [operation resultPath];
|
||||
xar_file_t newFile = xar_add_frompath(x, 0, [[operation relativePath] fileSystemRepresentation], [resultPath fileSystemRepresentation]);
|
||||
assert(newFile);
|
||||
xar_prop_set(newFile, "binary-delta", "true");
|
||||
unlink([resultPath fileSystemRepresentation]);
|
||||
}
|
||||
|
||||
xar_close(x);
|
||||
|
||||
unlink([patchFile fileSystemRepresentation]);
|
||||
link([temporaryFile fileSystemRepresentation], [patchFile fileSystemRepresentation]);
|
||||
unlink([temporaryFile fileSystemRepresentation]);
|
||||
fprintf(stderr, "Done!\n");
|
||||
|
||||
return 0;
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -17,16 +17,16 @@
|
||||
|
||||
+ (BOOL)canUnarchivePath:(NSString *)path
|
||||
{
|
||||
return binaryDeltaSupported() && [[path pathExtension] isEqualToString:@"delta"];
|
||||
return [[path pathExtension] isEqualToString:@"delta"];
|
||||
}
|
||||
|
||||
- (void)applyBinaryDelta
|
||||
{
|
||||
@autoreleasepool {
|
||||
NSString *sourcePath = [[self.updateHost bundle] bundlePath];
|
||||
NSString *sourcePath = self.updateHostBundlePath;
|
||||
NSString *targetPath = [[self.archivePath stringByDeletingLastPathComponent] stringByAppendingPathComponent:[sourcePath lastPathComponent]];
|
||||
|
||||
int result = applyBinaryDelta(sourcePath, targetPath, self.archivePath);
|
||||
int result = applyBinaryDelta(sourcePath, targetPath, self.archivePath, NO);
|
||||
if (!result) {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[self notifyDelegateOfSuccess];
|
||||
|
||||
@@ -12,8 +12,10 @@
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
@interface SUCodeSigningVerifier : NSObject
|
||||
+ (BOOL)codeSignatureIsValidAtPath:(NSString *)destinationPath error:(NSError **)error;
|
||||
+ (BOOL)codeSignatureMatchesHostAndIsValidAtPath:(NSString *)applicationPath error:(NSError **)error;
|
||||
+ (BOOL)codeSignatureIsValidAtPath:(NSString *)applicationPath error:(NSError **)error;
|
||||
+ (BOOL)hostApplicationIsCodeSigned;
|
||||
+ (BOOL)applicationAtPathIsCodeSigned:(NSString *)applicationPath;
|
||||
@end
|
||||
|
||||
#endif
|
||||
@@ -13,7 +13,7 @@
|
||||
|
||||
@implementation SUCodeSigningVerifier
|
||||
|
||||
+ (BOOL)codeSignatureIsValidAtPath:(NSString *)destinationPath error:(NSError *__autoreleasing *)error
|
||||
+ (BOOL)codeSignatureMatchesHostAndIsValidAtPath:(NSString *)applicationPath error:(NSError *__autoreleasing *)error
|
||||
{
|
||||
OSStatus result;
|
||||
SecRequirementRef requirement = NULL;
|
||||
@@ -37,20 +37,23 @@
|
||||
goto finally;
|
||||
}
|
||||
|
||||
newBundle = [NSBundle bundleWithPath:destinationPath];
|
||||
newBundle = [NSBundle bundleWithPath:applicationPath];
|
||||
if (!newBundle) {
|
||||
SULog(@"Failed to load NSBundle for update");
|
||||
result = -1;
|
||||
goto finally;
|
||||
}
|
||||
|
||||
result = SecStaticCodeCreateWithPath((__bridge CFURLRef)[newBundle executableURL], kSecCSDefaultFlags, &staticCode);
|
||||
result = SecStaticCodeCreateWithPath((__bridge CFURLRef)[newBundle bundleURL], kSecCSDefaultFlags, &staticCode);
|
||||
if (result != noErr) {
|
||||
SULog(@"Failed to get static code %d", result);
|
||||
goto finally;
|
||||
}
|
||||
|
||||
result = SecStaticCodeCheckValidityWithErrors(staticCode, kSecCSDefaultFlags | kSecCSCheckAllArchitectures, requirement, &cfError);
|
||||
// Note that kSecCSCheckNestedCode may not work with pre-Mavericks code signing.
|
||||
// See https://github.com/sparkle-project/Sparkle/issues/376#issuecomment-48824267 and https://developer.apple.com/library/mac/technotes/tn2206
|
||||
SecCSFlags flags = kSecCSDefaultFlags | kSecCSCheckAllArchitectures;
|
||||
result = SecStaticCodeCheckValidityWithErrors(staticCode, flags, requirement, &cfError);
|
||||
|
||||
if (cfError) {
|
||||
NSError *tmpError = CFBridgingRelease(cfError);
|
||||
@@ -80,6 +83,53 @@ finally:
|
||||
return (result == noErr);
|
||||
}
|
||||
|
||||
+ (BOOL)codeSignatureIsValidAtPath:(NSString *)applicationPath error:(NSError *__autoreleasing *)error
|
||||
{
|
||||
OSStatus result;
|
||||
SecStaticCodeRef staticCode = NULL;
|
||||
NSBundle *newBundle;
|
||||
CFErrorRef cfError = NULL;
|
||||
if (error) {
|
||||
*error = nil;
|
||||
}
|
||||
|
||||
newBundle = [NSBundle bundleWithPath:applicationPath];
|
||||
if (!newBundle) {
|
||||
SULog(@"Failed to load NSBundle");
|
||||
result = -1;
|
||||
goto finally;
|
||||
}
|
||||
|
||||
result = SecStaticCodeCreateWithPath((__bridge CFURLRef)[newBundle bundleURL], kSecCSDefaultFlags, &staticCode);
|
||||
if (result != noErr) {
|
||||
SULog(@"Failed to get static code %d", result);
|
||||
goto finally;
|
||||
}
|
||||
|
||||
// Note that kSecCSCheckNestedCode may not work with pre-Mavericks code signing.
|
||||
// See https://github.com/sparkle-project/Sparkle/issues/376#issuecomment-48824267 and https://developer.apple.com/library/mac/technotes/tn2206
|
||||
SecCSFlags flags = kSecCSDefaultFlags | kSecCSCheckAllArchitectures;
|
||||
result = SecStaticCodeCheckValidityWithErrors(staticCode, flags, NULL, &cfError);
|
||||
|
||||
if (cfError) {
|
||||
NSError *tmpError = CFBridgingRelease(cfError);
|
||||
if (error) *error = tmpError;
|
||||
}
|
||||
|
||||
if (result != noErr) {
|
||||
if (result == errSecCSUnsigned) {
|
||||
SULog(@"Error: The app is not signed using Apple Code Signing. %@", applicationPath);
|
||||
}
|
||||
if (result == errSecCSReqFailed) {
|
||||
[self logSigningInfoForCode:staticCode label:@"new info"];
|
||||
}
|
||||
}
|
||||
|
||||
finally:
|
||||
if (staticCode) CFRelease(staticCode);
|
||||
return (result == noErr);
|
||||
}
|
||||
|
||||
static id valueOrNSNull(id value) {
|
||||
return value ? value : [NSNull null];
|
||||
}
|
||||
@@ -114,4 +164,35 @@ static id valueOrNSNull(id value) {
|
||||
return (result == 0);
|
||||
}
|
||||
|
||||
+ (BOOL)applicationAtPathIsCodeSigned:(NSString *)applicationPath
|
||||
{
|
||||
OSStatus result;
|
||||
SecStaticCodeRef staticCode = NULL;
|
||||
NSBundle *newBundle;
|
||||
|
||||
newBundle = [NSBundle bundleWithPath:applicationPath];
|
||||
if (!newBundle) {
|
||||
SULog(@"Failed to load NSBundle");
|
||||
return NO;
|
||||
}
|
||||
|
||||
result = SecStaticCodeCreateWithPath((__bridge CFURLRef)[newBundle bundleURL], kSecCSDefaultFlags, &staticCode);
|
||||
if (result == errSecCSUnsigned) {
|
||||
return NO;
|
||||
}
|
||||
|
||||
SecRequirementRef requirement = NULL;
|
||||
result = SecCodeCopyDesignatedRequirement(staticCode, kSecCSDefaultFlags, &requirement);
|
||||
if (staticCode) {
|
||||
CFRelease(staticCode);
|
||||
}
|
||||
if (requirement) {
|
||||
CFRelease(requirement);
|
||||
}
|
||||
if (result == errSecCSUnsigned) {
|
||||
return NO;
|
||||
}
|
||||
return (result == 0);
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,35 @@
|
||||
//
|
||||
// SUGuidedPackageInstaller.h
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Graham Miln on 14/05/2010.
|
||||
// Copyright 2010 Dragon Systems Software Limited. All rights reserved.
|
||||
//
|
||||
|
||||
/*!
|
||||
# Sparkle Guided Installations
|
||||
|
||||
A guided installation allows Sparkle to download and install a package (pkg) or multi-package (mpkg) without user interaction.
|
||||
|
||||
The installer package is installed using Mac OS X's built-in command line installer, `/usr/sbin/installer`. No installation interface is shown to the user.
|
||||
|
||||
A guided installation can be started by applications other than the application being replaced. This is particularly useful where helper applications or agents are used.
|
||||
|
||||
## To Do
|
||||
- Replace the use of `AuthorizationExecuteWithPrivilegesAndWait`. This method remains because it is well supported and tested. Ideally a helper tool or XPC would be used.
|
||||
*/
|
||||
|
||||
#ifndef SUGUIDEDPACKAGEINSTALLER_H
|
||||
#define SUGUIDEDPACKAGEINSTALLER_H
|
||||
|
||||
#import "Sparkle.h"
|
||||
#import "SUInstaller.h"
|
||||
|
||||
@interface SUGuidedPackageInstaller : SUInstaller {
|
||||
}
|
||||
|
||||
/*! Perform the guided installation */
|
||||
+ (void)performInstallationToPath:(NSString *)path fromPath:(NSString *)installerGuide host:(SUHost *)host versionComparator:(id<SUVersionComparison>)comparator completionHandler:(void (^)(NSError *))completionHandler;
|
||||
@end
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,139 @@
|
||||
//
|
||||
// SUGuidedPackageInstaller.m
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Graham Miln on 14/05/2010.
|
||||
// Copyright 2010 Dragon Systems Software Limited. All rights reserved.
|
||||
//
|
||||
|
||||
#import <sys/stat.h>
|
||||
#import <Security/Security.h>
|
||||
|
||||
#import "SUGuidedPackageInstaller.h"
|
||||
|
||||
static BOOL AuthorizationExecuteWithPrivilegesAndWait(AuthorizationRef authorization, const char* executablePath, AuthorizationFlags options, const char* const* arguments)
|
||||
{
|
||||
sig_t oldSigChildHandler = signal(SIGCHLD, SIG_DFL);
|
||||
BOOL returnValue = YES;
|
||||
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
||||
/* AuthorizationExecuteWithPrivileges used to support 10.4+; should be replaced with XPC or external process */
|
||||
if (AuthorizationExecuteWithPrivileges(authorization, executablePath, options, (char* const*)arguments, NULL) == errAuthorizationSuccess)
|
||||
#pragma clang diagnostic pop
|
||||
{
|
||||
int status = 0;
|
||||
pid_t pid = wait(&status);
|
||||
if (pid == -1 || !WIFEXITED(status) || WEXITSTATUS(status) != 0)
|
||||
returnValue = NO;
|
||||
}
|
||||
else
|
||||
returnValue = NO;
|
||||
|
||||
signal(SIGCHLD, oldSigChildHandler);
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
@implementation SUGuidedPackageInstaller (SUGuidedPackageInstallerAuthentication)
|
||||
|
||||
+ (AuthorizationRef)authorizationForExecutable:(NSString*)executablePath
|
||||
{
|
||||
NSParameterAssert(executablePath);
|
||||
|
||||
// Get authorization using advice in Apple's Technical Q&A1172
|
||||
|
||||
// ...create authorization without specific rights
|
||||
AuthorizationRef auth = NULL;
|
||||
OSStatus validAuth = AuthorizationCreate(NULL,
|
||||
kAuthorizationEmptyEnvironment,
|
||||
kAuthorizationFlagDefaults,
|
||||
&auth);
|
||||
// ...then extend authorization with desired rights
|
||||
if ((validAuth == errAuthorizationSuccess) &&
|
||||
(auth != NULL))
|
||||
{
|
||||
const char* executableFileSystemRepresentation = [executablePath fileSystemRepresentation];
|
||||
|
||||
// Prepare a right allowing script to execute with privileges
|
||||
AuthorizationItem right;
|
||||
memset(&right,0,sizeof(right));
|
||||
right.name = kAuthorizationRightExecute;
|
||||
right.value = (void*) executableFileSystemRepresentation;
|
||||
right.valueLength = strlen(executableFileSystemRepresentation);
|
||||
|
||||
// Package up the single right
|
||||
AuthorizationRights rights;
|
||||
memset(&rights,0,sizeof(rights));
|
||||
rights.count = 1;
|
||||
rights.items = &right;
|
||||
|
||||
// Extend rights to run script
|
||||
validAuth = AuthorizationCopyRights(auth,
|
||||
&rights,
|
||||
kAuthorizationEmptyEnvironment,
|
||||
kAuthorizationFlagPreAuthorize |
|
||||
kAuthorizationFlagExtendRights |
|
||||
kAuthorizationFlagInteractionAllowed,
|
||||
NULL);
|
||||
if (validAuth != errAuthorizationSuccess)
|
||||
{
|
||||
// Error, clean up authorization
|
||||
(void) AuthorizationFree(auth,kAuthorizationFlagDefaults);
|
||||
auth = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
return auth;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation SUGuidedPackageInstaller
|
||||
|
||||
+ (void)performInstallationToPath:(NSString *)destinationPath fromPath:(NSString *)packagePath host:(SUHost *)__unused host versionComparator:(id<SUVersionComparison>)__unused comparator completionHandler:(void (^)(NSError *))completionHandler
|
||||
{
|
||||
NSParameterAssert(packagePath);
|
||||
|
||||
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
|
||||
|
||||
// Preflight
|
||||
NSString* installerPath = @"/usr/sbin/installer"; // Mac OS X 10.2+ command line installer tool
|
||||
NSError* error = nil;
|
||||
|
||||
// Create authorization for installer executable
|
||||
BOOL validInstallation = NO;
|
||||
AuthorizationRef auth = [self authorizationForExecutable:installerPath];
|
||||
if (auth != NULL)
|
||||
{
|
||||
// Permission was granted to execute the installer with privileges
|
||||
const char* const arguments[] = {
|
||||
"-pkg",
|
||||
[packagePath fileSystemRepresentation],
|
||||
"-target",
|
||||
"/",
|
||||
NULL
|
||||
};
|
||||
validInstallation = AuthorizationExecuteWithPrivilegesAndWait(auth,
|
||||
[installerPath fileSystemRepresentation],
|
||||
kAuthorizationFlagDefaults,
|
||||
arguments);
|
||||
// TODO: wait for communications pipe to close via fileno & CFSocketCreateWithNative
|
||||
AuthorizationFree(auth,kAuthorizationFlagDefaults);
|
||||
}
|
||||
else
|
||||
{
|
||||
NSString* errorMessage = [NSString stringWithFormat:@"Sparkle Updater: Script authorization denied."];
|
||||
error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUInstallationError userInfo:[NSDictionary dictionaryWithObject:errorMessage forKey:NSLocalizedDescriptionKey]];
|
||||
}
|
||||
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[self finishInstallationToPath:destinationPath
|
||||
withResult:validInstallation
|
||||
error:error
|
||||
completionHandler:completionHandler];
|
||||
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -102,7 +102,13 @@ typedef struct {
|
||||
|
||||
- (NSString *)name
|
||||
{
|
||||
NSString *name = [self.bundle objectForInfoDictionaryKey:@"CFBundleDisplayName"];
|
||||
NSString *name;
|
||||
|
||||
// Allow host bundle to provide a custom name
|
||||
name = [self objectForInfoDictionaryKey:@"SUBundleName"];
|
||||
if (name) return name;
|
||||
|
||||
name = [self.bundle objectForInfoDictionaryKey:@"CFBundleDisplayName"];
|
||||
if (name) return name;
|
||||
|
||||
name = [self objectForInfoDictionaryKey:(__bridge NSString *)kCFBundleNameKey];
|
||||
|
||||
@@ -12,21 +12,14 @@
|
||||
#import <Cocoa/Cocoa.h>
|
||||
#import "SUVersionComparisonProtocol.h"
|
||||
|
||||
@protocol SUInstallerDelegate;
|
||||
|
||||
@class SUHost;
|
||||
@interface SUInstaller : NSObject
|
||||
|
||||
+ (NSString *)appPathInUpdateFolder:(NSString *)updateFolder forHost:(SUHost *)host;
|
||||
+ (void)installFromUpdateFolder:(NSString *)updateFolder overHost:(SUHost *)host installationPath:(NSString *)installationPath delegate:(id<SUInstallerDelegate>)delegate versionComparator:(id<SUVersionComparison>)comparator;
|
||||
+ (void)finishInstallationToPath:(NSString *)installationPath withResult:(BOOL)result host:(SUHost *)host error:(NSError *)error delegate:(id<SUInstallerDelegate>)delegate;
|
||||
+ (void)installFromUpdateFolder:(NSString *)updateFolder overHost:(SUHost *)host installationPath:(NSString *)installationPath versionComparator:(id<SUVersionComparison>)comparator completionHandler:(void (^)(NSError *))completionHandler;
|
||||
+ (void)finishInstallationToPath:(NSString *)installationPath withResult:(BOOL)result error:(NSError *)error completionHandler:(void (^)(NSError *))completionHandler;
|
||||
+ (NSString *)updateFolder;
|
||||
|
||||
@end
|
||||
|
||||
@protocol SUInstallerDelegate <NSObject>
|
||||
- (void)installerFinishedForHost:(SUHost *)host;
|
||||
- (void)installerForHost:(SUHost *)host failedWithError:(NSError *)error;
|
||||
@end
|
||||
|
||||
#endif
|
||||
@@ -9,11 +9,11 @@
|
||||
#import "SUInstaller.h"
|
||||
#import "SUPlainInstaller.h"
|
||||
#import "SUPackageInstaller.h"
|
||||
#import "SUGuidedPackageInstaller.h"
|
||||
#import "SUHost.h"
|
||||
#import "SUConstants.h"
|
||||
#import "SULog.h"
|
||||
|
||||
|
||||
@implementation SUInstaller
|
||||
|
||||
static NSString *sUpdateFolder = nil;
|
||||
@@ -42,50 +42,49 @@ static NSString *sUpdateFolder = nil;
|
||||
return NO;
|
||||
}
|
||||
|
||||
+ (NSString *)installSourcePathInUpdateFolder:(NSString *)inUpdateFolder forHost:(SUHost *)host isPackage:(BOOL *)isPackagePtr
|
||||
+ (NSString *)installSourcePathInUpdateFolder:(NSString *)inUpdateFolder forHost:(SUHost *)host isPackage:(BOOL *)isPackagePtr isGuided:(BOOL *)isGuidedPtr
|
||||
{
|
||||
NSParameterAssert(inUpdateFolder);
|
||||
NSParameterAssert(host);
|
||||
|
||||
// Search subdirectories for the application
|
||||
NSString *currentFile,
|
||||
*newAppDownloadPath = nil,
|
||||
*bundleFileName = [[host bundlePath] lastPathComponent],
|
||||
*alternateBundleFileName = [[host name] stringByAppendingPathExtension:[[host bundlePath] pathExtension]];
|
||||
BOOL isPackage = NO;
|
||||
BOOL isGuided = NO;
|
||||
NSString *fallbackPackagePath = nil;
|
||||
NSDirectoryEnumerator *dirEnum = [[NSFileManager defaultManager] enumeratorAtPath:inUpdateFolder];
|
||||
NSString *bundleFileNameNoExtension = [bundleFileName stringByDeletingPathExtension];
|
||||
|
||||
sUpdateFolder = inUpdateFolder;
|
||||
|
||||
while ((currentFile = [dirEnum nextObject]))
|
||||
{
|
||||
while ((currentFile = [dirEnum nextObject])) {
|
||||
NSString *currentPath = [inUpdateFolder stringByAppendingPathComponent:currentFile];
|
||||
if ([[currentFile lastPathComponent] isEqualToString:bundleFileName] ||
|
||||
[[currentFile lastPathComponent] isEqualToString:alternateBundleFileName]) // We found one!
|
||||
NSString *currentFilename = [currentFile lastPathComponent];
|
||||
NSString *currentExtension = [currentFile pathExtension];
|
||||
NSString *currentFilenameNoExtension = [currentFilename stringByDeletingPathExtension];
|
||||
if ([currentFilename isEqualToString:bundleFileName] ||
|
||||
[currentFilename isEqualToString:alternateBundleFileName]) // We found one!
|
||||
{
|
||||
isPackage = NO;
|
||||
newAppDownloadPath = currentPath;
|
||||
break;
|
||||
}
|
||||
else if ([[currentFile pathExtension] isEqualToString:@"pkg"] ||
|
||||
[[currentFile pathExtension] isEqualToString:@"mpkg"])
|
||||
{
|
||||
if ([[[currentFile lastPathComponent] stringByDeletingPathExtension] isEqualToString:[bundleFileName stringByDeletingPathExtension]])
|
||||
{
|
||||
} else if ([currentExtension isEqualToString:@"pkg"] ||
|
||||
[currentExtension isEqualToString:@"mpkg"]) {
|
||||
if ([currentFilenameNoExtension isEqualToString:bundleFileNameNoExtension]) {
|
||||
isPackage = YES;
|
||||
newAppDownloadPath = currentPath;
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
// Remember any other non-matching packages we have seen should we need to use one of them as a fallback.
|
||||
fallbackPackagePath = currentPath;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
// Try matching on bundle identifiers in case the user has changed the name of the host app
|
||||
NSBundle *incomingBundle = [NSBundle bundleWithPath:currentPath];
|
||||
if(incomingBundle && [[incomingBundle bundleIdentifier] isEqualToString:[[host bundle] bundleIdentifier]])
|
||||
{
|
||||
if (incomingBundle && [[incomingBundle bundleIdentifier] isEqualToString:[[host bundle] bundleIdentifier]]) {
|
||||
isPackage = NO;
|
||||
newAppDownloadPath = currentPath;
|
||||
break;
|
||||
@@ -99,35 +98,52 @@ static NSString *sUpdateFolder = nil;
|
||||
|
||||
// We don't have a valid path. Try to use the fallback package.
|
||||
|
||||
if (newAppDownloadPath == nil && fallbackPackagePath != nil)
|
||||
{
|
||||
if (newAppDownloadPath == nil && fallbackPackagePath != nil) {
|
||||
isPackage = YES;
|
||||
newAppDownloadPath = fallbackPackagePath;
|
||||
}
|
||||
|
||||
if (isPackagePtr) *isPackagePtr = isPackage;
|
||||
if (isPackage) {
|
||||
// foo.app -> foo.sparkle_guided.pkg or foo.sparkle_guided.mpkg
|
||||
if ([[[newAppDownloadPath stringByDeletingPathExtension] pathExtension] isEqualToString:@"sparkle_guided"]) {
|
||||
isGuided = YES;
|
||||
}
|
||||
}
|
||||
|
||||
if (isPackagePtr)
|
||||
*isPackagePtr = isPackage;
|
||||
if (isGuidedPtr)
|
||||
*isGuidedPtr = isGuided;
|
||||
|
||||
if (!newAppDownloadPath) {
|
||||
SULog(@"Searched %@ for %@.(app|pkg)", inUpdateFolder, bundleFileNameNoExtension);
|
||||
}
|
||||
return newAppDownloadPath;
|
||||
}
|
||||
|
||||
+ (NSString *)appPathInUpdateFolder:(NSString *)updateFolder forHost:(SUHost *)host
|
||||
{
|
||||
BOOL isPackage = NO;
|
||||
NSString *path = [self installSourcePathInUpdateFolder:updateFolder forHost:host isPackage:&isPackage];
|
||||
NSString *path = [self installSourcePathInUpdateFolder:updateFolder forHost:host isPackage:&isPackage isGuided:nil];
|
||||
return isPackage ? nil : path;
|
||||
}
|
||||
|
||||
+ (void)installFromUpdateFolder:(NSString *)inUpdateFolder overHost:(SUHost *)host installationPath:(NSString *)installationPath delegate:(id<SUInstallerDelegate>)delegate versionComparator:(id<SUVersionComparison>)comparator
|
||||
+ (void)installFromUpdateFolder:(NSString *)inUpdateFolder overHost:(SUHost *)host installationPath:(NSString *)installationPath versionComparator:(id<SUVersionComparison>)comparator completionHandler:(void (^)(NSError *))completionHandler
|
||||
{
|
||||
BOOL isPackage = NO;
|
||||
NSString *newAppDownloadPath = [self installSourcePathInUpdateFolder:inUpdateFolder forHost:host isPackage:&isPackage];
|
||||
BOOL isGuided = NO;
|
||||
NSString *newAppDownloadPath = [self installSourcePathInUpdateFolder:inUpdateFolder forHost:host isPackage:&isPackage isGuided:&isGuided];
|
||||
|
||||
if (newAppDownloadPath == nil)
|
||||
{
|
||||
[self finishInstallationToPath:installationPath withResult:NO host:host error:[NSError errorWithDomain:SUSparkleErrorDomain code:SUMissingUpdateError userInfo:@{ NSLocalizedDescriptionKey: @"Couldn't find an appropriate update in the downloaded package." }] delegate:delegate];
|
||||
}
|
||||
else
|
||||
{
|
||||
[(isPackage ? [SUPackageInstaller class] : [SUPlainInstaller class])performInstallationToPath:installationPath fromPath:newAppDownloadPath host:host delegate:delegate versionComparator:comparator];
|
||||
if (newAppDownloadPath == nil) {
|
||||
[self finishInstallationToPath:installationPath withResult:NO error:[NSError errorWithDomain:SUSparkleErrorDomain code:SUMissingUpdateError userInfo:@{ NSLocalizedDescriptionKey: @"Couldn't find an appropriate update in the downloaded package." }] completionHandler:completionHandler];
|
||||
} else {
|
||||
if (isPackage && isGuided) {
|
||||
[SUGuidedPackageInstaller performInstallationToPath:installationPath fromPath:newAppDownloadPath host:host versionComparator:comparator completionHandler:completionHandler];
|
||||
} else if (isPackage) {
|
||||
[SUPackageInstaller performInstallationToPath:installationPath fromPath:newAppDownloadPath host:host versionComparator:comparator completionHandler:completionHandler];
|
||||
} else {
|
||||
[SUPlainInstaller performInstallationToPath:installationPath fromPath:newAppDownloadPath host:host versionComparator:comparator completionHandler:completionHandler];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -140,8 +156,7 @@ static NSString *sUpdateFolder = nil;
|
||||
NSTask *mdimport = [[NSTask alloc] init];
|
||||
[mdimport setLaunchPath:@"/usr/bin/mdimport"];
|
||||
[mdimport setArguments:@[installationPath]];
|
||||
@try
|
||||
{
|
||||
@try {
|
||||
[mdimport launch];
|
||||
[mdimport waitUntilExit];
|
||||
}
|
||||
@@ -152,24 +167,20 @@ static NSString *sUpdateFolder = nil;
|
||||
}
|
||||
}
|
||||
|
||||
+ (void)finishInstallationToPath:(NSString *)installationPath withResult:(BOOL)result host:(SUHost *)host error:(NSError *)error delegate:(id<SUInstallerDelegate>)delegate
|
||||
+ (void)finishInstallationToPath:(NSString *)installationPath withResult:(BOOL)result error:(NSError *)error completionHandler:(void (^)(NSError *))completionHandler
|
||||
{
|
||||
if (result)
|
||||
{
|
||||
if (result) {
|
||||
[self mdimportInstallationPath:installationPath];
|
||||
if ([delegate respondsToSelector:@selector(installerFinishedForHost:)]) {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[delegate installerFinishedForHost:host];
|
||||
});
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ([delegate respondsToSelector:@selector(installerForHost:failedWithError:)]) {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[delegate installerForHost:host failedWithError:error];
|
||||
});
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
completionHandler(nil);
|
||||
});
|
||||
} else {
|
||||
if (!error) {
|
||||
error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUInstallationError userInfo:nil];
|
||||
}
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
completionHandler(error);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
|
||||
@implementation SUPackageInstaller
|
||||
|
||||
+ (void)performInstallationToPath:(NSString *)installationPath fromPath:(NSString *)path host:(SUHost *)host delegate:(id<SUInstallerDelegate>)delegate versionComparator:(id<SUVersionComparison>)__unused comparator
|
||||
+ (void)performInstallationToPath:(NSString *)installationPath fromPath:(NSString *)path host:(SUHost *)__unused host versionComparator:(id<SUVersionComparison>)__unused comparator completionHandler:(void (^)(NSError *))completionHandler
|
||||
{
|
||||
// Run installer using the "open" command to ensure it is launched in front of current application.
|
||||
// -W = wait until the app has quit.
|
||||
@@ -23,7 +23,7 @@
|
||||
|
||||
if (![[NSFileManager defaultManager] fileExistsAtPath:command]) {
|
||||
NSError *error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUMissingInstallerToolError userInfo:@{ NSLocalizedDescriptionKey: @"Couldn't find Apple's installer tool!" }];
|
||||
[self finishInstallationToPath:installationPath withResult:NO host:host error:error delegate:delegate];
|
||||
[self finishInstallationToPath:installationPath withResult:NO error:error completionHandler:completionHandler];
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@
|
||||
|
||||
// Known bug: if the installation fails or is canceled, Sparkle goes ahead and restarts, thinking everything is fine.
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[self finishInstallationToPath:installationPath withResult:YES host:host error:nil delegate:delegate];
|
||||
[self finishInstallationToPath:installationPath withResult:YES error:nil completionHandler:completionHandler];
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -48,73 +48,69 @@
|
||||
}
|
||||
|
||||
// This method abstracts the types that use a command line tool piping data from stdin.
|
||||
- (void)extractArchivePipingDataToCommand:(NSString *)command
|
||||
- (void)extractArchivePipingDataToCommand:(NSString *)command args:(NSArray*)args
|
||||
{
|
||||
// *** GETS CALLED ON NON-MAIN THREAD!!!
|
||||
@autoreleasepool {
|
||||
FILE *fp = NULL, *cmdFP = NULL;
|
||||
char *oldDestinationString = NULL;
|
||||
// We have to declare these before a goto to prevent an error under ARC.
|
||||
// No, we cannot have them in the dispatch_async calls, as the goto "jump enters
|
||||
// lifetime of block which strongly captures a variable"
|
||||
dispatch_block_t delegateSuccess = ^{
|
||||
[self notifyDelegateOfSuccess];
|
||||
};
|
||||
dispatch_block_t delegateFailure = ^{
|
||||
[self notifyDelegateOfFailure];
|
||||
};
|
||||
|
||||
SULog(@"Extracting %@ using '%@'", self.archivePath, command);
|
||||
NSString *destination = [self.archivePath stringByDeletingLastPathComponent];
|
||||
|
||||
SULog(@"Extracting using '%@' '%@' < '%@' '%@'", command, [args componentsJoinedByString:@"' '"], self.archivePath, destination);
|
||||
|
||||
// Get the file size.
|
||||
NSNumber *fs = [[NSFileManager defaultManager] attributesOfItemAtPath:self.archivePath error:nil][NSFileSize];
|
||||
if (fs == nil) goto reportError;
|
||||
NSUInteger expectedLength = [[[NSFileManager defaultManager] attributesOfItemAtPath:self.archivePath error:nil][NSFileSize] unsignedIntegerValue];
|
||||
if (expectedLength > 0) {
|
||||
NSFileHandle *archiveInput = [NSFileHandle fileHandleForReadingAtPath:self.archivePath];
|
||||
|
||||
// Thank you, Allan Odgaard!
|
||||
// (who wrote the following extraction alg.)
|
||||
fp = fopen([self.archivePath fileSystemRepresentation], "r");
|
||||
if (!fp) goto reportError;
|
||||
NSPipe *pipe = [NSPipe pipe];
|
||||
NSFileHandle *archiveOutput = [pipe fileHandleForWriting];
|
||||
|
||||
oldDestinationString = getenv("DESTINATION");
|
||||
setenv("DESTINATION", [[self.archivePath stringByDeletingLastPathComponent] fileSystemRepresentation], 1);
|
||||
cmdFP = popen([command fileSystemRepresentation], "w");
|
||||
size_t written;
|
||||
if (!cmdFP) goto reportError;
|
||||
NSTask *task = [[NSTask alloc] init];
|
||||
[task setStandardInput:[pipe fileHandleForReading]];
|
||||
[task setStandardError:[NSFileHandle fileHandleWithStandardError]];
|
||||
[task setStandardOutput:[NSFileHandle fileHandleWithStandardOutput]];
|
||||
[task setLaunchPath:command];
|
||||
[task setArguments:[args arrayByAddingObject:destination]];
|
||||
[task launch];
|
||||
|
||||
char buf[32 * 1024];
|
||||
size_t len;
|
||||
while((len = fread(buf, 1, 32*1024, fp)))
|
||||
{
|
||||
written = fwrite(buf, 1, len, cmdFP);
|
||||
if( written < len )
|
||||
{
|
||||
pclose(cmdFP);
|
||||
goto reportError;
|
||||
NSUInteger bytesRead = 0;
|
||||
do {
|
||||
NSData *data = [archiveInput readDataOfLength:256*1024];
|
||||
NSUInteger len = [data length];
|
||||
if (!len) {
|
||||
break;
|
||||
}
|
||||
bytesRead += len;
|
||||
[archiveOutput writeData:data];
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[self notifyDelegateOfProgress:(double)bytesRead / (double)expectedLength];
|
||||
});
|
||||
}
|
||||
while(bytesRead < expectedLength);
|
||||
|
||||
[archiveOutput closeFile];
|
||||
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[self notifyDelegateOfExtractedLength:len];
|
||||
});
|
||||
}
|
||||
pclose(cmdFP);
|
||||
|
||||
if (ferror(fp)) {
|
||||
goto reportError;
|
||||
[task waitUntilExit];
|
||||
|
||||
if ([task terminationStatus] == 0) {
|
||||
if (bytesRead == expectedLength) {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[self notifyDelegateOfSuccess];
|
||||
});
|
||||
return;
|
||||
} else {
|
||||
SULog(@"Extraction failed, command '%@' got only %ld of %ld bytes", command, (long)bytesRead, (long)expectedLength);
|
||||
}
|
||||
} else {
|
||||
SULog(@"Extraction failed, command '%@' returned %d", command, [task terminationStatus]);
|
||||
}
|
||||
} else {
|
||||
SULog(@"Extraction failed, archive '%@' is empty", self.archivePath);
|
||||
}
|
||||
|
||||
dispatch_async(dispatch_get_main_queue(), delegateSuccess);
|
||||
goto finally;
|
||||
|
||||
reportError:
|
||||
dispatch_async(dispatch_get_main_queue(), delegateFailure);
|
||||
|
||||
finally:
|
||||
if (fp)
|
||||
fclose(fp);
|
||||
if (oldDestinationString)
|
||||
setenv("DESTINATION", oldDestinationString, 1);
|
||||
else
|
||||
unsetenv("DESTINATION");
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[self notifyDelegateOfFailure];
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -122,35 +118,35 @@
|
||||
{
|
||||
// *** GETS CALLED ON NON-MAIN THREAD!!!
|
||||
|
||||
[self extractArchivePipingDataToCommand:@"tar -xC \"$DESTINATION\""];
|
||||
[self extractArchivePipingDataToCommand:@"/usr/bin/tar" args:@[@"-xC"]];
|
||||
}
|
||||
|
||||
- (void)extractTGZ
|
||||
{
|
||||
// *** GETS CALLED ON NON-MAIN THREAD!!!
|
||||
|
||||
[self extractArchivePipingDataToCommand:@"tar -zxC \"$DESTINATION\""];
|
||||
[self extractArchivePipingDataToCommand:@"/usr/bin/tar" args:@[@"-zxC"]];
|
||||
}
|
||||
|
||||
- (void)extractTBZ
|
||||
{
|
||||
// *** GETS CALLED ON NON-MAIN THREAD!!!
|
||||
|
||||
[self extractArchivePipingDataToCommand:@"tar -jxC \"$DESTINATION\""];
|
||||
[self extractArchivePipingDataToCommand:@"/usr/bin/tar" args:@[@"-jxC"]];
|
||||
}
|
||||
|
||||
- (void)extractZIP
|
||||
{
|
||||
// *** GETS CALLED ON NON-MAIN THREAD!!!
|
||||
|
||||
[self extractArchivePipingDataToCommand:@"ditto -x -k - \"$DESTINATION\""];
|
||||
[self extractArchivePipingDataToCommand:@"/usr/bin/ditto" args:@[@"-x",@"-k",@"-"]];
|
||||
}
|
||||
|
||||
- (void)extractTXZ
|
||||
{
|
||||
// *** GETS CALLED ON NON-MAIN THREAD!!!
|
||||
|
||||
[self extractArchivePipingDataToCommand:@"tar -zxC \"$DESTINATION\""];
|
||||
[self extractArchivePipingDataToCommand:@"/usr/bin/tar" args:@[@"-zxC"]];
|
||||
}
|
||||
|
||||
+ (void)load
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
|
||||
@interface SUPlainInstaller : SUInstaller
|
||||
|
||||
+ (void)performInstallationToPath:(NSString *)installationPath fromPath:(NSString *)path host:(SUHost *)host delegate:(id<SUInstallerDelegate>)delegate versionComparator:(id<SUVersionComparison>)comparator;
|
||||
+ (void)performInstallationToPath:(NSString *)installationPath fromPath:(NSString *)path host:(SUHost *)host versionComparator:(id<SUVersionComparison>)comparator completionHandler:(void (^)(NSError *))completionHandler;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@@ -8,20 +8,22 @@
|
||||
|
||||
#import "SUPlainInstaller.h"
|
||||
#import "SUPlainInstallerInternals.h"
|
||||
#import "SUCodeSigningVerifier.h"
|
||||
#import "SUConstants.h"
|
||||
#import "SUHost.h"
|
||||
|
||||
@implementation SUPlainInstaller
|
||||
|
||||
+ (void)performInstallationToPath:(NSString *)installationPath fromPath:(NSString *)path host:(SUHost *)host delegate:(id<SUInstallerDelegate>)delegate versionComparator:(id<SUVersionComparison>)comparator
|
||||
+ (void)performInstallationToPath:(NSString *)installationPath fromPath:(NSString *)path host:(SUHost *)host versionComparator:(id<SUVersionComparison>)comparator completionHandler:(void (^)(NSError *))completionHandler
|
||||
{
|
||||
NSParameterAssert(host);
|
||||
|
||||
// Prevent malicious downgrades
|
||||
if (![[[NSBundle bundleWithIdentifier:SUBundleIdentifier] infoDictionary][SUEnableAutomatedDowngradesKey] boolValue]) {
|
||||
if ([comparator compareVersion:[host version] toVersion:[[NSBundle bundleWithPath:path] objectForInfoDictionaryKey:(__bridge NSString *)kCFBundleVersionKey]] == NSOrderedDescending)
|
||||
{
|
||||
if ([comparator compareVersion:[host version] toVersion:[[NSBundle bundleWithPath:path] objectForInfoDictionaryKey:(__bridge NSString *)kCFBundleVersionKey]] == NSOrderedDescending) {
|
||||
NSString *errorMessage = [NSString stringWithFormat:@"Sparkle Updater: Possible attack in progress! Attempting to \"upgrade\" from %@ to %@. Aborting update.", [host version], [[NSBundle bundleWithPath:path] objectForInfoDictionaryKey:(__bridge NSString *)kCFBundleVersionKey]];
|
||||
NSError *error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUDowngradeError userInfo:@{ NSLocalizedDescriptionKey: errorMessage }];
|
||||
[self finishInstallationToPath:installationPath withResult:NO host:host error:error delegate:delegate];
|
||||
[self finishInstallationToPath:installationPath withResult:NO error:error completionHandler:completionHandler];
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -30,8 +32,17 @@
|
||||
NSError *error = nil;
|
||||
NSString *oldPath = [host bundlePath];
|
||||
NSString *tempName = [self temporaryNameForPath:[host installationPath]];
|
||||
BOOL hostIsCodeSigned = [SUCodeSigningVerifier applicationAtPathIsCodeSigned:oldPath];
|
||||
|
||||
BOOL result = [self copyPathWithAuthentication:path overPath:installationPath temporaryName:tempName error:&error];
|
||||
|
||||
if (result) {
|
||||
// If the host is code signed, then the replacement should be be too (and the signature should be valid).
|
||||
BOOL needToCheckCodeSignature = (hostIsCodeSigned || [SUCodeSigningVerifier applicationAtPathIsCodeSigned:installationPath]);
|
||||
if (needToCheckCodeSignature) {
|
||||
result = [SUCodeSigningVerifier codeSignatureIsValidAtPath:installationPath error:&error];
|
||||
}
|
||||
}
|
||||
|
||||
if (result) {
|
||||
BOOL haveOld = [[NSFileManager defaultManager] fileExistsAtPath:oldPath];
|
||||
@@ -42,7 +53,7 @@
|
||||
}
|
||||
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[self finishInstallationToPath:installationPath withResult:result host:host error:error delegate:delegate];
|
||||
[self finishInstallationToPath:installationPath withResult:result error:error completionHandler:completionHandler];
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@
|
||||
|
||||
- (instancetype)initWithHost:(SUHost *)aHost
|
||||
{
|
||||
self = [super initWithHost:aHost windowNibName:@"SUStatus"];
|
||||
self = [super initWithWindowNibName:@"SUStatus"];
|
||||
if (self)
|
||||
{
|
||||
self.host = aHost;
|
||||
|
||||
@@ -15,11 +15,12 @@
|
||||
|
||||
@class SUStatusController;
|
||||
|
||||
@interface SUUIBasedUpdateDriver : SUBasicUpdateDriver <SUUnarchiverDelegate, SUUpdateAlertDelegate>
|
||||
@interface SUUIBasedUpdateDriver : SUBasicUpdateDriver <SUUnarchiverDelegate>
|
||||
|
||||
- (void)showModalAlert:(NSAlert *)alert;
|
||||
- (IBAction)cancelDownload:(id)sender;
|
||||
- (void)installAndRestart:(id)sender;
|
||||
- (void)appcastDidFinishLoading:(SUAppcast *)ac;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@@ -28,8 +28,9 @@
|
||||
|
||||
- (void)didFindValidUpdate
|
||||
{
|
||||
self.updateAlert = [[SUUpdateAlert alloc] initWithAppcastItem:self.updateItem host:self.host];
|
||||
[self.updateAlert setDelegate:self];
|
||||
self.updateAlert = [[SUUpdateAlert alloc] initWithAppcastItem:self.updateItem host:self.host completionBlock:^(SUUpdateAlertChoice choice) {
|
||||
[self updateAlertFinishedWithChoice:choice];
|
||||
}];
|
||||
|
||||
id<SUVersionDisplay> versDisp = nil;
|
||||
if ([[self.updater delegate] respondsToSelector:@selector(versionDisplayerForUpdater:)]) {
|
||||
@@ -44,8 +45,7 @@
|
||||
// If the app is a menubar app or the like, we need to focus it first and alter the
|
||||
// update prompt to behave like a normal window. Otherwise if the window were hidden
|
||||
// there may be no way for the application to be activated to make it visible again.
|
||||
if ([self.host isBackgroundApplication])
|
||||
{
|
||||
if ([self.host isBackgroundApplication]) {
|
||||
[[self.updateAlert window] setHidesOnDeactivate:NO];
|
||||
[NSApp activateIgnoringOtherApps:YES];
|
||||
}
|
||||
@@ -78,12 +78,11 @@
|
||||
[[NSNotificationCenter defaultCenter] removeObserver:self name:NSApplicationDidBecomeActiveNotification object:NSApp];
|
||||
}
|
||||
|
||||
- (void)updateAlert:(SUUpdateAlert *)__unused alert finishedWithChoice:(SUUpdateAlertChoice)choice
|
||||
- (void)updateAlertFinishedWithChoice:(SUUpdateAlertChoice)choice
|
||||
{
|
||||
self.updateAlert = nil;
|
||||
[self.host setObject:nil forUserDefaultsKey:SUSkippedVersionKey];
|
||||
switch (choice)
|
||||
{
|
||||
switch (choice) {
|
||||
case SUInstallUpdateChoice:
|
||||
self.statusController = [[SUStatusController alloc] initWithHost:self.host];
|
||||
[self.statusController beginActionWithTitle:SULocalizedString(@"Downloading update...", @"Take care not to overflow the status window.") maxProgressValue:0.0 statusText:nil];
|
||||
@@ -154,16 +153,13 @@
|
||||
[super extractUpdate];
|
||||
}
|
||||
|
||||
- (void)unarchiver:(SUUnarchiver *)__unused ua extractedLength:(unsigned long)length
|
||||
- (void)unarchiver:(SUUnarchiver *)__unused ua extractedProgress:(double)progress
|
||||
{
|
||||
// We do this here instead of in extractUpdate so that we only have a determinate progress bar for archives with progress.
|
||||
if ([self.statusController maxProgressValue] == 0.0)
|
||||
{
|
||||
NSDictionary *attributes;
|
||||
attributes = [[NSFileManager defaultManager] attributesOfItemAtPath:self.downloadPath error:nil];
|
||||
[self.statusController setMaxProgressValue:[attributes[NSFileSize] doubleValue]];
|
||||
if ([self.statusController maxProgressValue] == 0.0) {
|
||||
[self.statusController setMaxProgressValue:1];
|
||||
}
|
||||
[self.statusController setProgressValue:[self.statusController progressValue] + (double)length];
|
||||
[self.statusController setProgressValue:progress];
|
||||
}
|
||||
|
||||
- (void)unarchiverDidFinish:(SUUnarchiver *)__unused ua
|
||||
|
||||
@@ -15,10 +15,10 @@
|
||||
@interface SUUnarchiver : NSObject
|
||||
|
||||
@property (copy, readonly) NSString *archivePath;
|
||||
@property (weak, readonly) SUHost *updateHost;
|
||||
@property (weak, readonly) NSString *updateHostBundlePath;
|
||||
@property (weak) id<SUUnarchiverDelegate> delegate;
|
||||
|
||||
+ (SUUnarchiver *)unarchiverForPath:(NSString *)path updatingHost:(SUHost *)host;
|
||||
+ (SUUnarchiver *)unarchiverForPath:(NSString *)path updatingHostBundlePath:(NSString *)host;
|
||||
|
||||
- (void)start;
|
||||
@end
|
||||
@@ -27,7 +27,7 @@
|
||||
- (void)unarchiverDidFinish:(SUUnarchiver *)unarchiver;
|
||||
- (void)unarchiverDidFail:(SUUnarchiver *)unarchiver;
|
||||
@optional
|
||||
- (void)unarchiver:(SUUnarchiver *)unarchiver extractedLength:(unsigned long)length;
|
||||
- (void)unarchiver:(SUUnarchiver *)unarchiver extractedProgress:(double)progress;
|
||||
@end
|
||||
|
||||
#endif
|
||||
@@ -18,15 +18,15 @@
|
||||
@implementation SUUnarchiver
|
||||
|
||||
@synthesize archivePath;
|
||||
@synthesize updateHost;
|
||||
@synthesize updateHostBundlePath;
|
||||
@synthesize delegate;
|
||||
|
||||
+ (SUUnarchiver *)unarchiverForPath:(NSString *)path updatingHost:(SUHost *)host
|
||||
+ (SUUnarchiver *)unarchiverForPath:(NSString *)path updatingHostBundlePath:(NSString *)hostPath
|
||||
{
|
||||
for (id current in [self unarchiverImplementations])
|
||||
{
|
||||
if ([current canUnarchivePath:path]) {
|
||||
return [[current alloc] initWithPath:path host:host];
|
||||
return [[current alloc] initWithPath:path hostBundlePath:hostPath];
|
||||
}
|
||||
}
|
||||
return nil;
|
||||
@@ -39,12 +39,12 @@
|
||||
// No-op
|
||||
}
|
||||
|
||||
- (instancetype)initWithPath:(NSString *)path host:(SUHost *)host
|
||||
- (instancetype)initWithPath:(NSString *)path hostBundlePath:(NSString *)hostPath
|
||||
{
|
||||
if ((self = [super init]))
|
||||
{
|
||||
archivePath = [path copy];
|
||||
updateHost = host;
|
||||
updateHostBundlePath = hostPath;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
@@ -54,10 +54,10 @@
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (void)notifyDelegateOfExtractedLength:(size_t)length
|
||||
- (void)notifyDelegateOfProgress:(double)progress
|
||||
{
|
||||
if ([self.delegate respondsToSelector:@selector(unarchiver:extractedLength:)]) {
|
||||
[self.delegate unarchiver:self extractedLength:length];
|
||||
if ([self.delegate respondsToSelector:@selector(unarchiver:extractedProgress:)]) {
|
||||
[self.delegate unarchiver:self extractedProgress:progress];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -16,9 +16,9 @@
|
||||
+ (void)registerImplementation:(Class)implementation;
|
||||
+ (NSArray *)unarchiverImplementations;
|
||||
+ (BOOL)canUnarchivePath:(NSString *)path;
|
||||
- (instancetype)initWithPath:(NSString *)path host:(SUHost *)host;
|
||||
- (instancetype)initWithPath:(NSString *)archive hostBundlePath:(NSString *)host;
|
||||
|
||||
- (void)notifyDelegateOfExtractedLength:(size_t)length;
|
||||
- (void)notifyDelegateOfProgress:(double)progress;
|
||||
- (void)notifyDelegateOfSuccess;
|
||||
- (void)notifyDelegateOfFailure;
|
||||
@end
|
||||
|
||||
@@ -24,10 +24,9 @@ typedef NS_ENUM(NSInteger, SUUpdateAlertChoice) {
|
||||
@class WebView, SUAppcastItem, SUHost;
|
||||
@interface SUUpdateAlert : SUWindowController
|
||||
|
||||
@property (weak) id<SUUpdateAlertDelegate> delegate;
|
||||
@property (weak) id<SUVersionDisplay> versionDisplayer;
|
||||
|
||||
- (instancetype)initWithAppcastItem:(SUAppcastItem *)item host:(SUHost *)host;
|
||||
- (instancetype)initWithAppcastItem:(SUAppcastItem *)item host:(SUHost *)host completionBlock:(void(^)(SUUpdateAlertChoice))c;
|
||||
|
||||
- (IBAction)installUpdate:sender;
|
||||
- (IBAction)skipThisVersion:sender;
|
||||
@@ -35,10 +34,4 @@ typedef NS_ENUM(NSInteger, SUUpdateAlertChoice) {
|
||||
|
||||
@end
|
||||
|
||||
@protocol SUUpdateAlertDelegate <NSObject>
|
||||
- (void)updateAlert:(SUUpdateAlert *)updateAlert finishedWithChoice:(SUUpdateAlertChoice)updateChoice;
|
||||
@optional
|
||||
- (void)updateAlert:(SUUpdateAlert *)updateAlert shouldAllowAutoUpdate:(BOOL *)shouldAllowAutoUpdate;
|
||||
@end
|
||||
|
||||
#endif
|
||||
@@ -21,6 +21,7 @@
|
||||
|
||||
@property (strong) SUAppcastItem *updateItem;
|
||||
@property (strong) SUHost *host;
|
||||
@property (strong) void(^completionBlock)(SUUpdateAlertChoice);
|
||||
|
||||
@property (strong) NSProgressIndicator *releaseNotesSpinner;
|
||||
@property (assign) BOOL webViewFinishedLoading;
|
||||
@@ -36,7 +37,7 @@
|
||||
|
||||
@implementation SUUpdateAlert
|
||||
|
||||
@synthesize delegate;
|
||||
@synthesize completionBlock;
|
||||
@synthesize versionDisplayer;
|
||||
|
||||
@synthesize updateItem;
|
||||
@@ -52,11 +53,12 @@
|
||||
@synthesize skipButton;
|
||||
@synthesize laterButton;
|
||||
|
||||
- (instancetype)initWithAppcastItem:(SUAppcastItem *)item host:(SUHost *)aHost
|
||||
- (instancetype)initWithAppcastItem:(SUAppcastItem *)item host:(SUHost *)aHost completionBlock:(void (^)(SUUpdateAlertChoice))block
|
||||
{
|
||||
self = [super initWithHost:host windowNibName:@"SUUpdateAlert"];
|
||||
self = [super initWithWindowNibName:@"SUUpdateAlert"];
|
||||
if (self)
|
||||
{
|
||||
self.completionBlock = block;
|
||||
host = aHost;
|
||||
updateItem = item;
|
||||
[self setShouldCascadeWindows:NO];
|
||||
@@ -79,8 +81,8 @@
|
||||
[self.releaseNotesView setPolicyDelegate:nil];
|
||||
[self.releaseNotesView removeFromSuperview]; // Otherwise it gets sent Esc presses (why?!) and gets very confused.
|
||||
[self close];
|
||||
if ([self.delegate respondsToSelector:@selector(updateAlert:finishedWithChoice:)])
|
||||
[self.delegate updateAlert:self finishedWithChoice:choice];
|
||||
self.completionBlock(choice);
|
||||
self.completionBlock = nil;
|
||||
}
|
||||
|
||||
- (IBAction)installUpdate:(id)__unused sender
|
||||
@@ -164,10 +166,6 @@
|
||||
if ([self.host objectForInfoDictionaryKey:SUAllowsAutomaticUpdatesKey])
|
||||
allowAutoUpdates = [self.host boolForInfoDictionaryKey:SUAllowsAutomaticUpdatesKey];
|
||||
|
||||
// Give delegate a chance to modify this choice:
|
||||
if (self.delegate && [self.delegate respondsToSelector:@selector(updateAlert:shouldAllowAutoUpdate:)])
|
||||
[self.delegate updateAlert:self shouldAllowAutoUpdate:&allowAutoUpdates];
|
||||
|
||||
return allowAutoUpdates;
|
||||
}
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@
|
||||
|
||||
- (instancetype)initWithHost:(SUHost *)aHost systemProfile:(NSArray *)profile delegate:(id<SUUpdatePermissionPromptDelegate>)d
|
||||
{
|
||||
self = [super initWithHost:aHost windowNibName:@"SUUpdatePermissionPrompt"];
|
||||
self = [super initWithWindowNibName:@"SUUpdatePermissionPrompt"];
|
||||
if (self)
|
||||
{
|
||||
host = aHost;
|
||||
|
||||
@@ -46,6 +46,8 @@ SU_EXPORT @interface SUUpdater : NSObject
|
||||
|
||||
@property (nonatomic, copy) NSString *userAgentString;
|
||||
|
||||
@property (copy) NSDictionary *httpHeaders;
|
||||
|
||||
@property BOOL sendsSystemProfile;
|
||||
|
||||
@property BOOL automaticallyDownloadsUpdates;
|
||||
|
||||
@@ -51,7 +51,7 @@ NSString *const SUUpdaterAppcastNotificationKey = @"SUUpdaterAppCastNotification
|
||||
@synthesize delegate;
|
||||
@synthesize checkTimer;
|
||||
@synthesize userAgentString = customUserAgentString;
|
||||
|
||||
@synthesize httpHeaders;
|
||||
@synthesize driver;
|
||||
@synthesize host;
|
||||
|
||||
@@ -145,38 +145,28 @@ static NSString *const SUUpdaterDefaultsObservationContext = @"SUUpdaterDefaults
|
||||
- (void)startUpdateCycle
|
||||
{
|
||||
BOOL shouldPrompt = NO;
|
||||
BOOL hasLaunchedBefore = [self.host boolForUserDefaultsKey:SUHasLaunchedBeforeKey];
|
||||
|
||||
// If the user has been asked about automatic checks, don't bother prompting
|
||||
if ([self.host objectForUserDefaultsKey:SUEnableAutomaticChecksKey])
|
||||
{
|
||||
if ([self.host objectForUserDefaultsKey:SUEnableAutomaticChecksKey]) {
|
||||
shouldPrompt = NO;
|
||||
}
|
||||
// Does the delegate want to take care of the logic for when we should ask permission to update?
|
||||
else if ([self.delegate respondsToSelector:@selector(updaterShouldPromptForPermissionToCheckForUpdates:)])
|
||||
{
|
||||
else if ([self.delegate respondsToSelector:@selector(updaterShouldPromptForPermissionToCheckForUpdates:)]) {
|
||||
shouldPrompt = [self.delegate updaterShouldPromptForPermissionToCheckForUpdates:self];
|
||||
}
|
||||
// Has he been asked already? And don't ask if the host has a default value set in its Info.plist.
|
||||
else if ([self.host objectForKey:SUEnableAutomaticChecksKey] == nil)
|
||||
{
|
||||
if ([self.host objectForUserDefaultsKey:SUEnableAutomaticChecksKeyOld]) {
|
||||
[self setAutomaticallyChecksForUpdates:[self.host boolForUserDefaultsKey:SUEnableAutomaticChecksKeyOld]];
|
||||
}
|
||||
else if ([self.host objectForKey:SUEnableAutomaticChecksKey] == nil) {
|
||||
// Now, we don't want to ask the user for permission to do a weird thing on the first launch.
|
||||
// We wait until the second launch, unless explicitly overridden via SUPromptUserOnFirstLaunchKey.
|
||||
else if (![self.host objectForKey:SUPromptUserOnFirstLaunchKey])
|
||||
{
|
||||
if ([self.host boolForUserDefaultsKey:SUHasLaunchedBeforeKey] == NO)
|
||||
[self.host setBool:YES forUserDefaultsKey:SUHasLaunchedBeforeKey];
|
||||
else
|
||||
shouldPrompt = YES;
|
||||
}
|
||||
else
|
||||
shouldPrompt = YES;
|
||||
shouldPrompt = [self.host objectForKey:SUPromptUserOnFirstLaunchKey] || hasLaunchedBefore;
|
||||
}
|
||||
|
||||
if (shouldPrompt)
|
||||
{
|
||||
if (!hasLaunchedBefore) {
|
||||
[self.host setBool:YES forUserDefaultsKey:SUHasLaunchedBeforeKey];
|
||||
}
|
||||
|
||||
if (shouldPrompt) {
|
||||
NSArray *profileInfo = [self.host systemProfile];
|
||||
// Always say we're sending the system profile here so that the delegate displays the parameters it would send.
|
||||
if ([self.delegate respondsToSelector:@selector(feedParametersForUpdater:sendingSystemProfile:)]) {
|
||||
@@ -184,9 +174,7 @@ static NSString *const SUUpdaterDefaultsObservationContext = @"SUUpdaterDefaults
|
||||
}
|
||||
[SUUpdatePermissionPrompt promptWithHost:self.host systemProfile:profileInfo delegate:self];
|
||||
// We start the update checks and register as observer for changes after the prompt finishes
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
// We check if the user's said they want updates, or they haven't said anything, and the default is set to checking.
|
||||
[self scheduleNextUpdateCheck];
|
||||
}
|
||||
|
||||
@@ -78,16 +78,6 @@
|
||||
[super abortUpdate];
|
||||
}
|
||||
|
||||
- (void)appcast:(SUAppcast *)ac failedToLoadWithError:(NSError *)error
|
||||
{
|
||||
if (self.isCanceled)
|
||||
{
|
||||
[self abortUpdate];
|
||||
return;
|
||||
}
|
||||
[super appcast:ac failedToLoadWithError:error];
|
||||
}
|
||||
|
||||
- (BOOL)itemContainsValidUpdate:(SUAppcastItem *)ui
|
||||
{
|
||||
// We don't check to see if this update's been skipped, because the user explicitly *asked* if he had the latest version.
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
@class SUHost;
|
||||
@interface SUWindowController : NSWindowController
|
||||
// We use this instead of plain old NSWindowController initWithWindowNibName so that we'll be able to find the right path when running in a bundle loaded from another app.
|
||||
- (instancetype)initWithHost:(SUHost *)host windowNibName:(NSString *)nibName;
|
||||
- (instancetype)initWithWindowNibName:(NSString *)nibName;
|
||||
@end
|
||||
|
||||
#endif
|
||||
@@ -11,16 +11,9 @@
|
||||
|
||||
@implementation SUWindowController
|
||||
|
||||
- (instancetype)initWithHost:(SUHost *)host windowNibName:(NSString *)nibName
|
||||
- (instancetype)initWithWindowNibName:(NSString *)nibName
|
||||
{
|
||||
NSString *path = [[NSBundle bundleForClass:[self class]] pathForResource:nibName ofType:@"nib"];
|
||||
if (path == nil) // Slight hack to resolve issues with running Sparkle in debug configurations.
|
||||
{
|
||||
NSString *frameworkPath = [[[host bundle] sharedFrameworksPath] stringByAppendingPathComponent:@"Sparkle.framework"];
|
||||
NSBundle *framework = [NSBundle bundleWithPath:frameworkPath];
|
||||
path = [framework pathForResource:nibName ofType:@"nib"];
|
||||
}
|
||||
self = [super initWithWindowNibPath:path owner:self];
|
||||
self = [super initWithWindowNibName:nibName owner:self];
|
||||
return self;
|
||||
}
|
||||
|
||||
|
||||
@@ -96,7 +96,7 @@ Gw
|
||||
<button id="17">
|
||||
<rect key="frame" x="105" y="58" width="619" height="18"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
<buttonCell key="cell" type="check" title="Automatiquement télécharger et installer les mises à jour à l’avenir" bezelStyle="regularSquare" imagePosition="left" alignment="left" controlSize="small" inset="2" id="43">
|
||||
<buttonCell key="cell" type="check" title="Télécharger et installer automatiquement les mises à jour" bezelStyle="regularSquare" imagePosition="left" alignment="left" controlSize="small" inset="2" id="43">
|
||||
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
|
||||
<font key="font" metaFont="smallSystem"/>
|
||||
</buttonCell>
|
||||
|
||||
@@ -173,7 +173,7 @@ DQ
|
||||
</textField>
|
||||
<button translatesAutoresizingMaskIntoConstraints="NO" id="117">
|
||||
<rect key="frame" x="106" y="49" width="495" height="18"/>
|
||||
<buttonCell key="cell" type="check" title="Automatiquement télécharger et installer les mises à jour à l’avenir" bezelStyle="regularSquare" imagePosition="left" alignment="left" controlSize="small" inset="2" id="175">
|
||||
<buttonCell key="cell" type="check" title="Télécharger et installer automatiquement les mises à jour" bezelStyle="regularSquare" imagePosition="left" alignment="left" controlSize="small" inset="2" id="175">
|
||||
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
|
||||
<font key="font" metaFont="smallSystem"/>
|
||||
</buttonCell>
|
||||
|
||||
@@ -0,0 +1,283 @@
|
||||
// !$*UTF8*$!
|
||||
{
|
||||
archiveVersion = 1;
|
||||
classes = {
|
||||
};
|
||||
objectVersion = 46;
|
||||
objects = {
|
||||
|
||||
/* Begin PBXBuildFile section */
|
||||
5A195FB01983E85D000BE570 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 5A195FAF1983E85D000BE570 /* main.m */; };
|
||||
5A195FB31983E85D000BE570 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 5A195FB21983E85D000BE570 /* AppDelegate.m */; };
|
||||
5A195FB51983E85D000BE570 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 5A195FB41983E85D000BE570 /* Images.xcassets */; };
|
||||
5A195FB81983E85D000BE570 /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = 5A195FB61983E85D000BE570 /* MainMenu.xib */; };
|
||||
/* End PBXBuildFile section */
|
||||
|
||||
/* Begin PBXFileReference section */
|
||||
5A195FAA1983E85D000BE570 /* Sparkle Updated Test App.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "Sparkle Updated Test App.app"; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
5A195FAE1983E85D000BE570 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
|
||||
5A195FAF1983E85D000BE570 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
|
||||
5A195FB11983E85D000BE570 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = "<group>"; };
|
||||
5A195FB21983E85D000BE570 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = "<group>"; };
|
||||
5A195FB41983E85D000BE570 /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = "<group>"; };
|
||||
5A195FB71983E85D000BE570 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/MainMenu.xib; sourceTree = "<group>"; };
|
||||
/* End PBXFileReference section */
|
||||
|
||||
/* Begin PBXFrameworksBuildPhase section */
|
||||
5A195FA71983E85D000BE570 /* Frameworks */ = {
|
||||
isa = PBXFrameworksBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
/* End PBXFrameworksBuildPhase section */
|
||||
|
||||
/* Begin PBXGroup section */
|
||||
5A195FA11983E85D000BE570 = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
5A195FAC1983E85D000BE570 /* Sparkle Updated Test App */,
|
||||
5A195FAB1983E85D000BE570 /* Products */,
|
||||
);
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
5A195FAB1983E85D000BE570 /* Products */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
5A195FAA1983E85D000BE570 /* Sparkle Updated Test App.app */,
|
||||
);
|
||||
name = Products;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
5A195FAC1983E85D000BE570 /* Sparkle Updated Test App */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
5A195FB11983E85D000BE570 /* AppDelegate.h */,
|
||||
5A195FB21983E85D000BE570 /* AppDelegate.m */,
|
||||
5A195FB61983E85D000BE570 /* MainMenu.xib */,
|
||||
5A195FAD1983E85D000BE570 /* Supporting Files */,
|
||||
);
|
||||
path = "Sparkle Updated Test App";
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
5A195FAD1983E85D000BE570 /* Supporting Files */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
5A195FB41983E85D000BE570 /* Images.xcassets */,
|
||||
5A195FAE1983E85D000BE570 /* Info.plist */,
|
||||
5A195FAF1983E85D000BE570 /* main.m */,
|
||||
);
|
||||
name = "Supporting Files";
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
/* End PBXGroup section */
|
||||
|
||||
/* Begin PBXNativeTarget section */
|
||||
5A195FA91983E85D000BE570 /* Sparkle Updated Test App */ = {
|
||||
isa = PBXNativeTarget;
|
||||
buildConfigurationList = 5A195FC71983E85D000BE570 /* Build configuration list for PBXNativeTarget "Sparkle Updated Test App" */;
|
||||
buildPhases = (
|
||||
5A195FA61983E85D000BE570 /* Sources */,
|
||||
5A195FA71983E85D000BE570 /* Frameworks */,
|
||||
5A195FA81983E85D000BE570 /* Resources */,
|
||||
);
|
||||
buildRules = (
|
||||
);
|
||||
dependencies = (
|
||||
);
|
||||
name = "Sparkle Updated Test App";
|
||||
productName = "Sparkle Updated Test App";
|
||||
productReference = 5A195FAA1983E85D000BE570 /* Sparkle Updated Test App.app */;
|
||||
productType = "com.apple.product-type.application";
|
||||
};
|
||||
/* End PBXNativeTarget section */
|
||||
|
||||
/* Begin PBXProject section */
|
||||
5A195FA21983E85D000BE570 /* Project object */ = {
|
||||
isa = PBXProject;
|
||||
attributes = {
|
||||
LastUpgradeCheck = 0600;
|
||||
ORGANIZATIONNAME = "Sparkle-project";
|
||||
TargetAttributes = {
|
||||
5A195FA91983E85D000BE570 = {
|
||||
CreatedOnToolsVersion = 6.0;
|
||||
};
|
||||
};
|
||||
};
|
||||
buildConfigurationList = 5A195FA51983E85D000BE570 /* Build configuration list for PBXProject "Sparkle Updated Test App" */;
|
||||
compatibilityVersion = "Xcode 3.2";
|
||||
developmentRegion = English;
|
||||
hasScannedForEncodings = 0;
|
||||
knownRegions = (
|
||||
en,
|
||||
Base,
|
||||
);
|
||||
mainGroup = 5A195FA11983E85D000BE570;
|
||||
productRefGroup = 5A195FAB1983E85D000BE570 /* Products */;
|
||||
projectDirPath = "";
|
||||
projectRoot = "";
|
||||
targets = (
|
||||
5A195FA91983E85D000BE570 /* Sparkle Updated Test App */,
|
||||
);
|
||||
};
|
||||
/* End PBXProject section */
|
||||
|
||||
/* Begin PBXResourcesBuildPhase section */
|
||||
5A195FA81983E85D000BE570 /* Resources */ = {
|
||||
isa = PBXResourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
5A195FB51983E85D000BE570 /* Images.xcassets in Resources */,
|
||||
5A195FB81983E85D000BE570 /* MainMenu.xib in Resources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
/* End PBXResourcesBuildPhase section */
|
||||
|
||||
/* Begin PBXSourcesBuildPhase section */
|
||||
5A195FA61983E85D000BE570 /* Sources */ = {
|
||||
isa = PBXSourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
5A195FB31983E85D000BE570 /* AppDelegate.m in Sources */,
|
||||
5A195FB01983E85D000BE570 /* main.m in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
/* End PBXSourcesBuildPhase section */
|
||||
|
||||
/* Begin PBXVariantGroup section */
|
||||
5A195FB61983E85D000BE570 /* MainMenu.xib */ = {
|
||||
isa = PBXVariantGroup;
|
||||
children = (
|
||||
5A195FB71983E85D000BE570 /* Base */,
|
||||
);
|
||||
name = MainMenu.xib;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
/* End PBXVariantGroup section */
|
||||
|
||||
/* Begin XCBuildConfiguration section */
|
||||
5A195FC51983E85D000BE570 /* Debug */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
ALWAYS_SEARCH_USER_PATHS = NO;
|
||||
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
|
||||
CLANG_CXX_LIBRARY = "libc++";
|
||||
CLANG_ENABLE_MODULES = YES;
|
||||
CLANG_ENABLE_OBJC_ARC = YES;
|
||||
CLANG_WARN_BOOL_CONVERSION = YES;
|
||||
CLANG_WARN_CONSTANT_CONVERSION = YES;
|
||||
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
|
||||
CLANG_WARN_EMPTY_BODY = YES;
|
||||
CLANG_WARN_ENUM_CONVERSION = YES;
|
||||
CLANG_WARN_INT_CONVERSION = YES;
|
||||
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
|
||||
CLANG_WARN_UNREACHABLE_CODE = YES;
|
||||
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
|
||||
CODE_SIGN_IDENTITY = "-";
|
||||
COPY_PHASE_STRIP = NO;
|
||||
ENABLE_STRICT_OBJC_MSGSEND = YES;
|
||||
GCC_C_LANGUAGE_STANDARD = gnu99;
|
||||
GCC_DYNAMIC_NO_PIC = NO;
|
||||
GCC_OPTIMIZATION_LEVEL = 0;
|
||||
GCC_PREPROCESSOR_DEFINITIONS = (
|
||||
"DEBUG=1",
|
||||
"$(inherited)",
|
||||
);
|
||||
GCC_SYMBOLS_PRIVATE_EXTERN = NO;
|
||||
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
|
||||
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
|
||||
GCC_WARN_UNDECLARED_SELECTOR = YES;
|
||||
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
|
||||
GCC_WARN_UNUSED_FUNCTION = YES;
|
||||
GCC_WARN_UNUSED_VARIABLE = YES;
|
||||
MACOSX_DEPLOYMENT_TARGET = 10.7;
|
||||
MTL_ENABLE_DEBUG_INFO = YES;
|
||||
ONLY_ACTIVE_ARCH = YES;
|
||||
SDKROOT = macosx;
|
||||
};
|
||||
name = Debug;
|
||||
};
|
||||
5A195FC61983E85D000BE570 /* Release */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
ALWAYS_SEARCH_USER_PATHS = NO;
|
||||
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
|
||||
CLANG_CXX_LIBRARY = "libc++";
|
||||
CLANG_ENABLE_MODULES = YES;
|
||||
CLANG_ENABLE_OBJC_ARC = YES;
|
||||
CLANG_WARN_BOOL_CONVERSION = YES;
|
||||
CLANG_WARN_CONSTANT_CONVERSION = YES;
|
||||
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
|
||||
CLANG_WARN_EMPTY_BODY = YES;
|
||||
CLANG_WARN_ENUM_CONVERSION = YES;
|
||||
CLANG_WARN_INT_CONVERSION = YES;
|
||||
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
|
||||
CLANG_WARN_UNREACHABLE_CODE = YES;
|
||||
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
|
||||
CODE_SIGN_IDENTITY = "-";
|
||||
COPY_PHASE_STRIP = YES;
|
||||
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
|
||||
ENABLE_NS_ASSERTIONS = NO;
|
||||
ENABLE_STRICT_OBJC_MSGSEND = YES;
|
||||
GCC_C_LANGUAGE_STANDARD = gnu99;
|
||||
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
|
||||
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
|
||||
GCC_WARN_UNDECLARED_SELECTOR = YES;
|
||||
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
|
||||
GCC_WARN_UNUSED_FUNCTION = YES;
|
||||
GCC_WARN_UNUSED_VARIABLE = YES;
|
||||
MACOSX_DEPLOYMENT_TARGET = 10.7;
|
||||
MTL_ENABLE_DEBUG_INFO = NO;
|
||||
SDKROOT = macosx;
|
||||
};
|
||||
name = Release;
|
||||
};
|
||||
5A195FC81983E85D000BE570 /* Debug */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
ASSETCATALOG_COMPILER_APPICON_NAME = Sparkle;
|
||||
COMBINE_HIDPI_IMAGES = YES;
|
||||
INFOPLIST_FILE = "Sparkle Updated Test App/Info.plist";
|
||||
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks";
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
};
|
||||
name = Debug;
|
||||
};
|
||||
5A195FC91983E85D000BE570 /* Release */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
ASSETCATALOG_COMPILER_APPICON_NAME = Sparkle;
|
||||
COMBINE_HIDPI_IMAGES = YES;
|
||||
INFOPLIST_FILE = "Sparkle Updated Test App/Info.plist";
|
||||
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks";
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
};
|
||||
name = Release;
|
||||
};
|
||||
/* End XCBuildConfiguration section */
|
||||
|
||||
/* Begin XCConfigurationList section */
|
||||
5A195FA51983E85D000BE570 /* Build configuration list for PBXProject "Sparkle Updated Test App" */ = {
|
||||
isa = XCConfigurationList;
|
||||
buildConfigurations = (
|
||||
5A195FC51983E85D000BE570 /* Debug */,
|
||||
5A195FC61983E85D000BE570 /* Release */,
|
||||
);
|
||||
defaultConfigurationIsVisible = 0;
|
||||
defaultConfigurationName = Release;
|
||||
};
|
||||
5A195FC71983E85D000BE570 /* Build configuration list for PBXNativeTarget "Sparkle Updated Test App" */ = {
|
||||
isa = XCConfigurationList;
|
||||
buildConfigurations = (
|
||||
5A195FC81983E85D000BE570 /* Debug */,
|
||||
5A195FC91983E85D000BE570 /* Release */,
|
||||
);
|
||||
defaultConfigurationIsVisible = 0;
|
||||
};
|
||||
/* End XCConfigurationList section */
|
||||
};
|
||||
rootObject = 5A195FA21983E85D000BE570 /* Project object */;
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
//
|
||||
// AppDelegate.h
|
||||
// Sparkle Updated Test App
|
||||
//
|
||||
// Created by Kornel on 26/07/2014.
|
||||
// Copyright (c) 2014 Sparkle-project. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
@interface AppDelegate : NSObject <NSApplicationDelegate>
|
||||
|
||||
|
||||
@end
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
//
|
||||
// AppDelegate.m
|
||||
// Sparkle Updated Test App
|
||||
//
|
||||
// Created by Kornel on 26/07/2014.
|
||||
// Copyright (c) 2014 Sparkle-project. All rights reserved.
|
||||
//
|
||||
|
||||
#import "AppDelegate.h"
|
||||
|
||||
@interface AppDelegate ()
|
||||
@end
|
||||
|
||||
@implementation AppDelegate
|
||||
|
||||
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
|
||||
NSRunAlertPanel(@"Update succeeded!", @"This is the updated version of Sparkle Test App.\n\nDelete and rebuild the app to test updates again.", @"OK", nil, nil);
|
||||
|
||||
NSURL *bundleURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] bundlePath]];
|
||||
if (bundleURL) {
|
||||
[[NSWorkspace sharedWorkspace] activateFileViewerSelectingURLs: @[bundleURL]];
|
||||
}
|
||||
|
||||
[NSApp terminate:self];
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,52 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="6185.7" systemVersion="14A298i" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
|
||||
<dependencies>
|
||||
<deployment defaultVersion="1070" identifier="macosx"/>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="6185.7"/>
|
||||
</dependencies>
|
||||
<objects>
|
||||
<customObject id="-2" userLabel="File's Owner" customClass="NSApplication">
|
||||
<connections>
|
||||
<outlet property="delegate" destination="Voe-Tx-rLC" id="GzC-gU-4Uq"/>
|
||||
</connections>
|
||||
</customObject>
|
||||
<customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
|
||||
<customObject id="-3" userLabel="Application"/>
|
||||
<customObject id="Voe-Tx-rLC" customClass="AppDelegate"/>
|
||||
<customObject id="YLy-65-1bz" customClass="NSFontManager"/>
|
||||
<menu title="Main Menu" systemMenu="main" id="AYu-sK-qS6">
|
||||
<items>
|
||||
<menuItem title="Sparkle Updated Test App" id="1Xt-HY-uBw">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<menu key="submenu" title="Sparkle Updated Test App" systemMenu="apple" id="uQy-DD-JDr">
|
||||
<items>
|
||||
<menuItem title="Hide Sparkle Updated Test App" keyEquivalent="h" id="Olw-nP-bQN">
|
||||
<connections>
|
||||
<action selector="hide:" target="-1" id="PnN-Uc-m68"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Hide Others" keyEquivalent="h" id="Vdr-fp-XzO">
|
||||
<modifierMask key="keyEquivalentModifierMask" option="YES" command="YES"/>
|
||||
<connections>
|
||||
<action selector="hideOtherApplications:" target="-1" id="VT4-aY-XCT"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Show All" id="Kd2-mp-pUS">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="unhideAllApplications:" target="-1" id="Dhg-Le-xox"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem isSeparatorItem="YES" id="kCx-OE-vgT"/>
|
||||
<menuItem title="Quit Sparkle Updated Test App" keyEquivalent="q" id="4sb-4s-VLi">
|
||||
<connections>
|
||||
<action selector="terminate:" target="-1" id="Te7-pn-YzF"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
</items>
|
||||
</menu>
|
||||
</menuItem>
|
||||
</items>
|
||||
</menu>
|
||||
</objects>
|
||||
</document>
|
||||
@@ -0,0 +1,64 @@
|
||||
{
|
||||
"images" : [
|
||||
{
|
||||
"size" : "16x16",
|
||||
"idiom" : "mac",
|
||||
"filename" : "icon_16x16.png",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"size" : "16x16",
|
||||
"idiom" : "mac",
|
||||
"filename" : "icon_16x16@2x.png",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"size" : "32x32",
|
||||
"idiom" : "mac",
|
||||
"filename" : "icon_32x32.png",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"size" : "32x32",
|
||||
"idiom" : "mac",
|
||||
"filename" : "icon_32x32@2x.png",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"size" : "128x128",
|
||||
"idiom" : "mac",
|
||||
"filename" : "icon_128x128.png",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"size" : "128x128",
|
||||
"idiom" : "mac",
|
||||
"filename" : "icon_128x128@2x.png",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"idiom" : "mac",
|
||||
"size" : "256x256",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"idiom" : "mac",
|
||||
"size" : "256x256",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"idiom" : "mac",
|
||||
"size" : "512x512",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"idiom" : "mac",
|
||||
"size" : "512x512",
|
||||
"scale" : "2x"
|
||||
}
|
||||
],
|
||||
"info" : {
|
||||
"version" : 1,
|
||||
"author" : "xcode"
|
||||
}
|
||||
}
|
||||
|
After Width: | Height: | Size: 15 KiB |
|
After Width: | Height: | Size: 37 KiB |
|
After Width: | Height: | Size: 754 B |
|
After Width: | Height: | Size: 2.1 KiB |
|
After Width: | Height: | Size: 2.1 KiB |
|
After Width: | Height: | Size: 5.9 KiB |
@@ -0,0 +1,36 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>CFBundleDevelopmentRegion</key>
|
||||
<string>en</string>
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>${EXECUTABLE_NAME}</string>
|
||||
<key>CFBundleIconFile</key>
|
||||
<string></string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>org.sparkle-project.${PRODUCT_NAME:rfc1034identifier}</string>
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
<string>6.0</string>
|
||||
<key>CFBundleName</key>
|
||||
<string>${PRODUCT_NAME}</string>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>APPL</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>2.0</string>
|
||||
<key>CFBundleSignature</key>
|
||||
<string>????</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>2</string>
|
||||
<key>LSApplicationCategoryType</key>
|
||||
<string>public.app-category.developer-tools</string>
|
||||
<key>LSMinimumSystemVersion</key>
|
||||
<string>${MACOSX_DEPLOYMENT_TARGET}</string>
|
||||
<key>NSHumanReadableCopyright</key>
|
||||
<string>Copyright © 2014 Sparkle-project. All rights reserved.</string>
|
||||
<key>NSMainNibFile</key>
|
||||
<string>MainMenu</string>
|
||||
<key>NSPrincipalClass</key>
|
||||
<string>NSApplication</string>
|
||||
</dict>
|
||||
</plist>
|
||||
@@ -0,0 +1,6 @@
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
int main(int argc, const char * argv[]) {
|
||||
return NSApplicationMain(argc, argv);
|
||||
}
|
||||
@@ -9,20 +9,925 @@
|
||||
#import <Cocoa/Cocoa.h>
|
||||
#import <XCTest/XCTest.h>
|
||||
#import "SUBinaryDeltaCommon.h"
|
||||
#import "SUBinaryDeltaCreate.h"
|
||||
#import "SUBinaryDeltaApply.h"
|
||||
#import <sys/stat.h>
|
||||
|
||||
@interface SUBinaryDeltaTest : XCTestCase
|
||||
|
||||
@end
|
||||
|
||||
typedef void (^SUDeltaHandler)(NSFileManager *fileManager, NSString *sourceDirectory, NSString *destinationDirectory);
|
||||
|
||||
@implementation SUBinaryDeltaTest
|
||||
|
||||
- (void)testTemporaryFilename
|
||||
- (void)testTemporaryDirectory
|
||||
{
|
||||
NSString *tmp1 = temporaryFilename(@"Sparkle");
|
||||
NSString *tmp2 = temporaryFilename(@"Sparkle");
|
||||
NSLog(@"Temporary filenames: %@, %@", tmp1, tmp2);
|
||||
NSString *tmp1 = temporaryDirectory(@"Sparkle");
|
||||
NSString *tmp2 = temporaryDirectory(@"Sparkle");
|
||||
NSLog(@"Temporary directories: %@, %@", tmp1, tmp2);
|
||||
XCTAssertNotEqualObjects(tmp1, tmp2);
|
||||
XCTAssert(YES, @"Pass");
|
||||
}
|
||||
|
||||
- (void)testTemporaryFile
|
||||
{
|
||||
NSString *tmp1 = temporaryFilename(@"Sparkle");
|
||||
NSString *tmp2 = temporaryFilename(@"Sparkle");
|
||||
NSLog(@"Temporary files: %@, %@", tmp1, tmp2);
|
||||
XCTAssertNotEqualObjects(tmp1, tmp2);
|
||||
XCTAssert(YES, @"Pass");
|
||||
}
|
||||
|
||||
- (BOOL)createAndApplyPatchUsingVersion:(SUBinaryDeltaMajorVersion)majorVersion beforeDiffHandler:(SUDeltaHandler)beforeDiffHandler afterDiffHandler:(SUDeltaHandler)afterDiffHandler
|
||||
{
|
||||
NSString *sourceDirectory = temporaryDirectory(@"Sparkle_temp1");
|
||||
NSString *destinationDirectory = temporaryDirectory(@"Sparkle_temp2");
|
||||
|
||||
NSString *diffFile = temporaryFilename(@"Sparkle_diff");
|
||||
NSString *patchDirectory = temporaryDirectory(@"Sparkle_patch");
|
||||
|
||||
XCTAssertNotNil(sourceDirectory);
|
||||
XCTAssertNotNil(destinationDirectory);
|
||||
XCTAssertNotNil(diffFile);
|
||||
|
||||
NSFileManager *fileManager = [[NSFileManager alloc] init];
|
||||
|
||||
if (beforeDiffHandler != nil) {
|
||||
beforeDiffHandler(fileManager, sourceDirectory, destinationDirectory);
|
||||
}
|
||||
|
||||
BOOL createdDiff =
|
||||
(createBinaryDelta(sourceDirectory, destinationDirectory, diffFile, majorVersion, NO) == 0);
|
||||
|
||||
if (createdDiff && afterDiffHandler != nil) {
|
||||
afterDiffHandler(fileManager, sourceDirectory, destinationDirectory);
|
||||
}
|
||||
|
||||
BOOL appliedDiff = (createdDiff && applyBinaryDelta(sourceDirectory, patchDirectory, diffFile, NO) == 0);
|
||||
|
||||
XCTAssertTrue([fileManager removeItemAtPath:sourceDirectory error:nil]);
|
||||
XCTAssertTrue([fileManager removeItemAtPath:destinationDirectory error:nil]);
|
||||
XCTAssertTrue([fileManager removeItemAtPath:patchDirectory error:nil]);
|
||||
XCTAssertTrue([fileManager removeItemAtPath:diffFile error:nil]);
|
||||
|
||||
return appliedDiff;
|
||||
}
|
||||
|
||||
- (BOOL)createAndApplyPatchWithBeforeDiffHandler:(SUDeltaHandler)beforeDiffHandler afterDiffHandler:(SUDeltaHandler)afterDiffHandler
|
||||
{
|
||||
return [self createAndApplyPatchUsingVersion:LATEST_DELTA_DIFF_MAJOR_VERSION beforeDiffHandler:beforeDiffHandler afterDiffHandler:afterDiffHandler];
|
||||
}
|
||||
|
||||
- (void)createAndApplyPatchWithHandler:(SUDeltaHandler)handler
|
||||
{
|
||||
BOOL success = [self createAndApplyPatchWithBeforeDiffHandler:handler afterDiffHandler:nil];
|
||||
XCTAssertTrue(success);
|
||||
}
|
||||
|
||||
- (BOOL)testDirectoryHashEqualityWithSource:(NSString *)source destination:(NSString *)destination
|
||||
{
|
||||
XCTAssertNotNil(source);
|
||||
XCTAssertNotNil(destination);
|
||||
|
||||
NSString *beforeHash = hashOfTree(source);
|
||||
NSString *afterHash = hashOfTree(destination);
|
||||
|
||||
XCTAssertNotNil(beforeHash);
|
||||
XCTAssertNotNil(afterHash);
|
||||
|
||||
return [beforeHash isEqualToString:afterHash];
|
||||
}
|
||||
|
||||
- (void)testNoFilesDiff
|
||||
{
|
||||
[self createAndApplyPatchWithHandler:^(NSFileManager *__unused fileManager, NSString *sourceDirectory, NSString *destinationDirectory) {
|
||||
XCTAssertTrue([self testDirectoryHashEqualityWithSource:sourceDirectory destination:destinationDirectory]);
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)testNoFilesDiffWithInvalidLowVersion
|
||||
{
|
||||
XCTAssertFalse([self createAndApplyPatchUsingVersion:(SUBinaryDeltaMajorVersion)0 beforeDiffHandler:^(NSFileManager *__unused fileManager, NSString *sourceDirectory, NSString *destinationDirectory) {
|
||||
XCTAssertTrue([self testDirectoryHashEqualityWithSource:sourceDirectory destination:destinationDirectory]);
|
||||
} afterDiffHandler:nil]);
|
||||
}
|
||||
|
||||
- (void)testNoFilesDiffWithInvalidHighVersion
|
||||
{
|
||||
XCTAssertFalse([self createAndApplyPatchUsingVersion:(SUBinaryDeltaMajorVersion)9999 beforeDiffHandler:^(NSFileManager *__unused fileManager, NSString *sourceDirectory, NSString *destinationDirectory) {
|
||||
XCTAssertTrue([self testDirectoryHashEqualityWithSource:sourceDirectory destination:destinationDirectory]);
|
||||
} afterDiffHandler:nil]);
|
||||
}
|
||||
|
||||
- (void)testEmptyDataDiff
|
||||
{
|
||||
[self createAndApplyPatchWithHandler:^(NSFileManager *__unused fileManager, NSString *sourceDirectory, NSString *destinationDirectory) {
|
||||
NSData *emptyData = [NSData data];
|
||||
NSString *sourceFile = [sourceDirectory stringByAppendingPathComponent:@"A"];
|
||||
NSString *destinationFile = [destinationDirectory stringByAppendingPathComponent:@"A"];
|
||||
|
||||
XCTAssertTrue([emptyData writeToFile:sourceFile atomically:YES]);
|
||||
XCTAssertTrue([emptyData writeToFile:destinationFile atomically:YES]);
|
||||
|
||||
XCTAssertTrue([self testDirectoryHashEqualityWithSource:sourceDirectory destination:destinationDirectory]);
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)testDifferentlyNamedEmptyDataDiff
|
||||
{
|
||||
[self createAndApplyPatchWithHandler:^(NSFileManager *__unused fileManager, NSString *sourceDirectory, NSString *destinationDirectory) {
|
||||
NSData *emptyData = [NSData data];
|
||||
NSString *sourceFile = [sourceDirectory stringByAppendingPathComponent:@"A"];
|
||||
NSString *destinationFile = [destinationDirectory stringByAppendingPathComponent:@"B"];
|
||||
|
||||
XCTAssertTrue([emptyData writeToFile:sourceFile atomically:YES]);
|
||||
XCTAssertTrue([emptyData writeToFile:destinationFile atomically:YES]);
|
||||
|
||||
XCTAssertFalse([self testDirectoryHashEqualityWithSource:sourceDirectory destination:destinationDirectory]);
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)testEmptyDirectoryDiff
|
||||
{
|
||||
[self createAndApplyPatchWithHandler:^(NSFileManager *fileManager, NSString *sourceDirectory, NSString *destinationDirectory) {
|
||||
NSString *sourceFile = [sourceDirectory stringByAppendingPathComponent:@"A"];
|
||||
NSString *destinationFile = [destinationDirectory stringByAppendingPathComponent:@"A"];
|
||||
|
||||
NSError *error = nil;
|
||||
if (![fileManager createDirectoryAtPath:sourceFile withIntermediateDirectories:NO attributes:nil error:&error]) {
|
||||
NSLog(@"Failed creating directory with error: %@", error);
|
||||
XCTFail("Failed to create directory");
|
||||
}
|
||||
|
||||
if (![fileManager createDirectoryAtPath:destinationFile withIntermediateDirectories:NO attributes:nil error:&error]) {
|
||||
NSLog(@"Failed creating directory with error: %@", error);
|
||||
XCTFail("Failed to create directory");
|
||||
}
|
||||
|
||||
XCTAssertTrue([self testDirectoryHashEqualityWithSource:sourceDirectory destination:destinationDirectory]);
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)testDifferentlyNamedEmptyDirectoryDiff
|
||||
{
|
||||
[self createAndApplyPatchWithHandler:^(NSFileManager *fileManager, NSString *sourceDirectory, NSString *destinationDirectory) {
|
||||
NSString *sourceFile = [sourceDirectory stringByAppendingPathComponent:@"A"];
|
||||
NSString *destinationFile = [destinationDirectory stringByAppendingPathComponent:@"B"];
|
||||
|
||||
NSError *error = nil;
|
||||
if (![fileManager createDirectoryAtPath:sourceFile withIntermediateDirectories:NO attributes:nil error:&error]) {
|
||||
NSLog(@"Failed creating directory with error: %@", error);
|
||||
XCTFail("Failed to create directory");
|
||||
}
|
||||
|
||||
if (![fileManager createDirectoryAtPath:destinationFile withIntermediateDirectories:NO attributes:nil error:&error]) {
|
||||
NSLog(@"Failed creating directory with error: %@", error);
|
||||
XCTFail("Failed to create directory");
|
||||
}
|
||||
|
||||
// This would fail for version 1.0
|
||||
XCTAssertFalse([self testDirectoryHashEqualityWithSource:sourceDirectory destination:destinationDirectory]);
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)testSameNonexistantSymlinkDiff
|
||||
{
|
||||
[self createAndApplyPatchWithHandler:^(NSFileManager *fileManager, NSString *sourceDirectory, NSString *destinationDirectory) {
|
||||
NSString *sourceFile = [sourceDirectory stringByAppendingPathComponent:@"A"];
|
||||
NSString *destinationFile = [destinationDirectory stringByAppendingPathComponent:@"A"];
|
||||
|
||||
NSError *error = nil;
|
||||
if (![fileManager createSymbolicLinkAtPath:sourceFile withDestinationPath:@"B" error:&error]) {
|
||||
NSLog(@"Failed creating empty symlink with error: %@", error);
|
||||
XCTFail("Failed to create empty symlink");
|
||||
}
|
||||
|
||||
if (![fileManager createSymbolicLinkAtPath:destinationFile withDestinationPath:@"B" error:&error]) {
|
||||
NSLog(@"Failed creating empty symlink with error: %@", error);
|
||||
XCTFail("Failed to create empty symlink");
|
||||
}
|
||||
|
||||
XCTAssertTrue([self testDirectoryHashEqualityWithSource:sourceDirectory destination:destinationDirectory]);
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)testDifferentNonexistantSymlinkDiff
|
||||
{
|
||||
[self createAndApplyPatchWithHandler:^(NSFileManager *fileManager, NSString *sourceDirectory, NSString *destinationDirectory) {
|
||||
NSString *sourceFile = [sourceDirectory stringByAppendingPathComponent:@"A"];
|
||||
NSString *destinationFile = [destinationDirectory stringByAppendingPathComponent:@"A"];
|
||||
|
||||
NSError *error = nil;
|
||||
if (![fileManager createSymbolicLinkAtPath:sourceFile withDestinationPath:@"B" error:&error]) {
|
||||
NSLog(@"Failed creating empty symlink with error: %@", error);
|
||||
XCTFail("Failed to create empty symlink");
|
||||
}
|
||||
|
||||
if (![fileManager createSymbolicLinkAtPath:destinationFile withDestinationPath:@"C" error:&error]) {
|
||||
NSLog(@"Failed creating empty symlink with error: %@", error);
|
||||
XCTFail("Failed to create empty symlink");
|
||||
}
|
||||
|
||||
XCTAssertFalse([self testDirectoryHashEqualityWithSource:sourceDirectory destination:destinationDirectory]);
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)testNonexistantSymlinkPermissionDiff
|
||||
{
|
||||
[self createAndApplyPatchWithHandler:^(NSFileManager *fileManager, NSString *sourceDirectory, NSString *destinationDirectory) {
|
||||
NSString *sourceFile = [sourceDirectory stringByAppendingPathComponent:@"A"];
|
||||
NSString *destinationFile = [destinationDirectory stringByAppendingPathComponent:@"A"];
|
||||
|
||||
NSError *error = nil;
|
||||
if (![fileManager createSymbolicLinkAtPath:sourceFile withDestinationPath:@"B" error:&error]) {
|
||||
NSLog(@"Failed creating empty symlink to source with error: %@", error);
|
||||
XCTFail("Failed to create empty symlink");
|
||||
}
|
||||
|
||||
if (![fileManager createSymbolicLinkAtPath:destinationFile withDestinationPath:@"B" error:&error]) {
|
||||
NSLog(@"Failed creating empty symlink to destination with error: %@", error);
|
||||
XCTFail("Failed to create empty symlink");
|
||||
}
|
||||
|
||||
if (lchmod([sourceFile fileSystemRepresentation], 0777) != 0) {
|
||||
NSLog(@"Change Permission Error..");
|
||||
XCTFail(@"Failed setting file permissions");
|
||||
}
|
||||
|
||||
XCTAssertFalse([self testDirectoryHashEqualityWithSource:sourceDirectory destination:destinationDirectory]);
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)testSmallDataDiff
|
||||
{
|
||||
[self createAndApplyPatchWithHandler:^(NSFileManager *__unused fileManager, NSString *sourceDirectory, NSString *destinationDirectory) {
|
||||
NSString *sourceFile = [sourceDirectory stringByAppendingPathComponent:@"A"];
|
||||
NSString *destinationFile = [destinationDirectory stringByAppendingPathComponent:@"A"];
|
||||
|
||||
XCTAssertTrue([[NSData data] writeToFile:sourceFile atomically:YES]);
|
||||
XCTAssertTrue([[NSData dataWithBytes:"loltest" length:7] writeToFile:destinationFile atomically:YES]);
|
||||
|
||||
XCTAssertFalse([self testDirectoryHashEqualityWithSource:sourceDirectory destination:destinationDirectory]);
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)testInvalidSource
|
||||
{
|
||||
BOOL success = [self createAndApplyPatchWithBeforeDiffHandler:^(NSFileManager *__unused fileManager, NSString *sourceDirectory, NSString *destinationDirectory) {
|
||||
NSString *sourceFile = [sourceDirectory stringByAppendingPathComponent:@"A"];
|
||||
NSString *destinationFile = [destinationDirectory stringByAppendingPathComponent:@"A"];
|
||||
|
||||
XCTAssertTrue([[NSData data] writeToFile:sourceFile atomically:YES]);
|
||||
XCTAssertTrue([[NSData dataWithBytes:"loltest" length:7] writeToFile:destinationFile atomically:YES]);
|
||||
|
||||
XCTAssertFalse([self testDirectoryHashEqualityWithSource:sourceDirectory destination:destinationDirectory]);
|
||||
} afterDiffHandler:^(NSFileManager *__unused fileManager, NSString *sourceDirectory, NSString *__unused destinationDirectory) {
|
||||
NSString *sourceFile = [sourceDirectory stringByAppendingPathComponent:@"A"];
|
||||
|
||||
XCTAssertTrue([[NSData dataWithBytes:"testt" length:5] writeToFile:sourceFile atomically:YES]);
|
||||
}];
|
||||
XCTAssertFalse(success);
|
||||
}
|
||||
|
||||
- (NSData *)bigData1
|
||||
{
|
||||
const size_t bufferSize = 4096*10;
|
||||
uint8_t *buffer = calloc(1, bufferSize);
|
||||
XCTAssertTrue(buffer != NULL);
|
||||
|
||||
return [NSData dataWithBytesNoCopy:buffer length:bufferSize];
|
||||
}
|
||||
|
||||
- (NSData *)bigData2
|
||||
{
|
||||
const size_t bufferSize = 4096*10;
|
||||
uint8_t *buffer = calloc(1, bufferSize);
|
||||
XCTAssertTrue(buffer != NULL);
|
||||
|
||||
for (size_t bufferIndex = 0; bufferIndex < bufferSize; ++bufferIndex) {
|
||||
buffer[bufferIndex] = 1;
|
||||
}
|
||||
|
||||
return [NSData dataWithBytesNoCopy:buffer length:bufferSize];
|
||||
}
|
||||
|
||||
- (void)testBigDataSameDiff
|
||||
{
|
||||
[self createAndApplyPatchWithHandler:^(NSFileManager *__unused fileManager, NSString *sourceDirectory, NSString *destinationDirectory) {
|
||||
NSString *sourceFile = [sourceDirectory stringByAppendingPathComponent:@"A"];
|
||||
NSString *destinationFile = [destinationDirectory stringByAppendingPathComponent:@"A"];
|
||||
|
||||
XCTAssertTrue([[self bigData1] writeToFile:sourceFile atomically:YES]);
|
||||
XCTAssertTrue([[self bigData1] writeToFile:destinationFile atomically:YES]);
|
||||
|
||||
XCTAssertTrue([self testDirectoryHashEqualityWithSource:sourceDirectory destination:destinationDirectory]);
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)testBigDataDifferentDiff
|
||||
{
|
||||
[self createAndApplyPatchWithHandler:^(NSFileManager *__unused fileManager, NSString *sourceDirectory, NSString *destinationDirectory) {
|
||||
NSString *sourceFile = [sourceDirectory stringByAppendingPathComponent:@"A"];
|
||||
NSString *destinationFile = [destinationDirectory stringByAppendingPathComponent:@"A"];
|
||||
|
||||
XCTAssertTrue([[self bigData1] writeToFile:sourceFile atomically:YES]);
|
||||
XCTAssertTrue([[self bigData2] writeToFile:destinationFile atomically:YES]);
|
||||
|
||||
XCTAssertFalse([self testDirectoryHashEqualityWithSource:sourceDirectory destination:destinationDirectory]);
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)testRegularFileAdded
|
||||
{
|
||||
[self createAndApplyPatchWithHandler:^(NSFileManager *__unused fileManager, NSString *sourceDirectory, NSString *destinationDirectory) {
|
||||
NSString *sourceFile = [sourceDirectory stringByAppendingPathComponent:@"A"];
|
||||
NSString *destinationFile = [destinationDirectory stringByAppendingPathComponent:@"A"];
|
||||
NSString *destinationFile2 = [destinationDirectory stringByAppendingPathComponent:@"B"];
|
||||
|
||||
XCTAssertTrue([[NSData data] writeToFile:sourceFile atomically:YES]);
|
||||
XCTAssertTrue([[NSData dataWithBytes:"loltest" length:7] writeToFile:destinationFile atomically:YES]);
|
||||
XCTAssertTrue([[NSData dataWithBytes:"lol" length:3] writeToFile:destinationFile2 atomically:YES]);
|
||||
|
||||
XCTAssertFalse([self testDirectoryHashEqualityWithSource:sourceDirectory destination:destinationDirectory]);
|
||||
}];
|
||||
}
|
||||
|
||||
// Make sure old version patches still work for simple cases
|
||||
- (void)testRegularFileAddedWithAzureVersion
|
||||
{
|
||||
XCTAssertTrue([self createAndApplyPatchUsingVersion:SUAzureMajorVersion beforeDiffHandler:^(NSFileManager *__unused fileManager, NSString *sourceDirectory, NSString *destinationDirectory) {
|
||||
NSString *sourceFile = [sourceDirectory stringByAppendingPathComponent:@"A"];
|
||||
NSString *destinationFile = [destinationDirectory stringByAppendingPathComponent:@"A"];
|
||||
NSString *destinationFile2 = [destinationDirectory stringByAppendingPathComponent:@"B"];
|
||||
|
||||
XCTAssertTrue([[NSData data] writeToFile:sourceFile atomically:YES]);
|
||||
XCTAssertTrue([[NSData dataWithBytes:"loltest" length:7] writeToFile:destinationFile atomically:YES]);
|
||||
XCTAssertTrue([[NSData dataWithBytes:"lol" length:3] writeToFile:destinationFile2 atomically:YES]);
|
||||
|
||||
XCTAssertFalse([self testDirectoryHashEqualityWithSource:sourceDirectory destination:destinationDirectory]);
|
||||
} afterDiffHandler:nil]);
|
||||
}
|
||||
|
||||
- (void)testDirectoryAdded
|
||||
{
|
||||
[self createAndApplyPatchWithHandler:^(NSFileManager *fileManager, NSString *sourceDirectory, NSString *destinationDirectory) {
|
||||
NSString *sourceFile = [sourceDirectory stringByAppendingPathComponent:@"A"];
|
||||
|
||||
NSString *destinationFile1 = [destinationDirectory stringByAppendingPathComponent:@"A"];
|
||||
NSString *destinationFile2 = [destinationDirectory stringByAppendingPathComponent:@"B"];
|
||||
NSString *destinationFile3 = [destinationFile2 stringByAppendingPathComponent:@"C"];
|
||||
|
||||
XCTAssertTrue([[NSData data] writeToFile:sourceFile atomically:YES]);
|
||||
XCTAssertTrue([[NSData dataWithBytes:"loltest" length:7] writeToFile:destinationFile1 atomically:YES]);
|
||||
|
||||
NSError *error = nil;
|
||||
if (![fileManager createDirectoryAtPath:destinationFile2 withIntermediateDirectories:NO attributes:nil error:&error]) {
|
||||
NSLog(@"Failed creating directory with error: %@", error);
|
||||
XCTFail("Failed to create directory");
|
||||
}
|
||||
|
||||
XCTAssertTrue([[self bigData2] writeToFile:destinationFile3 atomically:YES]);
|
||||
XCTAssertFalse([self testDirectoryHashEqualityWithSource:sourceDirectory destination:destinationDirectory]);
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)testRegularFileRemoved
|
||||
{
|
||||
[self createAndApplyPatchWithHandler:^(NSFileManager *__unused fileManager, NSString *sourceDirectory, NSString *destinationDirectory) {
|
||||
NSString *sourceFile = [sourceDirectory stringByAppendingPathComponent:@"A"];
|
||||
NSString *sourceFile2 = [destinationDirectory stringByAppendingPathComponent:@"B"];
|
||||
NSString *destinationFile = [destinationDirectory stringByAppendingPathComponent:@"A"];
|
||||
|
||||
XCTAssertTrue([[NSData data] writeToFile:sourceFile atomically:YES]);
|
||||
XCTAssertTrue([[NSData dataWithBytes:"lol" length:3] writeToFile:sourceFile2 atomically:YES]);
|
||||
XCTAssertTrue([[NSData dataWithBytes:"loltest" length:7] writeToFile:destinationFile atomically:YES]);
|
||||
|
||||
XCTAssertFalse([self testDirectoryHashEqualityWithSource:sourceDirectory destination:destinationDirectory]);
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)testDirectoryRemoved
|
||||
{
|
||||
[self createAndApplyPatchWithHandler:^(NSFileManager *fileManager, NSString *sourceDirectory, NSString *destinationDirectory) {
|
||||
NSString *destinationFile = [destinationDirectory stringByAppendingPathComponent:@"A"];
|
||||
|
||||
NSString *sourceFile1 = [sourceDirectory stringByAppendingPathComponent:@"A"];
|
||||
NSString *sourceFile2 = [sourceDirectory stringByAppendingPathComponent:@"B"];
|
||||
NSString *sourceFile3 = [sourceFile2 stringByAppendingPathComponent:@"C"];
|
||||
|
||||
XCTAssertTrue([[NSData data] writeToFile:destinationFile atomically:YES]);
|
||||
XCTAssertTrue([[NSData dataWithBytes:"loltest" length:7] writeToFile:sourceFile1 atomically:YES]);
|
||||
|
||||
NSError *error = nil;
|
||||
if (![fileManager createDirectoryAtPath:sourceFile2 withIntermediateDirectories:NO attributes:nil error:&error]) {
|
||||
NSLog(@"Failed creating directory with error: %@", error);
|
||||
XCTFail("Failed to create directory");
|
||||
}
|
||||
|
||||
XCTAssertTrue([[self bigData2] writeToFile:sourceFile3 atomically:YES]);
|
||||
XCTAssertFalse([self testDirectoryHashEqualityWithSource:sourceDirectory destination:destinationDirectory]);
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)testRegularFileMove
|
||||
{
|
||||
[self createAndApplyPatchWithHandler:^(NSFileManager *__unused fileManager, NSString *sourceDirectory, NSString *destinationDirectory) {
|
||||
NSString *sourceFile = [sourceDirectory stringByAppendingPathComponent:@"A"];
|
||||
NSString *destinationFile = [destinationDirectory stringByAppendingPathComponent:@"B"];
|
||||
|
||||
NSData *data = [NSData dataWithBytes:"loltest" length:7];
|
||||
XCTAssertTrue([data writeToFile:sourceFile atomically:YES]);
|
||||
XCTAssertTrue([data writeToFile:destinationFile atomically:YES]);
|
||||
|
||||
XCTAssertFalse([self testDirectoryHashEqualityWithSource:sourceDirectory destination:destinationDirectory]);
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)testCaseSensitiveRegularFileMove
|
||||
{
|
||||
[self createAndApplyPatchWithHandler:^(NSFileManager *__unused fileManager, NSString *sourceDirectory, NSString *destinationDirectory) {
|
||||
NSString *sourceFile1 = [sourceDirectory stringByAppendingPathComponent:@"A"];
|
||||
NSString *sourceFile2 = [sourceDirectory stringByAppendingPathComponent:@"b"];
|
||||
|
||||
NSString *destinationFile1 = [destinationDirectory stringByAppendingPathComponent:@"a"];
|
||||
NSString *destinationFile2 = [destinationDirectory stringByAppendingPathComponent:@"B"];
|
||||
|
||||
NSData *data = [NSData dataWithBytes:"loltest" length:7];
|
||||
|
||||
XCTAssertTrue([data writeToFile:sourceFile1 atomically:YES]);
|
||||
XCTAssertTrue([data writeToFile:sourceFile2 atomically:YES]);
|
||||
|
||||
XCTAssertTrue([data writeToFile:destinationFile1 atomically:YES]);
|
||||
XCTAssertTrue([data writeToFile:destinationFile2 atomically:YES]);
|
||||
|
||||
XCTAssertFalse([self testDirectoryHashEqualityWithSource:sourceDirectory destination:destinationDirectory]);
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)testRemovingSymlink
|
||||
{
|
||||
[self createAndApplyPatchWithHandler:^(NSFileManager *fileManager, NSString *sourceDirectory, NSString *destinationDirectory) {
|
||||
NSString *sourceFile = [sourceDirectory stringByAppendingPathComponent:@"A"];
|
||||
|
||||
NSError *error = nil;
|
||||
if (![fileManager createSymbolicLinkAtPath:sourceFile withDestinationPath:@"B" error:&error]) {
|
||||
NSLog(@"Error in creating symlink: %@", error);
|
||||
XCTFail(@"Failed to create symlink");
|
||||
}
|
||||
|
||||
XCTAssertFalse([self testDirectoryHashEqualityWithSource:sourceDirectory destination:destinationDirectory]);
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)testAddingSymlink
|
||||
{
|
||||
[self createAndApplyPatchWithHandler:^(NSFileManager *fileManager, NSString *sourceDirectory, NSString *destinationDirectory) {
|
||||
NSString *destinationFile = [destinationDirectory stringByAppendingPathComponent:@"A"];
|
||||
|
||||
NSError *error = nil;
|
||||
if (![fileManager createSymbolicLinkAtPath:destinationFile withDestinationPath:@"B" error:&error]) {
|
||||
NSLog(@"Error in creating symlink: %@", error);
|
||||
XCTFail(@"Failed to create symlink");
|
||||
}
|
||||
|
||||
XCTAssertFalse([self testDirectoryHashEqualityWithSource:sourceDirectory destination:destinationDirectory]);
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)testSmallFilePermissionChangeWithNoContentChange
|
||||
{
|
||||
[self createAndApplyPatchWithHandler:^(NSFileManager *fileManager, NSString *sourceDirectory, NSString *destinationDirectory) {
|
||||
NSString *sourceFile = [sourceDirectory stringByAppendingPathComponent:@"A"];
|
||||
NSString *destinationFile = [destinationDirectory stringByAppendingPathComponent:@"A"];
|
||||
|
||||
NSData *data = [NSData dataWithBytes:"loltest" length:7];
|
||||
XCTAssertTrue([data writeToFile:sourceFile atomically:YES]);
|
||||
XCTAssertTrue([data writeToFile:destinationFile atomically:YES]);
|
||||
|
||||
NSError *error = nil;
|
||||
if (![fileManager setAttributes:@{NSFilePosixPermissions : @0755} ofItemAtPath:destinationFile error:&error]) {
|
||||
NSLog(@"Change Permission Error: %@", error);
|
||||
XCTFail(@"Failed setting file permissions");
|
||||
}
|
||||
|
||||
// This would fail for version 1.0
|
||||
XCTAssertFalse([self testDirectoryHashEqualityWithSource:sourceDirectory destination:destinationDirectory]);
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)testBigFilePermissionChangeWithNoContentChange
|
||||
{
|
||||
[self createAndApplyPatchWithHandler:^(NSFileManager *fileManager, NSString *sourceDirectory, NSString *destinationDirectory) {
|
||||
NSString *sourceFile = [sourceDirectory stringByAppendingPathComponent:@"A"];
|
||||
NSString *destinationFile = [destinationDirectory stringByAppendingPathComponent:@"A"];
|
||||
|
||||
NSData *data = [self bigData1];
|
||||
XCTAssertTrue([data writeToFile:sourceFile atomically:YES]);
|
||||
XCTAssertTrue([data writeToFile:destinationFile atomically:YES]);
|
||||
|
||||
NSError *error = nil;
|
||||
if (![fileManager setAttributes:@{NSFilePosixPermissions : @0755} ofItemAtPath:destinationFile error:&error]) {
|
||||
NSLog(@"Change Permission Error: %@", error);
|
||||
XCTFail(@"Failed setting file permissions");
|
||||
}
|
||||
|
||||
// This would fail for version 1.0
|
||||
XCTAssertFalse([self testDirectoryHashEqualityWithSource:sourceDirectory destination:destinationDirectory]);
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)testSmallFilePermissionChangeWithContentChange
|
||||
{
|
||||
[self createAndApplyPatchWithHandler:^(NSFileManager *fileManager, NSString *sourceDirectory, NSString *destinationDirectory) {
|
||||
NSString *sourceFile = [sourceDirectory stringByAppendingPathComponent:@"A"];
|
||||
NSString *destinationFile = [destinationDirectory stringByAppendingPathComponent:@"A"];
|
||||
|
||||
XCTAssertTrue([[NSData data] writeToFile:sourceFile atomically:YES]);
|
||||
XCTAssertTrue([[NSData dataWithBytes:@"lawl" length:4] writeToFile:destinationFile atomically:YES]);
|
||||
|
||||
NSError *error = nil;
|
||||
if (![fileManager setAttributes:@{NSFilePosixPermissions : @0755} ofItemAtPath:destinationFile error:&error]) {
|
||||
NSLog(@"Change Permission Error: %@", error);
|
||||
XCTFail(@"Failed setting file permissions");
|
||||
}
|
||||
|
||||
// This would fail for version 1.0
|
||||
XCTAssertFalse([self testDirectoryHashEqualityWithSource:sourceDirectory destination:destinationDirectory]);
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)testBigFilePermissionChangeWithContentChange
|
||||
{
|
||||
[self createAndApplyPatchWithHandler:^(NSFileManager *fileManager, NSString *sourceDirectory, NSString *destinationDirectory) {
|
||||
NSString *sourceFile = [sourceDirectory stringByAppendingPathComponent:@"A"];
|
||||
NSString *destinationFile = [destinationDirectory stringByAppendingPathComponent:@"A"];
|
||||
|
||||
XCTAssertTrue([[self bigData1] writeToFile:sourceFile atomically:YES]);
|
||||
XCTAssertTrue([[self bigData2] writeToFile:destinationFile atomically:YES]);
|
||||
|
||||
NSError *error = nil;
|
||||
if (![fileManager setAttributes:@{NSFilePosixPermissions : @0755} ofItemAtPath:destinationFile error:&error]) {
|
||||
NSLog(@"Change Permission Error: %@", error);
|
||||
XCTFail(@"Failed setting file permissions");
|
||||
}
|
||||
|
||||
// This would fail for version 1.0
|
||||
XCTAssertFalse([self testDirectoryHashEqualityWithSource:sourceDirectory destination:destinationDirectory]);
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)testDirectoryPermissionChangeWithContentChange
|
||||
{
|
||||
[self createAndApplyPatchWithHandler:^(NSFileManager *fileManager, NSString *sourceDirectory, NSString *destinationDirectory) {
|
||||
NSString *sourceFile1 = [sourceDirectory stringByAppendingPathComponent:@"A"];
|
||||
NSString *sourceFile2 = [sourceFile1 stringByAppendingPathComponent:@"B"];
|
||||
|
||||
NSString *destinationFile1 = [destinationDirectory stringByAppendingPathComponent:@"A"];
|
||||
NSString *destinationFile2 = [destinationFile1 stringByAppendingPathComponent:@"B"];
|
||||
|
||||
NSError *error = nil;
|
||||
if (![fileManager createDirectoryAtPath:sourceFile1 withIntermediateDirectories:NO attributes:nil error:&error]) {
|
||||
NSLog(@"Failed creating directory with error: %@", error);
|
||||
XCTFail("Failed to create directory");
|
||||
}
|
||||
|
||||
if (![fileManager createDirectoryAtPath:destinationFile1 withIntermediateDirectories:NO attributes:nil error:&error]) {
|
||||
NSLog(@"Failed creating directory with error: %@", error);
|
||||
XCTFail("Failed to create directory");
|
||||
}
|
||||
|
||||
XCTAssertTrue([[self bigData1] writeToFile:sourceFile2 atomically:YES]);
|
||||
XCTAssertTrue([[self bigData1] writeToFile:destinationFile2 atomically:YES]);
|
||||
|
||||
if (![fileManager setAttributes:@{NSFilePosixPermissions : @0766} ofItemAtPath:sourceFile1 error:&error]) {
|
||||
NSLog(@"Change Permission Error: %@", error);
|
||||
XCTFail(@"Failed setting file permissions");
|
||||
}
|
||||
|
||||
if (![fileManager setAttributes:@{NSFilePosixPermissions : @0755} ofItemAtPath:destinationFile1 error:&error]) {
|
||||
NSLog(@"Change Permission Error: %@", error);
|
||||
XCTFail(@"Failed setting file permissions");
|
||||
}
|
||||
|
||||
// This would fail for version 1.0
|
||||
XCTAssertFalse([self testDirectoryHashEqualityWithSource:sourceDirectory destination:destinationDirectory]);
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)testInvalidPermissionsInAfterTree
|
||||
{
|
||||
BOOL success = [self createAndApplyPatchWithBeforeDiffHandler:^(NSFileManager *fileManager, NSString *sourceDirectory, NSString *destinationDirectory) {
|
||||
NSString *sourceFile = [sourceDirectory stringByAppendingPathComponent:@"A"];
|
||||
NSString *destinationFile = [destinationDirectory stringByAppendingPathComponent:@"A"];
|
||||
|
||||
NSData *data = [NSData dataWithBytes:"loltest" length:7];
|
||||
XCTAssertTrue([data writeToFile:sourceFile atomically:YES]);
|
||||
XCTAssertTrue([data writeToFile:destinationFile atomically:YES]);
|
||||
|
||||
NSError *error = nil;
|
||||
if (![fileManager setAttributes:@{NSFilePosixPermissions : @0777} ofItemAtPath:destinationFile error:&error]) {
|
||||
NSLog(@"Change Permission Error: %@", error);
|
||||
XCTFail(@"Failed setting file permissions");
|
||||
}
|
||||
|
||||
// This would fail for version 1.0
|
||||
XCTAssertFalse([self testDirectoryHashEqualityWithSource:sourceDirectory destination:destinationDirectory]);
|
||||
} afterDiffHandler:nil];
|
||||
XCTAssertFalse(success);
|
||||
}
|
||||
|
||||
- (void)testBadPermissionsInBeforeTree
|
||||
{
|
||||
[self createAndApplyPatchWithHandler:^(NSFileManager *fileManager, NSString *sourceDirectory, NSString *destinationDirectory) {
|
||||
NSString *sourceFile = [sourceDirectory stringByAppendingPathComponent:@"A"];
|
||||
NSString *destinationFile = [destinationDirectory stringByAppendingPathComponent:@"A"];
|
||||
|
||||
NSData *data = [NSData dataWithBytes:"loltest" length:7];
|
||||
XCTAssertTrue([data writeToFile:sourceFile atomically:YES]);
|
||||
XCTAssertTrue([data writeToFile:destinationFile atomically:YES]);
|
||||
|
||||
NSError *error = nil;
|
||||
if (![fileManager setAttributes:@{NSFilePosixPermissions : @0777} ofItemAtPath:sourceFile error:&error]) {
|
||||
NSLog(@"Change Permission Error: %@", error);
|
||||
XCTFail(@"Failed setting file permissions");
|
||||
}
|
||||
|
||||
// This would fail for version 1.0
|
||||
XCTAssertFalse([self testDirectoryHashEqualityWithSource:sourceDirectory destination:destinationDirectory]);
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)testInvalidRegularFileWithACLInBeforeTree
|
||||
{
|
||||
BOOL success = [self createAndApplyPatchWithBeforeDiffHandler:^(NSFileManager *__unused fileManager, NSString *sourceDirectory, NSString * __unused destinationDirectory) {
|
||||
NSString *sourceFile = [sourceDirectory stringByAppendingPathComponent:@"A"];
|
||||
|
||||
XCTAssertTrue([[NSData dataWithBytes:"loltest" length:7] writeToFile:sourceFile atomically:YES]);
|
||||
|
||||
acl_t acl = acl_init(1);
|
||||
|
||||
acl_entry_t entry;
|
||||
XCTAssertEqual(0, acl_create_entry(&acl, &entry));
|
||||
|
||||
acl_permset_t permset;
|
||||
XCTAssertEqual(0, acl_get_permset(entry, &permset));
|
||||
|
||||
XCTAssertEqual(0, acl_add_perm(permset, ACL_SEARCH));
|
||||
|
||||
XCTAssertEqual(0, acl_set_link_np([sourceFile fileSystemRepresentation], ACL_TYPE_EXTENDED, acl));
|
||||
|
||||
XCTAssertEqual(0, acl_free(acl));
|
||||
} afterDiffHandler:nil];
|
||||
|
||||
XCTAssertFalse(success);
|
||||
}
|
||||
|
||||
- (void)testInvalidRegularFileWithACLInAfterTree
|
||||
{
|
||||
BOOL success = [self createAndApplyPatchWithBeforeDiffHandler:^(NSFileManager *__unused fileManager, NSString *__unused sourceDirectory, NSString *destinationDirectory) {
|
||||
NSString *destinationFile = [destinationDirectory stringByAppendingPathComponent:@"A"];
|
||||
|
||||
XCTAssertTrue([[NSData dataWithBytes:"loltest" length:7] writeToFile:destinationFile atomically:YES]);
|
||||
|
||||
acl_t acl = acl_init(1);
|
||||
|
||||
acl_entry_t entry;
|
||||
XCTAssertEqual(0, acl_create_entry(&acl, &entry));
|
||||
|
||||
acl_permset_t permset;
|
||||
XCTAssertEqual(0, acl_get_permset(entry, &permset));
|
||||
|
||||
XCTAssertEqual(0, acl_add_perm(permset, ACL_SEARCH));
|
||||
|
||||
XCTAssertEqual(0, acl_set_link_np([destinationFile fileSystemRepresentation], ACL_TYPE_EXTENDED, acl));
|
||||
|
||||
XCTAssertEqual(0, acl_free(acl));
|
||||
|
||||
} afterDiffHandler:nil];
|
||||
|
||||
XCTAssertFalse(success);
|
||||
}
|
||||
|
||||
- (void)testInvalidDirectoryWithACLInBeforeTree
|
||||
{
|
||||
BOOL success = [self createAndApplyPatchWithBeforeDiffHandler:^(NSFileManager *fileManager, NSString *sourceDirectory, NSString * __unused destinationDirectory) {
|
||||
NSString *sourceFile = [sourceDirectory stringByAppendingPathComponent:@"A"];
|
||||
|
||||
XCTAssertTrue([fileManager createDirectoryAtPath:sourceFile withIntermediateDirectories:NO attributes:nil error:nil]);
|
||||
|
||||
acl_t acl = acl_init(1);
|
||||
|
||||
acl_entry_t entry;
|
||||
XCTAssertEqual(0, acl_create_entry(&acl, &entry));
|
||||
|
||||
acl_permset_t permset;
|
||||
XCTAssertEqual(0, acl_get_permset(entry, &permset));
|
||||
|
||||
XCTAssertEqual(0, acl_add_perm(permset, ACL_SEARCH));
|
||||
|
||||
XCTAssertEqual(0, acl_set_link_np([sourceFile fileSystemRepresentation], ACL_TYPE_EXTENDED, acl));
|
||||
|
||||
XCTAssertEqual(0, acl_free(acl));
|
||||
} afterDiffHandler:nil];
|
||||
|
||||
XCTAssertFalse(success);
|
||||
}
|
||||
|
||||
- (void)testInvalidDirectoryWithACLInAfterTree
|
||||
{
|
||||
BOOL success = [self createAndApplyPatchWithBeforeDiffHandler:^(NSFileManager *fileManager, NSString * __unused sourceDirectory, NSString *destinationDirectory) {
|
||||
NSString *destinationFile = [destinationDirectory stringByAppendingPathComponent:@"A"];
|
||||
|
||||
XCTAssertTrue([fileManager createDirectoryAtPath:destinationFile withIntermediateDirectories:NO attributes:nil error:nil]);
|
||||
|
||||
acl_t acl = acl_init(1);
|
||||
|
||||
acl_entry_t entry;
|
||||
XCTAssertEqual(0, acl_create_entry(&acl, &entry));
|
||||
|
||||
acl_permset_t permset;
|
||||
XCTAssertEqual(0, acl_get_permset(entry, &permset));
|
||||
|
||||
XCTAssertEqual(0, acl_add_perm(permset, ACL_SEARCH));
|
||||
|
||||
XCTAssertEqual(0, acl_set_link_np([destinationFile fileSystemRepresentation], ACL_TYPE_EXTENDED, acl));
|
||||
|
||||
XCTAssertEqual(0, acl_free(acl));
|
||||
} afterDiffHandler:nil];
|
||||
|
||||
XCTAssertFalse(success);
|
||||
}
|
||||
|
||||
- (void)testRegularFileToSymlinkChange
|
||||
{
|
||||
[self createAndApplyPatchWithHandler:^(NSFileManager *fileManager, NSString *sourceDirectory, NSString *destinationDirectory) {
|
||||
NSString *sourceFile1 = [sourceDirectory stringByAppendingPathComponent:@"A"];
|
||||
NSString *sourceFile2 = [sourceDirectory stringByAppendingPathComponent:@"B"];
|
||||
|
||||
NSString *destinationFile1 = [destinationDirectory stringByAppendingPathComponent:@"A"];
|
||||
NSString *destinationFile2 = [destinationDirectory stringByAppendingPathComponent:@"B"];
|
||||
|
||||
NSData *data = [NSData dataWithBytes:"A" length:1];
|
||||
|
||||
XCTAssertTrue([data writeToFile:sourceFile1 atomically:YES]);
|
||||
XCTAssertTrue([data writeToFile:sourceFile2 atomically:YES]);
|
||||
|
||||
XCTAssertTrue([data writeToFile:destinationFile1 atomically:YES]);
|
||||
|
||||
NSError *error = nil;
|
||||
if (![fileManager createSymbolicLinkAtPath:destinationFile2 withDestinationPath:@"A" error:&error]) {
|
||||
NSLog(@"Error in creating symlink: %@", error);
|
||||
XCTFail(@"Failed to create symlink");
|
||||
}
|
||||
|
||||
// This would fail with version 1.0
|
||||
XCTAssertFalse([self testDirectoryHashEqualityWithSource:sourceDirectory destination:destinationDirectory]);
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)testSymlinkToRegularFileChange
|
||||
{
|
||||
[self createAndApplyPatchWithHandler:^(NSFileManager *fileManager, NSString *sourceDirectory, NSString *destinationDirectory) {
|
||||
NSString *sourceFile1 = [sourceDirectory stringByAppendingPathComponent:@"A"];
|
||||
NSString *sourceFile2 = [sourceDirectory stringByAppendingPathComponent:@"B"];
|
||||
|
||||
NSString *destinationFile1 = [destinationDirectory stringByAppendingPathComponent:@"A"];
|
||||
NSString *destinationFile2 = [destinationDirectory stringByAppendingPathComponent:@"B"];
|
||||
|
||||
NSData *data = [NSData dataWithBytes:"loltest" length:7];
|
||||
|
||||
XCTAssertTrue([data writeToFile:sourceFile1 atomically:YES]);
|
||||
|
||||
XCTAssertTrue([data writeToFile:destinationFile1 atomically:YES]);
|
||||
XCTAssertTrue([data writeToFile:destinationFile2 atomically:YES]);
|
||||
|
||||
NSError *error = nil;
|
||||
if (![fileManager createSymbolicLinkAtPath:sourceFile2 withDestinationPath:@"A" error:&error]) {
|
||||
NSLog(@"Error in creating symlink: %@", error);
|
||||
XCTFail(@"Failed to create symlink");
|
||||
}
|
||||
|
||||
XCTAssertFalse([self testDirectoryHashEqualityWithSource:sourceDirectory destination:destinationDirectory]);
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)testRegularFileToDirectoryChange
|
||||
{
|
||||
[self createAndApplyPatchWithHandler:^(NSFileManager *fileManager, NSString *sourceDirectory, NSString *destinationDirectory) {
|
||||
NSString *sourceFile = [sourceDirectory stringByAppendingPathComponent:@"A"];
|
||||
NSString *destinationFile = [destinationDirectory stringByAppendingPathComponent:@"A"];
|
||||
|
||||
NSData *data = [NSData dataWithBytes:"loltest" length:7];
|
||||
XCTAssertTrue([data writeToFile:sourceFile atomically:YES]);
|
||||
|
||||
NSError *error = nil;
|
||||
if (![fileManager createDirectoryAtPath:destinationFile withIntermediateDirectories:NO attributes:nil error:&error]) {
|
||||
NSLog(@"Failed creating directory with error: %@", error);
|
||||
XCTFail("Failed to create directory");
|
||||
}
|
||||
|
||||
XCTAssertFalse([self testDirectoryHashEqualityWithSource:sourceDirectory destination:destinationDirectory]);
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)testDirectoryToRegularFileChange
|
||||
{
|
||||
[self createAndApplyPatchWithHandler:^(NSFileManager *fileManager, NSString *sourceDirectory, NSString *destinationDirectory) {
|
||||
NSString *sourceFile = [sourceDirectory stringByAppendingPathComponent:@"A"];
|
||||
NSString *destinationFile = [destinationDirectory stringByAppendingPathComponent:@"A"];
|
||||
|
||||
NSError *error = nil;
|
||||
if (![fileManager createDirectoryAtPath:sourceFile withIntermediateDirectories:NO attributes:nil error:&error]) {
|
||||
NSLog(@"Failed creating directory with error: %@", error);
|
||||
XCTFail("Failed to create directory");
|
||||
}
|
||||
|
||||
NSData *data = [NSData dataWithBytes:"loltest" length:7];
|
||||
XCTAssertTrue([data writeToFile:destinationFile atomically:YES]);
|
||||
|
||||
XCTAssertFalse([self testDirectoryHashEqualityWithSource:sourceDirectory destination:destinationDirectory]);
|
||||
}];
|
||||
}
|
||||
|
||||
// See issue #514 for more info
|
||||
- (void)testDirectoryToSymlinkChange
|
||||
{
|
||||
[self createAndApplyPatchWithHandler:^(NSFileManager *fileManager, NSString *sourceDirectory, NSString *destinationDirectory) {
|
||||
NSString *sourceFile1 = [sourceDirectory stringByAppendingPathComponent:@"A"];
|
||||
NSString *sourceFile2 = [sourceDirectory stringByAppendingPathComponent:@"Current"];
|
||||
NSString *sourceFile3 = [sourceFile2 stringByAppendingPathComponent:@"B"];
|
||||
|
||||
NSString *destinationFile1 = [destinationDirectory stringByAppendingPathComponent:@"A"];
|
||||
NSString *destinationFile2 = [destinationFile1 stringByAppendingPathComponent:@"B"];
|
||||
NSString *destinationFile3 = [destinationDirectory stringByAppendingPathComponent:@"Current"];
|
||||
|
||||
NSError *error = nil;
|
||||
if (![fileManager createDirectoryAtPath:sourceFile1 withIntermediateDirectories:NO attributes:nil error:&error]) {
|
||||
NSLog(@"Failed creating directory with error: %@", error);
|
||||
XCTFail("Failed to create directory A in source");
|
||||
}
|
||||
|
||||
if (![fileManager createDirectoryAtPath:sourceFile2 withIntermediateDirectories:NO attributes:nil error:&error]) {
|
||||
NSLog(@"Failed creating directory with error: %@", error);
|
||||
XCTFail("Failed to create directory Current in source");
|
||||
}
|
||||
|
||||
if (![fileManager createDirectoryAtPath:destinationFile1 withIntermediateDirectories:NO attributes:nil error:&error]) {
|
||||
NSLog(@"Failed creating directory with error: %@", error);
|
||||
XCTFail("Failed to create directory A in destination");
|
||||
}
|
||||
|
||||
if (![fileManager createSymbolicLinkAtPath:destinationFile3 withDestinationPath:@"A/" error:&error]) {
|
||||
NSLog(@"Error in creating symlink: %@", error);
|
||||
XCTFail(@"Failed to create symlink");
|
||||
}
|
||||
|
||||
XCTAssertTrue([[self bigData1] writeToFile:sourceFile3 atomically:YES]);
|
||||
XCTAssertTrue([[self bigData1] writeToFile:destinationFile2 atomically:YES]);
|
||||
|
||||
XCTAssertFalse([self testDirectoryHashEqualityWithSource:sourceDirectory destination:destinationDirectory]);
|
||||
}];
|
||||
}
|
||||
|
||||
// Opposite of the test method testDirectoryToSymlinkChange
|
||||
- (void)testSymlinkToDirectoryChange
|
||||
{
|
||||
[self createAndApplyPatchWithHandler:^(NSFileManager *fileManager, NSString *sourceDirectory, NSString *destinationDirectory) {
|
||||
NSString *sourceFile1 = [sourceDirectory stringByAppendingPathComponent:@"A"];
|
||||
NSString *sourceFile2 = [sourceFile1 stringByAppendingPathComponent:@"B"];
|
||||
NSString *sourceFile3 = [sourceDirectory stringByAppendingPathComponent:@"Current"];
|
||||
|
||||
NSString *destinationFile1 = [destinationDirectory stringByAppendingPathComponent:@"A"];
|
||||
NSString *destinationFile2 = [destinationDirectory stringByAppendingPathComponent:@"Current"];
|
||||
NSString *destinationFile3 = [destinationFile2 stringByAppendingPathComponent:@"B"];
|
||||
|
||||
NSError *error = nil;
|
||||
if (![fileManager createDirectoryAtPath:sourceFile1 withIntermediateDirectories:NO attributes:nil error:&error]) {
|
||||
NSLog(@"Failed creating directory with error: %@", error);
|
||||
XCTFail("Failed to create directory A in source");
|
||||
}
|
||||
|
||||
if (![fileManager createDirectoryAtPath:destinationFile1 withIntermediateDirectories:NO attributes:nil error:&error]) {
|
||||
NSLog(@"Failed creating directory with error: %@", error);
|
||||
XCTFail("Failed to create directory A in destination");
|
||||
}
|
||||
|
||||
if (![fileManager createDirectoryAtPath:destinationFile2 withIntermediateDirectories:NO attributes:nil error:&error]) {
|
||||
NSLog(@"Failed creating directory with error: %@", error);
|
||||
XCTFail("Failed to create directory Current in destination");
|
||||
}
|
||||
|
||||
if (![fileManager createSymbolicLinkAtPath:sourceFile3 withDestinationPath:@"A/" error:&error]) {
|
||||
NSLog(@"Error in creating symlink: %@", error);
|
||||
XCTFail(@"Failed to create symlink");
|
||||
}
|
||||
|
||||
XCTAssertTrue([[self bigData1] writeToFile:sourceFile2 atomically:YES]);
|
||||
XCTAssertTrue([[self bigData1] writeToFile:destinationFile3 atomically:YES]);
|
||||
|
||||
XCTAssertFalse([self testDirectoryHashEqualityWithSource:sourceDirectory destination:destinationDirectory]);
|
||||
}];
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,176 @@
|
||||
//
|
||||
// SUCodeSigningVerifierTest.m
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Isaac Wankerl on 04/13/2015.
|
||||
// Copyright (c) 2015 Sparkle Project. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
#import <XCTest/XCTest.h>
|
||||
#import "NTSynchronousTask.h"
|
||||
#import "SUCodeSigningVerifier.h"
|
||||
|
||||
@interface SUCodeSigningVerifierTest : XCTestCase
|
||||
|
||||
@property (copy) NSString *notSignedAppPath;
|
||||
@property (copy) NSString *validSignedAppPath;
|
||||
@property (copy) NSString *invalidSignedAppPath;
|
||||
|
||||
@end
|
||||
|
||||
@implementation SUCodeSigningVerifierTest
|
||||
|
||||
@synthesize notSignedAppPath = _notSignedAppPath;
|
||||
@synthesize validSignedAppPath = _validSignedAppPath;
|
||||
@synthesize invalidSignedAppPath = _invalidSignedAppPath;
|
||||
|
||||
- (void)setUp
|
||||
{
|
||||
[super setUp];
|
||||
|
||||
NSBundle *unitTestBundle = [NSBundle bundleForClass:[self class]];
|
||||
NSString *zippedAppPath = [unitTestBundle pathForResource:@"SparkleTestCodeSignApp" ofType:@"zip"];
|
||||
NSString *tempDir = [NSTemporaryDirectory() stringByAppendingPathComponent:[unitTestBundle bundleIdentifier]];
|
||||
NSError *error = nil;
|
||||
if ([[NSFileManager defaultManager] createDirectoryAtPath:tempDir withIntermediateDirectories:YES attributes:nil error:&error]) {
|
||||
if ([self unzip:zippedAppPath toPath:tempDir]) {
|
||||
self.notSignedAppPath = [tempDir stringByAppendingPathComponent:@"SparkleTestCodeSignApp.app"];
|
||||
[self setupValidSignedApp];
|
||||
[self setupInvalidSignedApp];
|
||||
}
|
||||
else {
|
||||
NSLog(@"Failed to unzip %@", zippedAppPath);
|
||||
}
|
||||
}
|
||||
else {
|
||||
NSLog(@"Failed to created dir %@ with error %@", tempDir, error);
|
||||
}
|
||||
}
|
||||
|
||||
- (void)tearDown
|
||||
{
|
||||
[super tearDown];
|
||||
|
||||
if (self.notSignedAppPath) {
|
||||
[[NSFileManager defaultManager] removeItemAtPath:self.notSignedAppPath error:nil];
|
||||
}
|
||||
if (self.validSignedAppPath) {
|
||||
[[NSFileManager defaultManager] removeItemAtPath:self.validSignedAppPath error:nil];
|
||||
}
|
||||
if (self.invalidSignedAppPath) {
|
||||
[[NSFileManager defaultManager] removeItemAtPath:self.invalidSignedAppPath error:nil];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)setupValidSignedApp
|
||||
{
|
||||
NSError *error = nil;
|
||||
NSString *tempDir = [self.notSignedAppPath stringByDeletingLastPathComponent];
|
||||
NSString *signedAndValid = [tempDir stringByAppendingPathComponent:@"valid-signed.app"];
|
||||
if ([[NSFileManager defaultManager] copyItemAtPath:self.notSignedAppPath toPath:signedAndValid error:&error]) {
|
||||
self.validSignedAppPath = signedAndValid;
|
||||
if (![self codesignAppPath:self.validSignedAppPath]) {
|
||||
NSLog(@"Failed to codesign %@", self.validSignedAppPath);
|
||||
}
|
||||
}
|
||||
else {
|
||||
NSLog(@"Failed to copy %@ to %@ with error %@", self.notSignedAppPath, signedAndValid, error);
|
||||
}
|
||||
}
|
||||
|
||||
- (void)setupInvalidSignedApp
|
||||
{
|
||||
NSError *error = nil;
|
||||
NSString *tempDir = [self.notSignedAppPath stringByDeletingLastPathComponent];
|
||||
NSString *signedAndInvalid = [tempDir stringByAppendingPathComponent:@"invalid-signed.app"];
|
||||
if ([[NSFileManager defaultManager] copyItemAtPath:self.notSignedAppPath toPath:signedAndInvalid error:&error]) {
|
||||
self.invalidSignedAppPath = signedAndInvalid;
|
||||
if ([self codesignAppPath:self.invalidSignedAppPath]) {
|
||||
NSString *fileInAppBundleToRemove = [self.invalidSignedAppPath stringByAppendingPathComponent:@"Contents/Resources/test_app_only_dsa_pub.pem"];
|
||||
if (![[NSFileManager defaultManager] removeItemAtPath:fileInAppBundleToRemove error:&error]) {
|
||||
NSLog(@"Failed to remove %@ with error %@", fileInAppBundleToRemove, error);
|
||||
}
|
||||
}
|
||||
else {
|
||||
NSLog(@"Failed to codesign %@", self.invalidSignedAppPath);
|
||||
}
|
||||
}
|
||||
else {
|
||||
NSLog(@"Failed to copy %@ to %@ with error %@", self.notSignedAppPath, signedAndInvalid, error);
|
||||
}
|
||||
}
|
||||
|
||||
- (BOOL)unzip:(NSString *)zipPath toPath:(NSString *)destPath
|
||||
{
|
||||
BOOL success = NO;
|
||||
@try
|
||||
{
|
||||
NTSynchronousTask *task = [[NTSynchronousTask alloc] init];
|
||||
NSArray *arguments = @[ zipPath ];
|
||||
[task run:@"/usr/bin/unzip" directory:destPath withArgs:arguments input:nil];
|
||||
success = ([task result] == 0);
|
||||
}
|
||||
@catch (NSException *exception)
|
||||
{
|
||||
NSLog(@"exception: %@", exception);
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
||||
- (BOOL)codesignAppPath:(NSString *)appPath
|
||||
{
|
||||
BOOL success = NO;
|
||||
@try
|
||||
{
|
||||
// ad-hoc signing with the dash
|
||||
NSArray *arguments = @[ @"--force", @"--deep", @"--sign", @"-", appPath ];
|
||||
NTSynchronousTask *task = [[NTSynchronousTask alloc] init];
|
||||
[task run:@"/usr/bin/codesign" directory:nil withArgs:arguments input:nil];
|
||||
success = ([task result] == 0);
|
||||
}
|
||||
@catch (NSException *exception)
|
||||
{
|
||||
NSLog(@"exception: %@", exception);
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
||||
- (void)testUnsignedApp
|
||||
{
|
||||
XCTAssertFalse([SUCodeSigningVerifier applicationAtPathIsCodeSigned:self.notSignedAppPath], @"App not expected to be code signed");
|
||||
|
||||
NSError *error = nil;
|
||||
XCTAssertFalse([SUCodeSigningVerifier codeSignatureIsValidAtPath:self.notSignedAppPath error:&error], @"signature should not be valid as it's not code signed");
|
||||
XCTAssertNotNil(error, @"error should not be nil");
|
||||
}
|
||||
|
||||
- (void)testValidSignedApp
|
||||
{
|
||||
XCTAssertTrue([SUCodeSigningVerifier applicationAtPathIsCodeSigned:self.validSignedAppPath], @"App expected to be code signed");
|
||||
|
||||
NSError *error = nil;
|
||||
XCTAssertTrue([SUCodeSigningVerifier codeSignatureIsValidAtPath:self.validSignedAppPath error:&error], @"signature should be valid");
|
||||
XCTAssertNil(error, @"error should be nil");
|
||||
}
|
||||
|
||||
- (void)testValidSignedCalculatorApp
|
||||
{
|
||||
NSString *appPath = @"/Applications/Calculator.app";
|
||||
XCTAssertTrue([SUCodeSigningVerifier applicationAtPathIsCodeSigned:appPath], @"App expected to be code signed");
|
||||
|
||||
NSError *error = nil;
|
||||
XCTAssertTrue([SUCodeSigningVerifier codeSignatureIsValidAtPath:appPath error:&error], @"signature should be valid");
|
||||
XCTAssertNil(error, @"error should be nil");
|
||||
}
|
||||
|
||||
- (void)testInvalidSignedApp
|
||||
{
|
||||
XCTAssertTrue([SUCodeSigningVerifier applicationAtPathIsCodeSigned:self.invalidSignedAppPath], @"App expected to be code signed, but signature is invalid");
|
||||
|
||||
NSError *error = nil;
|
||||
XCTAssertFalse([SUCodeSigningVerifier codeSignatureIsValidAtPath:self.invalidSignedAppPath error:&error], @"signature should not be valid");
|
||||
XCTAssertNotNil(error, @"error should not be nil");
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,65 @@
|
||||
//
|
||||
// SUInstallerTest.m
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Kornel on 24/04/2015.
|
||||
// Copyright (c) 2015 Sparkle Project. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
#import <XCTest/XCTest.h>
|
||||
#import "SUHost.h"
|
||||
#import "SUInstaller.h"
|
||||
#import <unistd.h>
|
||||
|
||||
@interface SUInstallerTest : XCTestCase
|
||||
|
||||
@end
|
||||
|
||||
@implementation SUInstallerTest
|
||||
|
||||
- (void)setUp
|
||||
{
|
||||
[super setUp];
|
||||
// Put setup code here. This method is called before the invocation of each test method in the class.
|
||||
}
|
||||
|
||||
- (void)tearDown
|
||||
{
|
||||
// Put teardown code here. This method is called after the invocation of each test method in the class.
|
||||
[super tearDown];
|
||||
}
|
||||
|
||||
- (void)testInstallIfRoot
|
||||
{
|
||||
uid_t uid = getuid();
|
||||
|
||||
if (uid) {
|
||||
NSLog(@"Test must be run as root: sudo xctest -XCTest SUInstallerTest 'Sparkle Unit Tests.xctest'");
|
||||
return;
|
||||
}
|
||||
|
||||
NSString *expectedDestination = @"/tmp/sparklepkgtest.app";
|
||||
NSFileManager *fm = [NSFileManager defaultManager];
|
||||
[fm removeItemAtPath:expectedDestination error:nil];
|
||||
XCTAssertFalse([fm fileExistsAtPath:expectedDestination isDirectory:nil]);
|
||||
|
||||
XCTestExpectation *done = [self expectationWithDescription:@"install finished"];
|
||||
|
||||
NSBundle *bundle = [NSBundle bundleForClass:[self class]];
|
||||
NSString *path = [bundle pathForResource:@"test.sparkle_guided" ofType:@"pkg"];
|
||||
XCTAssertNotNil(path);
|
||||
|
||||
SUHost *host = [[SUHost alloc] initWithBundle:bundle];
|
||||
|
||||
[SUInstaller installFromUpdateFolder:[path stringByDeletingLastPathComponent] overHost:host installationPath:@"/tmp" versionComparator:nil completionHandler:^(NSError *error) {
|
||||
XCTAssertNil(error);
|
||||
XCTAssertTrue([fm fileExistsAtPath:expectedDestination isDirectory:nil]);
|
||||
[done fulfill];
|
||||
}];
|
||||
|
||||
[self waitForExpectationsWithTimeout:40 handler:nil];
|
||||
[fm removeItemAtPath:expectedDestination error:nil];
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,70 @@
|
||||
//
|
||||
// SUPipedUnarchiverTest.m
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Kornel on 23/04/2015.
|
||||
// Copyright (c) 2015 Sparkle Project. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
#import <XCTest/XCTest.h>
|
||||
#import "SUUnarchiver.h"
|
||||
#import "SUPipedUnarchiver.h"
|
||||
|
||||
@interface SUPipedUnarchiverTest : XCTestCase<SUUnarchiverDelegate>
|
||||
@end
|
||||
|
||||
@implementation SUPipedUnarchiverTest {
|
||||
XCTestExpectation *unarchived;
|
||||
BOOL result;
|
||||
}
|
||||
|
||||
- (void)setUp {
|
||||
[super setUp];
|
||||
unarchived = [self expectationWithDescription:@"unarchived"];
|
||||
}
|
||||
|
||||
- (void)tearDown {
|
||||
// Put teardown code here. This method is called after the invocation of each test method in the class.
|
||||
[super tearDown];
|
||||
}
|
||||
|
||||
- (void) unarchiver:(SUUnarchiver *)unarchiver extractedProgress:(double)_unused {
|
||||
}
|
||||
|
||||
- (void) unarchiverDidFail:(SUUnarchiver *)_unused {
|
||||
result = NO;
|
||||
[unarchived fulfill];
|
||||
}
|
||||
|
||||
- (void) unarchiverDidFinish:(SUUnarchiver *)_unused {
|
||||
result = YES;
|
||||
[unarchived fulfill];
|
||||
}
|
||||
|
||||
- (void)testBlah {
|
||||
NSString *originalArchivePath = [[NSBundle bundleForClass:[self class]] pathForResource:@"test archive" ofType:@"zip"];
|
||||
NSString *tempDestDir = NSTemporaryDirectory();
|
||||
NSString *tempArchivePath = [[tempDestDir stringByAppendingPathComponent:[NSUUID UUID].UUIDString] stringByAppendingPathExtension:@"zip"];
|
||||
|
||||
NSFileManager *fm = [NSFileManager defaultManager];
|
||||
NSString *testFile = [tempDestDir stringByAppendingPathComponent:@"extracted file.txt"];
|
||||
[fm removeItemAtPath:testFile error:nil];
|
||||
|
||||
XCTAssertFalse([fm fileExistsAtPath:testFile isDirectory:nil]);
|
||||
XCTAssertTrue([fm copyItemAtPath:originalArchivePath toPath:tempArchivePath error:nil]);
|
||||
|
||||
SUUnarchiver *unarc = [SUUnarchiver unarchiverForPath:tempArchivePath updatingHostBundlePath:nil];
|
||||
|
||||
XCTAssertTrue([unarc isKindOfClass:[SUPipedUnarchiver class]]);
|
||||
|
||||
unarc.delegate = self;
|
||||
[unarc start];
|
||||
|
||||
[self waitForExpectationsWithTimeout:5.0 handler:nil];
|
||||
|
||||
XCTAssertTrue(result);
|
||||
XCTAssertTrue([fm fileExistsAtPath:testFile isDirectory:nil]);
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -29,6 +29,7 @@ __FBSDID("$FreeBSD: src/usr.bin/bsdiff/bsdiff/bsdiff.c, v 1.1 2005/08/06 01:59:0
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
#include "sais.h"
|
||||
|
||||
#include <err.h>
|
||||
#include <fcntl.h>
|
||||
@@ -39,138 +40,6 @@ __FBSDID("$FreeBSD: src/usr.bin/bsdiff/bsdiff/bsdiff.c, v 1.1 2005/08/06 01:59:0
|
||||
|
||||
#define MIN(x, y) (((x)<(y)) ? (x) : (y))
|
||||
|
||||
static void split(off_t *I, off_t *V, off_t start, off_t len, off_t h)
|
||||
{
|
||||
off_t i, j, k, x, tmp, jj, kk;
|
||||
|
||||
if (len < 16) {
|
||||
for (k = start; k < start + len; k += j) {
|
||||
j = 1; x = V[I[k] + h];
|
||||
for (i = 1; k + i < start + len; i++) {
|
||||
if (V[I[k + i] + h] < x) {
|
||||
x = V[I[k + i] + h];
|
||||
j = 0;
|
||||
};
|
||||
if (V[I[k + i] + h] == x) {
|
||||
tmp = I[k + j]; I[k + j] = I[k + i]; I[k + i] = tmp;
|
||||
j++;
|
||||
};
|
||||
};
|
||||
for (i = 0; i < j; i++)
|
||||
V[I[k + i]] = k + j - 1;
|
||||
if (j == 1)
|
||||
I[k] = -1;
|
||||
};
|
||||
return;
|
||||
};
|
||||
|
||||
x = V[I[start + len/2] + h];
|
||||
jj = 0; kk = 0;
|
||||
for (i = start; i < start + len; i++) {
|
||||
if (V[I[i] + h] < x)
|
||||
jj++;
|
||||
if (V[I[i] + h] == x)
|
||||
kk++;
|
||||
};
|
||||
jj += start; kk += jj;
|
||||
|
||||
i = start; j = 0; k = 0;
|
||||
while (i < jj) {
|
||||
if (V[I[i] + h] < x) {
|
||||
i++;
|
||||
} else if (V[I[i] + h] == x) {
|
||||
tmp = I[i]; I[i] = I[jj + j]; I[jj + j] = tmp;
|
||||
j++;
|
||||
} else {
|
||||
tmp = I[i]; I[i] = I[kk + k]; I[kk + k] = tmp;
|
||||
k++;
|
||||
};
|
||||
};
|
||||
|
||||
while (jj + j < kk) {
|
||||
if (V[I[jj + j] + h] == x) {
|
||||
j++;
|
||||
} else {
|
||||
tmp = I[jj + j]; I[jj + j] = I[kk + k]; I[kk + k] = tmp;
|
||||
k++;
|
||||
};
|
||||
};
|
||||
|
||||
if (jj > start)
|
||||
split(I, V, start, jj - start, h);
|
||||
|
||||
for (i = 0; i < kk - jj; i++)
|
||||
V[I[jj + i]] = kk - 1;
|
||||
if (jj == kk - 1)
|
||||
I[jj] = -1;
|
||||
|
||||
if (start + len > kk)
|
||||
split(I, V, kk, start + len - kk, h);
|
||||
}
|
||||
|
||||
/* qsufsort(I, V, old, oldsize)
|
||||
*
|
||||
* Computes the suffix sort of the string at 'old' and stores the resulting
|
||||
* indices in 'I', using 'V' as a temporary array for the computation. */
|
||||
static void qsufsort(off_t *I, off_t *V, u_char *old, off_t oldsize)
|
||||
{
|
||||
off_t buckets[256];
|
||||
off_t i, h, len;
|
||||
|
||||
/* count number of each byte */
|
||||
for (i = 0; i < 256; i++)
|
||||
buckets[i] = 0;
|
||||
for (i = 0; i < oldsize; i++)
|
||||
buckets[old[i]]++;
|
||||
/* make buckets cumulative */
|
||||
for (i = 1; i < 256; i++)
|
||||
buckets[i] += buckets[i - 1];
|
||||
/* shift right by one */
|
||||
for (i = 255; i > 0; i--)
|
||||
buckets[i] = buckets[i - 1];
|
||||
buckets[0] = 0;
|
||||
/* at this point, buckets[c] is the number of bytes in the old file with
|
||||
* value less than c. */
|
||||
|
||||
/* set up the sort order of the suffixes based solely on the first
|
||||
* character */
|
||||
for (i = 0; i < oldsize; i++)
|
||||
I[++buckets[old[i]]] = i;
|
||||
I[0] = oldsize;
|
||||
/* ? */
|
||||
for (i = 0; i < oldsize; i++)
|
||||
V[i] = buckets[old[i]];
|
||||
V[oldsize] = 0;
|
||||
/* forward any entries in the ordering which have the same initial
|
||||
* character */
|
||||
for (i = 1; i < 256; i++) {
|
||||
if (buckets[i] == buckets[i - 1] + 1)
|
||||
I[buckets[i]] = -1;
|
||||
}
|
||||
I[0] = -1;
|
||||
|
||||
for (h = 1; I[0] != -(oldsize + 1); h += h) {
|
||||
len = 0;
|
||||
for (i = 0; i < oldsize + 1;) {
|
||||
if (I[i] < 0) {
|
||||
len -= I[i];
|
||||
i -= I[i];
|
||||
} else {
|
||||
if (len)
|
||||
I[i - len] = -len;
|
||||
len = V[I[i]] + 1 - i;
|
||||
split(I, V, i, len, h);
|
||||
i += len;
|
||||
len = 0;
|
||||
}
|
||||
}
|
||||
if (len)
|
||||
I[i - len] = -len;
|
||||
};
|
||||
|
||||
for (i = 0; i < oldsize + 1; i++) I[V[i]] = i;
|
||||
}
|
||||
|
||||
/* matchlen(old, oldsize, new, newsize)
|
||||
*
|
||||
* Returns the length of the longest common prefix between 'old' and 'new'. */
|
||||
@@ -255,7 +124,7 @@ int bsdiff(int argc, char *argv[])
|
||||
off_t oldsize, newsize; /* length of old, new files */
|
||||
off_t *I,*V; /* arrays used for suffix sort; I is ordering */
|
||||
off_t scan; /* position of current match in old file */
|
||||
off_t pos; /* position of current match in new file */
|
||||
off_t pos = 0; /* position of current match in new file */
|
||||
off_t len; /* length of current match */
|
||||
off_t lastscan; /* position of previous match in old file */
|
||||
off_t lastpos; /* position of previous match in new file */
|
||||
@@ -288,7 +157,7 @@ int bsdiff(int argc, char *argv[])
|
||||
err(1, NULL);
|
||||
|
||||
/* Do a suffix sort on the old file. */
|
||||
qsufsort(I, V, old, oldsize);
|
||||
I[0] = oldsize; sais(old, I+1, oldsize);
|
||||
|
||||
free(V);
|
||||
|
||||
|
||||
@@ -0,0 +1,534 @@
|
||||
/*
|
||||
* sais.c for sais-lite
|
||||
* Copyright (c) 2008-2010 Yuta Mori All Rights Reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person
|
||||
* obtaining a copy of this software and associated documentation
|
||||
* files (the "Software"), to deal in the Software without
|
||||
* restriction, including without limitation the rights to use,
|
||||
* copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following
|
||||
* conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
* OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
#include "sais.h"
|
||||
|
||||
#ifndef UCHAR_SIZE
|
||||
# define UCHAR_SIZE 256
|
||||
#endif
|
||||
#ifndef MINBUCKETSIZE
|
||||
# define MINBUCKETSIZE 256
|
||||
#endif
|
||||
|
||||
#define sais_bool_type int
|
||||
#define SAIS_LMSSORT2_LIMIT 0x3fffffff
|
||||
|
||||
#define SAIS_MYMALLOC(_num, _type) ((_type *)malloc((_num) * sizeof(_type)))
|
||||
#define SAIS_MYFREE(_ptr, _num, _type) free((_ptr))
|
||||
#define chr(_a) (cs == sizeof(sais_index_type) ? ((sais_index_type *)T)[(_a)] : ((unsigned char *)T)[(_a)])
|
||||
|
||||
/* find the start or end of each bucket */
|
||||
static
|
||||
void
|
||||
getCounts(const void *T, sais_index_type *C, sais_index_type n, sais_index_type k, int cs) {
|
||||
sais_index_type i;
|
||||
for(i = 0; i < k; ++i) { C[i] = 0; }
|
||||
for(i = 0; i < n; ++i) { ++C[chr(i)]; }
|
||||
}
|
||||
static
|
||||
void
|
||||
getBuckets(const sais_index_type *C, sais_index_type *B, sais_index_type k, sais_bool_type end) {
|
||||
sais_index_type i, sum = 0;
|
||||
if(end) { for(i = 0; i < k; ++i) { sum += C[i]; B[i] = sum; } }
|
||||
else { for(i = 0; i < k; ++i) { sum += C[i]; B[i] = sum - C[i]; } }
|
||||
}
|
||||
|
||||
/* sort all type LMS suffixes */
|
||||
static
|
||||
void
|
||||
LMSsort1(const void *T, sais_index_type *SA,
|
||||
sais_index_type *C, sais_index_type *B,
|
||||
sais_index_type n, sais_index_type k, int cs) {
|
||||
sais_index_type *b, i, j;
|
||||
sais_index_type c0, c1;
|
||||
|
||||
/* compute SAl */
|
||||
if(C == B) { getCounts(T, C, n, k, cs); }
|
||||
getBuckets(C, B, k, 0); /* find starts of buckets */
|
||||
j = n - 1;
|
||||
b = SA + B[c1 = chr(j)];
|
||||
--j;
|
||||
*b++ = (chr(j) < c1) ? ~j : j;
|
||||
for(i = 0; i < n; ++i) {
|
||||
if(0 < (j = SA[i])) {
|
||||
assert(chr(j) >= chr(j + 1));
|
||||
if((c0 = chr(j)) != c1) { B[c1] = b - SA; b = SA + B[c1 = c0]; }
|
||||
assert(i < (b - SA));
|
||||
--j;
|
||||
*b++ = (chr(j) < c1) ? ~j : j;
|
||||
SA[i] = 0;
|
||||
} else if(j < 0) {
|
||||
SA[i] = ~j;
|
||||
}
|
||||
}
|
||||
/* compute SAs */
|
||||
if(C == B) { getCounts(T, C, n, k, cs); }
|
||||
getBuckets(C, B, k, 1); /* find ends of buckets */
|
||||
for(i = n - 1, b = SA + B[c1 = 0]; 0 <= i; --i) {
|
||||
if(0 < (j = SA[i])) {
|
||||
assert(chr(j) <= chr(j + 1));
|
||||
if((c0 = chr(j)) != c1) { B[c1] = b - SA; b = SA + B[c1 = c0]; }
|
||||
assert((b - SA) <= i);
|
||||
--j;
|
||||
*--b = (chr(j) > c1) ? ~(j + 1) : j;
|
||||
SA[i] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
static
|
||||
sais_index_type
|
||||
LMSpostproc1(const void *T, sais_index_type *SA,
|
||||
sais_index_type n, sais_index_type m, int cs) {
|
||||
sais_index_type i, j, p, q, plen, qlen, name;
|
||||
sais_index_type c0, c1;
|
||||
sais_bool_type diff;
|
||||
|
||||
/* compact all the sorted substrings into the first m items of SA
|
||||
2*m must be not larger than n (proveable) */
|
||||
assert(0 < n);
|
||||
for(i = 0; (p = SA[i]) < 0; ++i) { SA[i] = ~p; assert((i + 1) < n); }
|
||||
if(i < m) {
|
||||
for(j = i, ++i;; ++i) {
|
||||
assert(i < n);
|
||||
if((p = SA[i]) < 0) {
|
||||
SA[j++] = ~p; SA[i] = 0;
|
||||
if(j == m) { break; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* store the length of all substrings */
|
||||
i = n - 1; j = n - 1; c0 = chr(n - 1);
|
||||
do { c1 = c0; } while((0 <= --i) && ((c0 = chr(i)) >= c1));
|
||||
for(; 0 <= i;) {
|
||||
do { c1 = c0; } while((0 <= --i) && ((c0 = chr(i)) <= c1));
|
||||
if(0 <= i) {
|
||||
SA[m + ((i + 1) >> 1)] = j - i; j = i + 1;
|
||||
do { c1 = c0; } while((0 <= --i) && ((c0 = chr(i)) >= c1));
|
||||
}
|
||||
}
|
||||
|
||||
/* find the lexicographic names of all substrings */
|
||||
for(i = 0, name = 0, q = n, qlen = 0; i < m; ++i) {
|
||||
p = SA[i], plen = SA[m + (p >> 1)], diff = 1;
|
||||
if((plen == qlen) && ((q + plen) < n)) {
|
||||
for(j = 0; (j < plen) && (chr(p + j) == chr(q + j)); ++j) { }
|
||||
if(j == plen) { diff = 0; }
|
||||
}
|
||||
if(diff != 0) { ++name, q = p, qlen = plen; }
|
||||
SA[m + (p >> 1)] = name;
|
||||
}
|
||||
|
||||
return name;
|
||||
}
|
||||
static
|
||||
void
|
||||
LMSsort2(const void *T, sais_index_type *SA,
|
||||
sais_index_type *C, sais_index_type *B, sais_index_type *D,
|
||||
sais_index_type n, sais_index_type k, int cs) {
|
||||
sais_index_type *b, i, j, t, d;
|
||||
sais_index_type c0, c1;
|
||||
assert(C != B);
|
||||
|
||||
/* compute SAl */
|
||||
getBuckets(C, B, k, 0); /* find starts of buckets */
|
||||
j = n - 1;
|
||||
b = SA + B[c1 = chr(j)];
|
||||
--j;
|
||||
t = (chr(j) < c1);
|
||||
j += n;
|
||||
*b++ = (t & 1) ? ~j : j;
|
||||
for(i = 0, d = 0; i < n; ++i) {
|
||||
if(0 < (j = SA[i])) {
|
||||
if(n <= j) { d += 1; j -= n; }
|
||||
assert(chr(j) >= chr(j + 1));
|
||||
if((c0 = chr(j)) != c1) { B[c1] = b - SA; b = SA + B[c1 = c0]; }
|
||||
assert(i < (b - SA));
|
||||
--j;
|
||||
t = c0; t = (t << 1) | (chr(j) < c1);
|
||||
if(D[t] != d) { j += n; D[t] = d; }
|
||||
*b++ = (t & 1) ? ~j : j;
|
||||
SA[i] = 0;
|
||||
} else if(j < 0) {
|
||||
SA[i] = ~j;
|
||||
}
|
||||
}
|
||||
for(i = n - 1; 0 <= i; --i) {
|
||||
if(0 < SA[i]) {
|
||||
if(SA[i] < n) {
|
||||
SA[i] += n;
|
||||
for(j = i - 1; SA[j] < n; --j) { }
|
||||
SA[j] -= n;
|
||||
i = j;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* compute SAs */
|
||||
getBuckets(C, B, k, 1); /* find ends of buckets */
|
||||
for(i = n - 1, d += 1, b = SA + B[c1 = 0]; 0 <= i; --i) {
|
||||
if(0 < (j = SA[i])) {
|
||||
if(n <= j) { d += 1; j -= n; }
|
||||
assert(chr(j) <= chr(j + 1));
|
||||
if((c0 = chr(j)) != c1) { B[c1] = b - SA; b = SA + B[c1 = c0]; }
|
||||
assert((b - SA) <= i);
|
||||
--j;
|
||||
t = c0; t = (t << 1) | (chr(j) > c1);
|
||||
if(D[t] != d) { j += n; D[t] = d; }
|
||||
*--b = (t & 1) ? ~(j + 1) : j;
|
||||
SA[i] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
static
|
||||
sais_index_type
|
||||
LMSpostproc2(sais_index_type *SA, sais_index_type n, sais_index_type m) {
|
||||
sais_index_type i, j, d, name;
|
||||
|
||||
/* compact all the sorted LMS substrings into the first m items of SA */
|
||||
assert(0 < n);
|
||||
for(i = 0, name = 0; (j = SA[i]) < 0; ++i) {
|
||||
j = ~j;
|
||||
if(n <= j) { name += 1; }
|
||||
SA[i] = j;
|
||||
assert((i + 1) < n);
|
||||
}
|
||||
if(i < m) {
|
||||
for(d = i, ++i;; ++i) {
|
||||
assert(i < n);
|
||||
if((j = SA[i]) < 0) {
|
||||
j = ~j;
|
||||
if(n <= j) { name += 1; }
|
||||
SA[d++] = j; SA[i] = 0;
|
||||
if(d == m) { break; }
|
||||
}
|
||||
}
|
||||
}
|
||||
if(name < m) {
|
||||
/* store the lexicographic names */
|
||||
for(i = m - 1, d = name + 1; 0 <= i; --i) {
|
||||
if(n <= (j = SA[i])) { j -= n; --d; }
|
||||
SA[m + (j >> 1)] = d;
|
||||
}
|
||||
} else {
|
||||
/* unset flags */
|
||||
for(i = 0; i < m; ++i) {
|
||||
if(n <= (j = SA[i])) { j -= n; SA[i] = j; }
|
||||
}
|
||||
}
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
/* compute SA and BWT */
|
||||
static
|
||||
void
|
||||
induceSA(const void *T, sais_index_type *SA,
|
||||
sais_index_type *C, sais_index_type *B,
|
||||
sais_index_type n, sais_index_type k, int cs) {
|
||||
sais_index_type *b, i, j;
|
||||
sais_index_type c0, c1;
|
||||
/* compute SAl */
|
||||
if(C == B) { getCounts(T, C, n, k, cs); }
|
||||
getBuckets(C, B, k, 0); /* find starts of buckets */
|
||||
j = n - 1;
|
||||
b = SA + B[c1 = chr(j)];
|
||||
*b++ = ((0 < j) && (chr(j - 1) < c1)) ? ~j : j;
|
||||
for(i = 0; i < n; ++i) {
|
||||
j = SA[i], SA[i] = ~j;
|
||||
if(0 < j) {
|
||||
--j;
|
||||
assert(chr(j) >= chr(j + 1));
|
||||
if((c0 = chr(j)) != c1) { B[c1] = b - SA; b = SA + B[c1 = c0]; }
|
||||
assert(i < (b - SA));
|
||||
*b++ = ((0 < j) && (chr(j - 1) < c1)) ? ~j : j;
|
||||
}
|
||||
}
|
||||
/* compute SAs */
|
||||
if(C == B) { getCounts(T, C, n, k, cs); }
|
||||
getBuckets(C, B, k, 1); /* find ends of buckets */
|
||||
for(i = n - 1, b = SA + B[c1 = 0]; 0 <= i; --i) {
|
||||
if(0 < (j = SA[i])) {
|
||||
--j;
|
||||
assert(chr(j) <= chr(j + 1));
|
||||
if((c0 = chr(j)) != c1) { B[c1] = b - SA; b = SA + B[c1 = c0]; }
|
||||
assert((b - SA) <= i);
|
||||
*--b = ((j == 0) || (chr(j - 1) > c1)) ? ~j : j;
|
||||
} else {
|
||||
SA[i] = ~j;
|
||||
}
|
||||
}
|
||||
}
|
||||
static
|
||||
sais_index_type
|
||||
computeBWT(const void *T, sais_index_type *SA,
|
||||
sais_index_type *C, sais_index_type *B,
|
||||
sais_index_type n, sais_index_type k, int cs) {
|
||||
sais_index_type *b, i, j, pidx = -1;
|
||||
sais_index_type c0, c1;
|
||||
/* compute SAl */
|
||||
if(C == B) { getCounts(T, C, n, k, cs); }
|
||||
getBuckets(C, B, k, 0); /* find starts of buckets */
|
||||
j = n - 1;
|
||||
b = SA + B[c1 = chr(j)];
|
||||
*b++ = ((0 < j) && (chr(j - 1) < c1)) ? ~j : j;
|
||||
for(i = 0; i < n; ++i) {
|
||||
if(0 < (j = SA[i])) {
|
||||
--j;
|
||||
assert(chr(j) >= chr(j + 1));
|
||||
SA[i] = ~((sais_index_type)(c0 = chr(j)));
|
||||
if(c0 != c1) { B[c1] = b - SA; b = SA + B[c1 = c0]; }
|
||||
assert(i < (b - SA));
|
||||
*b++ = ((0 < j) && (chr(j - 1) < c1)) ? ~j : j;
|
||||
} else if(j != 0) {
|
||||
SA[i] = ~j;
|
||||
}
|
||||
}
|
||||
/* compute SAs */
|
||||
if(C == B) { getCounts(T, C, n, k, cs); }
|
||||
getBuckets(C, B, k, 1); /* find ends of buckets */
|
||||
for(i = n - 1, b = SA + B[c1 = 0]; 0 <= i; --i) {
|
||||
if(0 < (j = SA[i])) {
|
||||
--j;
|
||||
assert(chr(j) <= chr(j + 1));
|
||||
SA[i] = (c0 = chr(j));
|
||||
if(c0 != c1) { B[c1] = b - SA; b = SA + B[c1 = c0]; }
|
||||
assert((b - SA) <= i);
|
||||
*--b = ((0 < j) && (chr(j - 1) > c1)) ? ~((sais_index_type)chr(j - 1)) : j;
|
||||
} else if(j != 0) {
|
||||
SA[i] = ~j;
|
||||
} else {
|
||||
pidx = i;
|
||||
}
|
||||
}
|
||||
return pidx;
|
||||
}
|
||||
|
||||
/* find the suffix array SA of T[0..n-1] in {0..255}^n */
|
||||
static
|
||||
sais_index_type
|
||||
sais_main(const void *T, sais_index_type *SA,
|
||||
sais_index_type fs, sais_index_type n, sais_index_type k, int cs,
|
||||
sais_bool_type isbwt) {
|
||||
sais_index_type *C, *B, *D, *RA, *b;
|
||||
sais_index_type i, j, m, p, q, t, name, pidx = 0, newfs;
|
||||
sais_index_type c0, c1;
|
||||
unsigned int flags;
|
||||
|
||||
assert((T != NULL) && (SA != NULL));
|
||||
assert((0 <= fs) && (0 < n) && (1 <= k));
|
||||
|
||||
if(k <= MINBUCKETSIZE) {
|
||||
if((C = SAIS_MYMALLOC((size_t)k, sais_index_type)) == NULL) { return -2; }
|
||||
if(k <= fs) {
|
||||
B = SA + (n + fs - k);
|
||||
flags = 1;
|
||||
} else {
|
||||
if((B = SAIS_MYMALLOC((size_t)k, sais_index_type)) == NULL) { SAIS_MYFREE(C, k, sais_index_type); return -2; }
|
||||
flags = 3;
|
||||
}
|
||||
} else if(k <= fs) {
|
||||
C = SA + (n + fs - k);
|
||||
if(k <= (fs - k)) {
|
||||
B = C - k;
|
||||
flags = 0;
|
||||
} else if(k <= (MINBUCKETSIZE * 4)) {
|
||||
if((B = SAIS_MYMALLOC((size_t)k, sais_index_type)) == NULL) { return -2; }
|
||||
flags = 2;
|
||||
} else {
|
||||
B = C;
|
||||
flags = 8;
|
||||
}
|
||||
} else {
|
||||
if((C = B = SAIS_MYMALLOC((size_t)k, sais_index_type)) == NULL) { return -2; }
|
||||
flags = 4 | 8;
|
||||
}
|
||||
if((n <= SAIS_LMSSORT2_LIMIT) && (2 <= (n / k))) {
|
||||
if(flags & 1) { flags |= ((k * 2) <= (fs - k)) ? 32 : 16; }
|
||||
else if((flags == 0) && ((k * 2) <= (fs - k * 2))) { flags |= 32; }
|
||||
}
|
||||
|
||||
/* stage 1: reduce the problem by at least 1/2
|
||||
sort all the LMS-substrings */
|
||||
getCounts(T, C, n, k, cs); getBuckets(C, B, k, 1); /* find ends of buckets */
|
||||
for(i = 0; i < n; ++i) { SA[i] = 0; }
|
||||
b = &t; i = n - 1; j = n; m = 0; c0 = chr(n - 1);
|
||||
do { c1 = c0; } while((0 <= --i) && ((c0 = chr(i)) >= c1));
|
||||
for(; 0 <= i;) {
|
||||
do { c1 = c0; } while((0 <= --i) && ((c0 = chr(i)) <= c1));
|
||||
if(0 <= i) {
|
||||
*b = j; b = SA + --B[c1]; j = i; ++m;
|
||||
do { c1 = c0; } while((0 <= --i) && ((c0 = chr(i)) >= c1));
|
||||
}
|
||||
}
|
||||
|
||||
if(1 < m) {
|
||||
if(flags & (16 | 32)) {
|
||||
if(flags & 16) {
|
||||
if((D = SAIS_MYMALLOC((size_t)k * 2, sais_index_type)) == NULL) {
|
||||
if(flags & (1 | 4)) { SAIS_MYFREE(C, k, sais_index_type); }
|
||||
if(flags & 2) { SAIS_MYFREE(B, k, sais_index_type); }
|
||||
return -2;
|
||||
}
|
||||
} else {
|
||||
D = B - k * 2;
|
||||
}
|
||||
assert((j + 1) < n);
|
||||
++B[chr(j + 1)];
|
||||
for(i = 0, j = 0; i < k; ++i) {
|
||||
j += C[i];
|
||||
if(B[i] != j) { assert(SA[B[i]] != 0); SA[B[i]] += n; }
|
||||
D[i] = D[i + k] = 0;
|
||||
}
|
||||
LMSsort2(T, SA, C, B, D, n, k, cs);
|
||||
name = LMSpostproc2(SA, n, m);
|
||||
if(flags & 16) { SAIS_MYFREE(D, k * 2, sais_index_type); }
|
||||
} else {
|
||||
LMSsort1(T, SA, C, B, n, k, cs);
|
||||
name = LMSpostproc1(T, SA, n, m, cs);
|
||||
}
|
||||
} else if(m == 1) {
|
||||
*b = j + 1;
|
||||
name = 1;
|
||||
} else {
|
||||
name = 0;
|
||||
}
|
||||
|
||||
/* stage 2: solve the reduced problem
|
||||
recurse if names are not yet unique */
|
||||
if(name < m) {
|
||||
if(flags & 4) { SAIS_MYFREE(C, k, sais_index_type); }
|
||||
if(flags & 2) { SAIS_MYFREE(B, k, sais_index_type); }
|
||||
newfs = (n + fs) - (m * 2);
|
||||
if((flags & (1 | 4 | 8)) == 0) {
|
||||
if((k + name) <= newfs) { newfs -= k; }
|
||||
else { flags |= 8; }
|
||||
}
|
||||
assert((n >> 1) <= (newfs + m));
|
||||
RA = SA + m + newfs;
|
||||
for(i = m + (n >> 1) - 1, j = m - 1; m <= i; --i) {
|
||||
if(SA[i] != 0) {
|
||||
RA[j--] = SA[i] - 1;
|
||||
}
|
||||
}
|
||||
if(sais_main(RA, SA, newfs, m, name, sizeof(sais_index_type), 0) != 0) {
|
||||
if(flags & 1) { SAIS_MYFREE(C, k, sais_index_type); }
|
||||
return -2;
|
||||
}
|
||||
|
||||
i = n - 1; j = m - 1; c0 = chr(n - 1);
|
||||
do { c1 = c0; } while((0 <= --i) && ((c0 = chr(i)) >= c1));
|
||||
for(; 0 <= i;) {
|
||||
do { c1 = c0; } while((0 <= --i) && ((c0 = chr(i)) <= c1));
|
||||
if(0 <= i) {
|
||||
RA[j--] = i + 1;
|
||||
do { c1 = c0; } while((0 <= --i) && ((c0 = chr(i)) >= c1));
|
||||
}
|
||||
}
|
||||
for(i = 0; i < m; ++i) { SA[i] = RA[SA[i]]; }
|
||||
if(flags & 4) {
|
||||
if((C = B = SAIS_MYMALLOC((size_t)k, sais_index_type)) == NULL) { return -2; }
|
||||
}
|
||||
if(flags & 2) {
|
||||
if((B = SAIS_MYMALLOC((size_t)k, sais_index_type)) == NULL) {
|
||||
if(flags & 1) { SAIS_MYFREE(C, k, sais_index_type); }
|
||||
return -2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* stage 3: induce the result for the original problem */
|
||||
if(flags & 8) { getCounts(T, C, n, k, cs); }
|
||||
/* put all left-most S characters into their buckets */
|
||||
if(1 < m) {
|
||||
getBuckets(C, B, k, 1); /* find ends of buckets */
|
||||
i = m - 1, j = n, p = SA[m - 1], c1 = chr(p);
|
||||
do {
|
||||
q = B[c0 = c1];
|
||||
while(q < j) { SA[--j] = 0; }
|
||||
do {
|
||||
SA[--j] = p;
|
||||
if(--i < 0) { break; }
|
||||
p = SA[i];
|
||||
} while((c1 = chr(p)) == c0);
|
||||
} while(0 <= i);
|
||||
while(0 < j) { SA[--j] = 0; }
|
||||
}
|
||||
if(isbwt == 0) { induceSA(T, SA, C, B, n, k, cs); }
|
||||
else { pidx = computeBWT(T, SA, C, B, n, k, cs); }
|
||||
if(flags & (1 | 4)) { SAIS_MYFREE(C, k, sais_index_type); }
|
||||
if(flags & 2) { SAIS_MYFREE(B, k, sais_index_type); }
|
||||
|
||||
return pidx;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
sais_index_type
|
||||
sais(const unsigned char *T, sais_index_type *SA, int n) {
|
||||
if((T == NULL) || (SA == NULL) || (n < 0)) { return -1; }
|
||||
if(n <= 1) { if(n == 1) { SA[0] = 0; } return 0; }
|
||||
return sais_main(T, SA, 0, n, UCHAR_SIZE, sizeof(unsigned char), 0);
|
||||
}
|
||||
|
||||
sais_index_type
|
||||
sais_int(const int *T, sais_index_type *SA, int n, int k) {
|
||||
if((T == NULL) || (SA == NULL) || (n < 0) || (k <= 0)) { return -1; }
|
||||
if(n <= 1) { if(n == 1) { SA[0] = 0; } return 0; }
|
||||
return sais_main(T, SA, 0, n, k, sizeof(int), 0);
|
||||
}
|
||||
|
||||
sais_index_type
|
||||
sais_bwt(const unsigned char *T, unsigned char *U, sais_index_type *A, int n) {
|
||||
int i;
|
||||
sais_index_type pidx;
|
||||
if((T == NULL) || (U == NULL) || (A == NULL) || (n < 0)) { return -1; }
|
||||
if(n <= 1) { if(n == 1) { U[0] = T[0]; } return n; }
|
||||
pidx = sais_main(T, A, 0, n, UCHAR_SIZE, sizeof(unsigned char), 1);
|
||||
if(pidx < 0) { return pidx; }
|
||||
U[0] = T[n - 1];
|
||||
for(i = 0; i < pidx; ++i) { U[i + 1] = (unsigned char)A[i]; }
|
||||
for(i += 1; i < n; ++i) { U[i] = (unsigned char)A[i]; }
|
||||
pidx += 1;
|
||||
return pidx;
|
||||
}
|
||||
|
||||
sais_index_type
|
||||
sais_int_bwt(const sais_index_type *T, sais_index_type *U, sais_index_type *A, int n, int k) {
|
||||
int i;
|
||||
sais_index_type pidx;
|
||||
if((T == NULL) || (U == NULL) || (A == NULL) || (n < 0) || (k <= 0)) { return -1; }
|
||||
if(n <= 1) { if(n == 1) { U[0] = T[0]; } return n; }
|
||||
pidx = sais_main(T, A, 0, n, k, sizeof(int), 1);
|
||||
if(pidx < 0) { return pidx; }
|
||||
U[0] = T[n - 1];
|
||||
for(i = 0; i < pidx; ++i) { U[i + 1] = A[i]; }
|
||||
for(i += 1; i < n; ++i) { U[i] = A[i]; }
|
||||
pidx += 1;
|
||||
return pidx;
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* sais.h for sais-lite
|
||||
* Copyright (c) 2008-2010 Yuta Mori All Rights Reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person
|
||||
* obtaining a copy of this software and associated documentation
|
||||
* files (the "Software"), to deal in the Software without
|
||||
* restriction, including without limitation the rights to use,
|
||||
* copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following
|
||||
* conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
* OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef _SAIS_H
|
||||
#define _SAIS_H 1
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#define sais_index_type off_t
|
||||
|
||||
/* find the suffix array SA of T[0..n-1]
|
||||
use a working space (excluding T and SA) of at most 2n+O(lg n) */
|
||||
sais_index_type
|
||||
sais(const unsigned char *T, sais_index_type *SA, int n);
|
||||
|
||||
/* find the suffix array SA of T[0..n-1] in {0..k-1}^n
|
||||
use a working space (excluding T and SA) of at most MAX(4k,2n) */
|
||||
sais_index_type
|
||||
sais_int(const int *T, sais_index_type *SA, int n, int k);
|
||||
|
||||
/* burrows-wheeler transform */
|
||||
sais_index_type
|
||||
sais_bwt(const unsigned char *T, unsigned char *U, sais_index_type *A, int n);
|
||||
sais_index_type
|
||||
sais_int_bwt(const sais_index_type *T, sais_index_type *U, sais_index_type *A, int n, int k);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* _SAIS_H */
|
||||