mirror of
https://github.com/sparkle-project/Sparkle
synced 2026-11-24 04:38:16 +00:00
Merge pull request #1018 from sparkle-project/filesystemnormalization
fileSystemRepresentation normalization
This commit is contained in:
commit
313352fe26
7 files changed
+37
-41
No files matched your search
Vendored
+3
-3
@@ -39,7 +39,7 @@ BOOL applyBinaryDelta(NSString *source, NSString *destination, NSString *patchFi
|
||||
}
|
||||
|
||||
SUBinaryDeltaMajorVersion majorDiffVersion = FIRST_DELTA_DIFF_MAJOR_VERSION;
|
||||
SUBinaryDeltaMinorVersion minorDiffVersion = FIRST_DELTA_DIFF_MINOR_VERSION;
|
||||
int minorDiffVersion = 0;
|
||||
|
||||
NSString *expectedBeforeHashv1 = nil;
|
||||
NSString *expectedAfterHashv1 = nil;
|
||||
@@ -62,8 +62,8 @@ BOOL applyBinaryDelta(NSString *source, NSString *destination, NSString *patchFi
|
||||
// available in version 2.0 or later
|
||||
xar_subdoc_prop_get(subdoc, MINOR_DIFF_VERSION_KEY, &value);
|
||||
if (value)
|
||||
minorDiffVersion = (SUBinaryDeltaMinorVersion)[@(value) intValue];
|
||||
|
||||
minorDiffVersion = [@(value) intValue];
|
||||
|
||||
// available in version 2.0 or later
|
||||
xar_subdoc_prop_get(subdoc, BEFORE_TREE_SHA1_KEY, &value);
|
||||
if (value)
|
||||
|
||||
Vendored
+1
-10
@@ -57,16 +57,7 @@ typedef NS_ENUM(uint16_t, SUBinaryDeltaMajorVersion)
|
||||
SUBeigeMajorVersion = 2
|
||||
};
|
||||
|
||||
// Only keep track of the latest minor version for each major version
|
||||
typedef NS_ENUM(uint16_t, SUBinaryDeltaMinorVersion)
|
||||
{
|
||||
SUAzureMinorVersion = 1,
|
||||
SUBeigeMinorVersion = 1,
|
||||
};
|
||||
|
||||
#define FIRST_DELTA_DIFF_MAJOR_VERSION SUAzureMajorVersion
|
||||
#define FIRST_DELTA_DIFF_MINOR_VERSION ((SUBinaryDeltaMinorVersion)0)
|
||||
|
||||
#define LATEST_DELTA_DIFF_MAJOR_VERSION SUBeigeMajorVersion
|
||||
|
||||
extern int compareFiles(const FTSENT **a, const FTSENT **b);
|
||||
@@ -80,5 +71,5 @@ extern NSString *pathRelativeToDirectory(NSString *directory, NSString *path);
|
||||
NSString *temporaryFilename(NSString *base);
|
||||
NSString *temporaryDirectory(NSString *base);
|
||||
NSString *stringWithFileSystemRepresentation(const char*);
|
||||
SUBinaryDeltaMinorVersion latestMinorVersionForMajorVersion(SUBinaryDeltaMajorVersion majorVersion);
|
||||
int latestMinorVersionForMajorVersion(SUBinaryDeltaMajorVersion majorVersion);
|
||||
#endif
|
||||
Vendored
+9
-6
@@ -39,15 +39,15 @@ NSString *stringWithFileSystemRepresentation(const char *input) {
|
||||
return [[NSFileManager defaultManager] stringWithFileSystemRepresentation:input length:strlen(input)];
|
||||
}
|
||||
|
||||
SUBinaryDeltaMinorVersion latestMinorVersionForMajorVersion(SUBinaryDeltaMajorVersion majorVersion)
|
||||
int latestMinorVersionForMajorVersion(SUBinaryDeltaMajorVersion majorVersion)
|
||||
{
|
||||
switch (majorVersion) {
|
||||
case SUAzureMajorVersion:
|
||||
return SUAzureMinorVersion;
|
||||
return 1;
|
||||
case SUBeigeMajorVersion:
|
||||
return SUBeigeMinorVersion;
|
||||
return 2;
|
||||
}
|
||||
return (SUBinaryDeltaMinorVersion)0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
NSString *temporaryFilename(NSString *base)
|
||||
@@ -163,6 +163,9 @@ NSString *hashOfTreeWithVersion(NSString *path, uint16_t majorVersion)
|
||||
CC_SHA1_CTX hashContext;
|
||||
CC_SHA1_Init(&hashContext);
|
||||
|
||||
// Ensure the path uses filesystem-specific Unicode normalization #1017
|
||||
NSString *normalizedPath = stringWithFileSystemRepresentation(pathBuffer);
|
||||
|
||||
FTSENT *ent = 0;
|
||||
while ((ent = fts_read(fts))) {
|
||||
if (ent->fts_info != FTS_F && ent->fts_info != FTS_SL && ent->fts_info != FTS_D)
|
||||
@@ -171,8 +174,8 @@ NSString *hashOfTreeWithVersion(NSString *path, uint16_t majorVersion)
|
||||
if (ent->fts_info == FTS_D && !MAJOR_VERSION_IS_AT_LEAST(majorVersion, SUBeigeMajorVersion)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
NSString *relativePath = pathRelativeToDirectory(path, stringWithFileSystemRepresentation(ent->fts_path));
|
||||
|
||||
NSString *relativePath = pathRelativeToDirectory(normalizedPath, stringWithFileSystemRepresentation(ent->fts_path));
|
||||
if (relativePath.length == 0)
|
||||
continue;
|
||||
|
||||
|
||||
Vendored
+3
-3
@@ -230,9 +230,9 @@ BOOL createBinaryDelta(NSString *source, NSString *destination, NSString *patchF
|
||||
assert(destination);
|
||||
assert(patchFile);
|
||||
assert(majorVersion >= FIRST_DELTA_DIFF_MAJOR_VERSION && majorVersion <= LATEST_DELTA_DIFF_MAJOR_VERSION);
|
||||
|
||||
SUBinaryDeltaMinorVersion minorVersion = latestMinorVersionForMajorVersion(majorVersion);
|
||||
|
||||
|
||||
int minorVersion = latestMinorVersionForMajorVersion(majorVersion);
|
||||
|
||||
NSMutableDictionary *originalTreeState = [NSMutableDictionary dictionary];
|
||||
|
||||
char pathBuffer[PATH_MAX] = {0};
|
||||
|
||||
Vendored
+4
-4
@@ -188,10 +188,10 @@ static BOOL runVersionCommand(NSString *programName, NSArray *args)
|
||||
fprintf(stderr, "Unable to open patch %s\n", [patchFile fileSystemRepresentation]);
|
||||
return NO;
|
||||
}
|
||||
|
||||
|
||||
SUBinaryDeltaMajorVersion majorDiffVersion = FIRST_DELTA_DIFF_MAJOR_VERSION;
|
||||
SUBinaryDeltaMinorVersion minorDiffVersion = FIRST_DELTA_DIFF_MINOR_VERSION;
|
||||
|
||||
int minorDiffVersion = 0;
|
||||
|
||||
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)) {
|
||||
@@ -205,7 +205,7 @@ static BOOL runVersionCommand(NSString *programName, NSArray *args)
|
||||
// available in version 2.0 or later
|
||||
xar_subdoc_prop_get(subdoc, MINOR_DIFF_VERSION_KEY, &value);
|
||||
if (value)
|
||||
minorDiffVersion = (SUBinaryDeltaMinorVersion)[@(value) intValue];
|
||||
minorDiffVersion = [@(value) intValue];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Vendored
+4
-2
@@ -154,8 +154,10 @@
|
||||
assert(bundle != nil);
|
||||
|
||||
NSString *normalizedAppPath = [[[bundle bundlePath] stringByDeletingLastPathComponent] stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.%@", [host objectForInfoDictionaryKey:(__bridge NSString *)kCFBundleNameKey], [[bundle bundlePath] pathExtension]]];
|
||||
|
||||
return normalizedAppPath;
|
||||
|
||||
// Roundtrip string through fileSystemRepresentation to ensure it uses filesystem's Unicode normalization
|
||||
// rather than arbitrary Unicode form from Info.plist - #1017
|
||||
return [NSString stringWithUTF8String:[normalizedAppPath fileSystemRepresentation]];
|
||||
}
|
||||
|
||||
@end
|
||||
+13
-13
@@ -24,8 +24,8 @@ typedef void (^SUDeltaHandler)(NSFileManager *fileManager, NSString *sourceDirec
|
||||
|
||||
- (void)testTemporaryDirectory
|
||||
{
|
||||
NSString *tmp1 = temporaryDirectory(@"Sparkle");
|
||||
NSString *tmp2 = temporaryDirectory(@"Sparkle");
|
||||
NSString *tmp1 = temporaryDirectory(@"Sparklęエンジン");
|
||||
NSString *tmp2 = temporaryDirectory(@"Sparklęエンジン");
|
||||
NSLog(@"Temporary directories: %@, %@", tmp1, tmp2);
|
||||
XCTAssertNotEqualObjects(tmp1, tmp2);
|
||||
XCTAssert(YES, @"Pass");
|
||||
@@ -33,8 +33,8 @@ typedef void (^SUDeltaHandler)(NSFileManager *fileManager, NSString *sourceDirec
|
||||
|
||||
- (void)testTemporaryFile
|
||||
{
|
||||
NSString *tmp1 = temporaryFilename(@"Sparkle");
|
||||
NSString *tmp2 = temporaryFilename(@"Sparkle");
|
||||
NSString *tmp1 = temporaryFilename(@"Sparklęエンジン");
|
||||
NSString *tmp2 = temporaryFilename(@"Sparklęエンジン");
|
||||
NSLog(@"Temporary files: %@, %@", tmp1, tmp2);
|
||||
XCTAssertNotEqualObjects(tmp1, tmp2);
|
||||
XCTAssert(YES, @"Pass");
|
||||
@@ -42,12 +42,12 @@ typedef void (^SUDeltaHandler)(NSFileManager *fileManager, NSString *sourceDirec
|
||||
|
||||
- (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");
|
||||
|
||||
NSString *sourceDirectory = temporaryDirectory(@"Spąrkle_temp1エンジン");
|
||||
NSString *destinationDirectory = temporaryDirectory(@"Spąrkle_temp2エンジン");
|
||||
|
||||
NSString *diffFile = temporaryFilename(@"Spąrkle_diffエンジン");
|
||||
NSString *patchDirectory = temporaryDirectory(@"Spąrkle_patchエンジン");
|
||||
|
||||
XCTAssertNotNil(sourceDirectory);
|
||||
XCTAssertNotNil(destinationDirectory);
|
||||
XCTAssertNotNil(diffFile);
|
||||
@@ -120,9 +120,9 @@ typedef void (^SUDeltaHandler)(NSFileManager *fileManager, NSString *sourceDirec
|
||||
{
|
||||
[self createAndApplyPatchWithHandler:^(NSFileManager *__unused fileManager, NSString *sourceDirectory, NSString *destinationDirectory) {
|
||||
NSData *emptyData = [NSData data];
|
||||
NSString *sourceFile = [sourceDirectory stringByAppendingPathComponent:@"A"];
|
||||
NSString *destinationFile = [destinationDirectory stringByAppendingPathComponent:@"A"];
|
||||
|
||||
NSString *sourceFile = [sourceDirectory stringByAppendingPathComponent:@"AĄエンジン"];
|
||||
NSString *destinationFile = [destinationDirectory stringByAppendingPathComponent:@"AĄエンジン"];
|
||||
|
||||
XCTAssertTrue([emptyData writeToFile:sourceFile atomically:YES]);
|
||||
XCTAssertTrue([emptyData writeToFile:destinationFile atomically:YES]);
|
||||
|
||||
|
||||
Reference in new issue
Block a user