From 11f195f7c33f4bf46970f5606156da09c865e01d Mon Sep 17 00:00:00 2001 From: Garrett Moon Date: Wed, 28 Jun 2017 16:36:43 -0700 Subject: [PATCH] Updates latest Carthage checkouts --- Cartfile.resolved | 2 +- .../PINCache/.buildkite/pipeline.yml | 4 - Carthage/Checkouts/PINCache/CHANGELOG.md | 43 +++-- Carthage/Checkouts/PINCache/CI/build.sh | 4 + .../PINCache/CI/exclude-from-build.json | 5 + .../xcschemes/PINOperation-macOS.xcscheme | 2 +- .../xcschemes/PINOperation-tvOS.xcscheme | 2 +- .../xcschemes/PINOperation.xcscheme | 2 +- Carthage/Checkouts/PINCache/Dangerfile | 23 +++ Carthage/Checkouts/PINCache/Gemfile | 4 + Carthage/Checkouts/PINCache/PINCache.podspec | 2 +- .../PINCache.xcodeproj/project.pbxproj | 10 +- .../xcschemes/PINCache-macOS.xcscheme | 2 +- .../xcschemes/PINCache-tvOS.xcscheme | 2 +- .../xcshareddata/xcschemes/PINCache.xcscheme | 2 +- Carthage/Checkouts/PINCache/README.md | 33 +++- Carthage/Checkouts/PINCache/Source/PINCache.h | 41 +++-- Carthage/Checkouts/PINCache/Source/PINCache.m | 27 ++- .../Checkouts/PINCache/Source/PINDiskCache.h | 60 +++---- .../Checkouts/PINCache/Source/PINDiskCache.m | 161 ++++++++++-------- .../Checkouts/PINCache/Tests/PINCacheTests.m | 50 +++--- .../PINCache/run_tests_update_status.sh | 38 ----- 22 files changed, 302 insertions(+), 217 deletions(-) delete mode 100644 Carthage/Checkouts/PINCache/.buildkite/pipeline.yml create mode 100755 Carthage/Checkouts/PINCache/CI/build.sh create mode 100644 Carthage/Checkouts/PINCache/CI/exclude-from-build.json create mode 100644 Carthage/Checkouts/PINCache/Dangerfile create mode 100644 Carthage/Checkouts/PINCache/Gemfile delete mode 100755 Carthage/Checkouts/PINCache/run_tests_update_status.sh diff --git a/Cartfile.resolved b/Cartfile.resolved index c2fedfc5..9eed4784 100644 --- a/Cartfile.resolved +++ b/Cartfile.resolved @@ -1,3 +1,3 @@ github "pinterest/PINOperation" "1.0.3" git "https://chromium.googlesource.com/webm/libwebp" "v0.5.1" -github "pinterest/PINCache" "3.0.1-beta.4" +github "pinterest/PINCache" "3.0.1-beta.5" diff --git a/Carthage/Checkouts/PINCache/.buildkite/pipeline.yml b/Carthage/Checkouts/PINCache/.buildkite/pipeline.yml deleted file mode 100644 index 6a5259ec..00000000 --- a/Carthage/Checkouts/PINCache/.buildkite/pipeline.yml +++ /dev/null @@ -1,4 +0,0 @@ -steps: - - label: 'Tests' - command: "./run_tests_update_status.sh \"${UPDATE_STATUS_PATH}\" \"${BUILDKITE_PULL_REQUEST}\" \"${BUILDKITE_BUILD_URL}\"" - timeout_in_minutes: 30 \ No newline at end of file diff --git a/Carthage/Checkouts/PINCache/CHANGELOG.md b/Carthage/Checkouts/PINCache/CHANGELOG.md index ca4fa9b4..2356eb8e 100644 --- a/Carthage/Checkouts/PINCache/CHANGELOG.md +++ b/Carthage/Checkouts/PINCache/CHANGELOG.md @@ -1,63 +1,70 @@ -### 2.2.1 -- 2016 Mar 5 ### +## master + +* Add your own contributions to the next release on the line below this with your name. + +## 3.0.1 -- Beta 5 +- [new] Added an ability to set custom encoder/decoder for file names: [#192](https://github.com/pinterest/PINCache/pull/192) + +## 2.2.1 -- 2016 Mar 5 - [new] Removed need for extension macro: [#72](https://github.com/pinterest/PINCache/pull/72) -### 2.2.1 -- 2016 Feb 15 ### +## 2.2.1 -- 2016 Feb 15 - [fixed] When ttlCache is enabled, skip updating the file modification time when accessing `fileURLForKey:` [#70](https://github.com/pinterest/PINCache/pull/70) -### 2.2 -- 2016 Feb 10 ### +## 2.2 -- 2016 Feb 10 - [new] Allow caches to behave like a TTLCache [#66](https://github.com/pinterest/PINCache/pull/66) -### 2.1.2 -- 2015 Nov 19 ### +## 2.1.2 -- 2015 Nov 19 - [fix] Fix disk caching bug due to incorrect string encoding [#42](https://github.com/pinterest/PINCache/pull/42) -### 2.1.1 -- 2015 Nov 17 ### +## 2.1.1 -- 2015 Nov 17 - [new] Added `tvOS` support - [fixed] PINDiskCache byteCount tracking bug [#30](https://github.com/pinterest/PINCache/pull/30) -### 2.1 -- 2015 Aug 24 ### +## 2.1 -- 2015 Aug 24 - [new] Xcode 7 support - [fixed] Invalid task ID's used for expiration handler on background tasks [#13](https://github.com/pinterest/PINCache/issues/13) - [fixed] Support for OS X since UIBackgroundTask is only on iOS [#19](https://github.com/pinterest/PINCache/pull/19) -### 2.0.1 -- 2015 May 1 ### +## 2.0.1 -- 2015 May 1 - [new] Added support for using PINCache in extensions - [new] Adopting nullability annotations. -### 2.0 -- 2015 February 25 ### +## 2.0 -- 2015 February 25 - [fix] PINCache redesign to avoid deadlocks -### 1.2.3 -- 2014 December 13 ### +## 1.2.3 -- 2014 December 13 - [fix] TMDiskCache/TMMemoryCache: import `UIKit` to facilitate Swift usage (thanks [digabriel](https://github.com/tumblr/TMCache/pull/57)!) - [fix] TMDiskCache: add try catch to ensure an exception isn’t thrown if a file on disk is unable to be unarchived (thanks [leonskywalker](https://github.com/tumblr/TMCache/pull/62)!) - [fix] TMDiskCache: create trash directory asynchronously to avoid race condition (thanks [napoapo77](https://github.com/tumblr/TMCache/pull/68)!) -### 1.2.2 -- 2014 October 6 ### +## 1.2.2 -- 2014 October 6 - [new] Remove deprecated `documentation` property from Podspec -### 1.2.1 -- 2013 July 28 ### +## 1.2.1 -- 2013 July 28 - [new] TMDiskCache: introduced concept of "trash" for rapid wipeouts - [new] TMDiskCache: `nil` checks to prevent crashes - [new] TMCache/TMDiskCache/TMMemoryCache: import Foundation to facilitate Swift usage -### 1.2.0 -- 2013 May 24 ### +## 1.2.0 -- 2013 May 24 - [new] TMDiskCache: added method `enumerateObjectsWithBlock:completionBlock:` - [new] TMDiskCache: added method `enumerateObjectsWithBlock:` @@ -72,31 +79,31 @@ - [del] TMCache: removed `cost` methods pending a solution for disk-based cost -### 1.1.2 -- 2013 May 13 ### +## 1.1.2 -- 2013 May 13 - [fix] TMCache: prevent `objectForKey:block:` from hitting the thread ceiling - [new] TMCache: added a test to make sure we don't deadlock the queue -### 1.1.1 -- 2013 May 1 ### +## 1.1.1 -- 2013 May 1 - [fix] simplified appledoc arguments in podspec, updated doc script -### 1.1.0 -- 2013 April 29 ### +## 1.1.0 -- 2013 April 29 - [new] TMCache: added method `setObject:forKey:withCost:` - [new] TMCache: documentation -### 1.0.3 -- 2013 April 27 ### +## 1.0.3 -- 2013 April 27 - [new] TMCache: added property `diskByteCount` (for convenience) - [new] TMMemoryCache: `totalCost` now returned synchronously from queue - [fix] TMMemoryCache: `totalCost` set to zero immediately after `removeAllObjects:` -### 1.0.2 -- 2013 April 26 ### +## 1.0.2 -- 2013 April 26 - [fix] TMCache: cache hits from memory will now update access time on disk - [fix] TMDiskCache: set & remove methods now acquire a `UIBackgroundTaskIdentifier` @@ -110,7 +117,7 @@ - [new] TMCache: added unit tests -### 1.0.1 -- 2013 April 23 ### +## 1.0.1 -- 2013 April 23 - added an optional "cost limit" to `TMMemoryCache`, including new properties and methods - calling `[TMDiskCache trimToDate:]` with `[NSDate distantPast]` will now clear the cache diff --git a/Carthage/Checkouts/PINCache/CI/build.sh b/Carthage/Checkouts/PINCache/CI/build.sh new file mode 100755 index 00000000..bbdb8f94 --- /dev/null +++ b/Carthage/Checkouts/PINCache/CI/build.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -eo pipefail + +make all \ No newline at end of file diff --git a/Carthage/Checkouts/PINCache/CI/exclude-from-build.json b/Carthage/Checkouts/PINCache/CI/exclude-from-build.json new file mode 100644 index 00000000..abc6f913 --- /dev/null +++ b/Carthage/Checkouts/PINCache/CI/exclude-from-build.json @@ -0,0 +1,5 @@ +[ + "^plans/", + "^docs/", + "^CI/exclude-from-build.json$" +] \ No newline at end of file diff --git a/Carthage/Checkouts/PINCache/Carthage/Checkouts/PINOperation/PINOperation.xcodeproj/xcshareddata/xcschemes/PINOperation-macOS.xcscheme b/Carthage/Checkouts/PINCache/Carthage/Checkouts/PINOperation/PINOperation.xcodeproj/xcshareddata/xcschemes/PINOperation-macOS.xcscheme index 98d66979..93570c21 100644 --- a/Carthage/Checkouts/PINCache/Carthage/Checkouts/PINOperation/PINOperation.xcodeproj/xcshareddata/xcschemes/PINOperation-macOS.xcscheme +++ b/Carthage/Checkouts/PINCache/Carthage/Checkouts/PINOperation/PINOperation.xcodeproj/xcshareddata/xcschemes/PINOperation-macOS.xcscheme @@ -1,6 +1,6 @@ 500 + +# Changelog entries are required for changes to source files. +no_changelog_entry = !git.modified_files.include?("CHANGELOG.md") +if has_changes_in_source_directory && no_changelog_entry && !declared_trivial + warn("Any source code changes should have an entry in CHANGELOG.md or have #trivial in their title.") +end diff --git a/Carthage/Checkouts/PINCache/Gemfile b/Carthage/Checkouts/PINCache/Gemfile new file mode 100644 index 00000000..38bfbc8e --- /dev/null +++ b/Carthage/Checkouts/PINCache/Gemfile @@ -0,0 +1,4 @@ +source 'https://rubygems.org' + +gem 'danger' +gem 'danger-slack' \ No newline at end of file diff --git a/Carthage/Checkouts/PINCache/PINCache.podspec b/Carthage/Checkouts/PINCache/PINCache.podspec index d0420c86..0465a572 100644 --- a/Carthage/Checkouts/PINCache/PINCache.podspec +++ b/Carthage/Checkouts/PINCache/PINCache.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'PINCache' - s.version = '3.0.1-beta.3' + s.version = '3.0.1-beta.5' s.homepage = 'https://github.com/pinterest/PINCache' s.summary = 'Fast, thread safe, parallel object cache for iOS and OS X.' s.authors = { 'Garrett Moon' => 'garrett@pinterest.com', 'Justin Ouellette' => 'jstn@tumblr.com' } diff --git a/Carthage/Checkouts/PINCache/PINCache.xcodeproj/project.pbxproj b/Carthage/Checkouts/PINCache/PINCache.xcodeproj/project.pbxproj index 69941ed6..dd17468d 100644 --- a/Carthage/Checkouts/PINCache/PINCache.xcodeproj/project.pbxproj +++ b/Carthage/Checkouts/PINCache/PINCache.xcodeproj/project.pbxproj @@ -492,7 +492,7 @@ CC0105A81E271A1600890935 /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 0730; + LastUpgradeCheck = 0820; ORGANIZATIONNAME = Pinterest; TargetAttributes = { CC0105B01E271A1600890935 = { @@ -741,8 +741,10 @@ CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; @@ -790,8 +792,10 @@ CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; @@ -823,6 +827,7 @@ isa = XCBuildConfiguration; buildSettings = { APPLICATION_EXTENSION_API_ONLY = YES; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = ""; DEFINES_MODULE = YES; DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; @@ -844,6 +849,7 @@ isa = XCBuildConfiguration; buildSettings = { APPLICATION_EXTENSION_API_ONLY = YES; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = ""; DEFINES_MODULE = YES; DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; @@ -865,6 +871,7 @@ isa = XCBuildConfiguration; buildSettings = { APPLICATION_EXTENSION_API_ONLY = YES; + "CODE_SIGN_IDENTITY[sdk=appletvos*]" = ""; DEFINES_MODULE = YES; DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; @@ -889,6 +896,7 @@ isa = XCBuildConfiguration; buildSettings = { APPLICATION_EXTENSION_API_ONLY = YES; + "CODE_SIGN_IDENTITY[sdk=appletvos*]" = ""; DEFINES_MODULE = YES; DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; diff --git a/Carthage/Checkouts/PINCache/PINCache.xcodeproj/xcshareddata/xcschemes/PINCache-macOS.xcscheme b/Carthage/Checkouts/PINCache/PINCache.xcodeproj/xcshareddata/xcschemes/PINCache-macOS.xcscheme index 657519a6..93f403a8 100644 --- a/Carthage/Checkouts/PINCache/PINCache.xcodeproj/xcshareddata/xcschemes/PINCache-macOS.xcscheme +++ b/Carthage/Checkouts/PINCache/PINCache.xcodeproj/xcshareddata/xcschemes/PINCache-macOS.xcscheme @@ -1,6 +1,6 @@ . + Multiple instances with the same name are *not* allowed and can *not* safely + access the same data on disk. Also used to create the . @see name @param name The name of the cache. @@ -75,31 +75,38 @@ PIN_SUBCLASSING_RESTRICTED - (instancetype)initWithName:(nonnull NSString *)name; /** - Multiple instances with the same name are allowed and can safely access - the same data on disk thanks to the magic of seriality. Also used to create the . + Multiple instances with the same name are *not* allowed and can *not* safely + access the same data on disk. Also used to create the . @see name @param name The name of the cache. - @param fileExtension The file extension for files on disk. + @param rootPath The path of the cache on disk. @result A new cache with the specified name. */ -- (instancetype)initWithName:(nonnull NSString *)name fileExtension:(nullable NSString *)fileExtension; +- (instancetype)initWithName:(nonnull NSString *)name rootPath:(nonnull NSString *)rootPath; /** - Multiple instances with the same name are allowed and can safely access - the same data on disk thanks to the magic of seriality. Also used to create the . + Multiple instances with the same name are *not* allowed and can *not* safely + access the same data on disk.. Also used to create the . + Initializer allows you to override default NSKeyedArchiver/NSKeyedUnarchiver serialization for . + You must provide both serializer and deserializer, or opt-out to default implementation providing nil values. @see name @param name The name of the cache. @param rootPath The path of the cache on disk. - @param fileExtension The file extension for files on disk. + @param serializer A block used to serialize object before writing to disk. If nil provided, default NSKeyedArchiver serialized will be used. + @param deserializer A block used to deserialize object read from disk. If nil provided, default NSKeyedUnarchiver serialized will be used. @result A new cache with the specified name. */ -- (instancetype)initWithName:(nonnull NSString *)name rootPath:(nonnull NSString *)rootPath fileExtension:(nullable NSString *)fileExtension; +- (instancetype)initWithName:(NSString *)name + rootPath:(NSString *)rootPath + serializer:(nullable PINDiskCacheSerializerBlock)serializer + deserializer:(nullable PINDiskCacheDeserializerBlock)deserializer; + /** - Multiple instances with the same name are allowed and can safely access - the same data on disk thanks to the magic of seriality. Also used to create the . + Multiple instances with the same name are *not* allowed and can *not* safely + access the same data on disk. Also used to create the . Initializer allows you to override default NSKeyedArchiver/NSKeyedUnarchiver serialization for . You must provide both serializer and deserializer, or opt-out to default implementation providing nil values. @@ -108,10 +115,16 @@ PIN_SUBCLASSING_RESTRICTED @param rootPath The path of the cache on disk. @param serializer A block used to serialize object before writing to disk. If nil provided, default NSKeyedArchiver serialized will be used. @param deserializer A block used to deserialize object read from disk. If nil provided, default NSKeyedUnarchiver serialized will be used. - @param fileExtension The file extension for files on disk. + @param keyEncoder A block used to encode key(filename). If nil provided, default url encoder will be used + @param keyDecoder A block used to decode key(filename). If nil provided, default url decoder will be used @result A new cache with the specified name. */ -- (instancetype)initWithName:(nonnull NSString *)name rootPath:(nonnull NSString *)rootPath serializer:(nullable PINDiskCacheSerializerBlock)serializer deserializer:(nullable PINDiskCacheDeserializerBlock)deserializer fileExtension:(nullable NSString *)fileExtension NS_DESIGNATED_INITIALIZER; +- (instancetype)initWithName:(nonnull NSString *)name + rootPath:(nonnull NSString *)rootPath + serializer:(nullable PINDiskCacheSerializerBlock)serializer + deserializer:(nullable PINDiskCacheDeserializerBlock)deserializer + keyEncoder:(nullable PINDiskCacheKeyEncoderBlock)keyEncoder + keyDecoder:(nullable PINDiskCacheKeyDecoderBlock)keyDecoder NS_DESIGNATED_INITIALIZER; @end diff --git a/Carthage/Checkouts/PINCache/Source/PINCache.m b/Carthage/Checkouts/PINCache/Source/PINCache.m index 9fddc413..1b0f2cc0 100644 --- a/Carthage/Checkouts/PINCache/Source/PINCache.m +++ b/Carthage/Checkouts/PINCache/Source/PINCache.m @@ -26,20 +26,24 @@ - (instancetype)init - (instancetype)initWithName:(NSString *)name { - return [self initWithName:name fileExtension:nil]; + return [self initWithName:name rootPath:[NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) firstObject]]; } -- (instancetype)initWithName:(NSString *)name fileExtension:(NSString *)fileExtension +- (instancetype)initWithName:(NSString *)name rootPath:(NSString *)rootPath { - return [self initWithName:name rootPath:[NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) firstObject] fileExtension:fileExtension]; + return [self initWithName:name rootPath:rootPath serializer:nil deserializer:nil]; } -- (instancetype)initWithName:(NSString *)name rootPath:(NSString *)rootPath fileExtension:(NSString *)fileExtension -{ - return [self initWithName:name rootPath:rootPath serializer:nil deserializer:nil fileExtension:fileExtension]; +- (instancetype)initWithName:(NSString *)name rootPath:(NSString *)rootPath serializer:(PINDiskCacheSerializerBlock)serializer deserializer:(PINDiskCacheDeserializerBlock)deserializer { + return [self initWithName:name rootPath:rootPath serializer:serializer deserializer:deserializer keyEncoder:nil keyDecoder:nil]; } -- (instancetype)initWithName:(NSString *)name rootPath:(NSString *)rootPath serializer:(PINDiskCacheSerializerBlock)serializer deserializer:(PINDiskCacheDeserializerBlock)deserializer fileExtension:(NSString *)fileExtension +- (instancetype)initWithName:(NSString *)name + rootPath:(NSString *)rootPath + serializer:(PINDiskCacheSerializerBlock)serializer + deserializer:(PINDiskCacheDeserializerBlock)deserializer + keyEncoder:(PINDiskCacheKeyEncoderBlock)keyEncoder + keyDecoder:(PINDiskCacheKeyDecoderBlock)keyDecoder { if (!name) return nil; @@ -49,7 +53,14 @@ - (instancetype)initWithName:(NSString *)name rootPath:(NSString *)rootPath seri //10 may actually be a bit high, but currently much of our threads are blocked on empyting the trash. Until we can resolve that, lets bump this up. _operationQueue = [[PINOperationQueue alloc] initWithMaxConcurrentOperations:10]; - _diskCache = [[PINDiskCache alloc] initWithName:_name prefix:PINDiskCachePrefix rootPath:rootPath serializer:serializer deserializer:deserializer fileExtension:fileExtension operationQueue:_operationQueue]; + _diskCache = [[PINDiskCache alloc] initWithName:_name + prefix:PINDiskCachePrefix + rootPath:rootPath + serializer:serializer + deserializer:deserializer + keyEncoder:nil + keyDecoder:nil + operationQueue:_operationQueue]; _memoryCache = [[PINMemoryCache alloc] initWithOperationQueue:_operationQueue]; } return self; diff --git a/Carthage/Checkouts/PINCache/Source/PINDiskCache.h b/Carthage/Checkouts/PINCache/Source/PINDiskCache.h index ae56fac6..be0883a9 100644 --- a/Carthage/Checkouts/PINCache/Source/PINDiskCache.h +++ b/Carthage/Checkouts/PINCache/Source/PINDiskCache.h @@ -50,6 +50,24 @@ typedef NSData* _Nonnull(^PINDiskCacheSerializerBlock)(id object, NSSt */ typedef id _Nonnull(^PINDiskCacheDeserializerBlock)(NSData* data, NSString *key); +/** + * A block used to encode keys + * + * @param decodedKey Original/decoded key + * + * @return encoded key + */ +typedef NSString *_Nonnull(^PINDiskCacheKeyEncoderBlock)(NSString *decodedKey); + +/** + * A block used to decode keys + * + * @param encodedKey An encoded key + * + * @return decoded key + */ +typedef NSString *_Nonnull(^PINDiskCacheKeyDecoderBlock)(NSString *encodedKey); + /** `PINDiskCache` is a thread safe key/value store backed by the file system. It accepts any object conforming @@ -136,11 +154,6 @@ PIN_SUBCLASSING_RESTRICTED */ @property (assign) NSTimeInterval ageLimit; -/** - Extension for all cache files on disk. Defaults to no extension. - */ -@property (nullable, readonly) NSString * fileExtension; - /** The writing protection option used when writing a file on disk. This value is used every time an object is set. NSDataWritingAtomic and NSDataWritingWithoutOverwriting are ignored if set @@ -227,17 +240,6 @@ PIN_SUBCLASSING_RESTRICTED */ - (instancetype)initWithName:(nonnull NSString *)name; -/** - Multiple instances with the same name are allowed and can safely access - the same data on disk thanks to the magic of seriality. - - @see name - @param name The name of the cache. - @param fileExtension The file extension for files on disk. - @result A new cache with the specified name. - */ -- (instancetype)initWithName:(nonnull NSString *)name fileExtension:(nullable NSString *)fileExtension; - /** Multiple instances with the same name are allowed and can safely access the same data on disk thanks to the magic of seriality. @@ -245,10 +247,9 @@ PIN_SUBCLASSING_RESTRICTED @see name @param name The name of the cache. @param rootPath The path of the cache. - @param fileExtension The file extension for files on disk. @result A new cache with the specified name. */ -- (instancetype)initWithName:(nonnull NSString *)name rootPath:(nonnull NSString *)rootPath fileExtension:(nullable NSString *)fileExtension; +- (instancetype)initWithName:(nonnull NSString *)name rootPath:(nonnull NSString *)rootPath; /** @see name @@ -256,10 +257,9 @@ PIN_SUBCLASSING_RESTRICTED @param rootPath The path of the cache. @param serializer A block used to serialize object. If nil provided, default NSKeyedArchiver serialized will be used. @param deserializer A block used to deserialize object. If nil provided, default NSKeyedUnarchiver serialized will be used. - @param fileExtension The file extension for files on disk. @result A new cache with the specified name. */ -- (instancetype)initWithName:(nonnull NSString *)name rootPath:(nonnull NSString *)rootPath serializer:(nullable PINDiskCacheSerializerBlock)serializer deserializer:(nullable PINDiskCacheDeserializerBlock)deserializer fileExtension:(nullable NSString *)fileExtension; +- (instancetype)initWithName:(nonnull NSString *)name rootPath:(nonnull NSString *)rootPath serializer:(nullable PINDiskCacheSerializerBlock)serializer deserializer:(nullable PINDiskCacheDeserializerBlock)deserializer; /** The designated initializer allowing you to override default NSKeyedArchiver/NSKeyedUnarchiver serialization. @@ -269,11 +269,10 @@ PIN_SUBCLASSING_RESTRICTED @param rootPath The path of the cache. @param serializer A block used to serialize object. If nil provided, default NSKeyedArchiver serialized will be used. @param deserializer A block used to deserialize object. If nil provided, default NSKeyedUnarchiver serialized will be used. - @param fileExtension The file extension for files on disk. @param operationQueue A PINOperationQueue to run asynchronous operations @result A new cache with the specified name. */ -- (instancetype)initWithName:(nonnull NSString *)name rootPath:(nonnull NSString *)rootPath serializer:(nullable PINDiskCacheSerializerBlock)serializer deserializer:(nullable PINDiskCacheDeserializerBlock)deserializer fileExtension:(nullable NSString *)fileExtension operationQueue:(nonnull PINOperationQueue *)operationQueue __attribute__((deprecated)); +- (instancetype)initWithName:(nonnull NSString *)name rootPath:(nonnull NSString *)rootPath serializer:(nullable PINDiskCacheSerializerBlock)serializer deserializer:(nullable PINDiskCacheDeserializerBlock)deserializer operationQueue:(nonnull PINOperationQueue *)operationQueue __attribute__((deprecated)); /** The designated initializer allowing you to override default NSKeyedArchiver/NSKeyedUnarchiver serialization. @@ -284,11 +283,19 @@ PIN_SUBCLASSING_RESTRICTED @param rootPath The path of the cache. @param serializer A block used to serialize object. If nil provided, default NSKeyedArchiver serialized will be used. @param deserializer A block used to deserialize object. If nil provided, default NSKeyedUnarchiver serialized will be used. - @param fileExtension The file extension for files on disk. + @param keyEncoder A block used to encode key(filename). If nil provided, default url encoder will be used + @param keyDecoder A block used to decode key(filename). If nil provided, default url decoder will be used @param operationQueue A PINOperationQueue to run asynchronous operations @result A new cache with the specified name. */ -- (instancetype)initWithName:(nonnull NSString *)name prefix:(nonnull NSString *)prefix rootPath:(nonnull NSString *)rootPath serializer:(nullable PINDiskCacheSerializerBlock)serializer deserializer:(nullable PINDiskCacheDeserializerBlock)deserializer fileExtension:(nullable NSString *)fileExtension operationQueue:(nonnull PINOperationQueue *)operationQueue NS_DESIGNATED_INITIALIZER; +- (instancetype)initWithName:(nonnull NSString *)name + prefix:(nonnull NSString *)prefix + rootPath:(nonnull NSString *)rootPath + serializer:(nullable PINDiskCacheSerializerBlock)serializer + deserializer:(nullable PINDiskCacheDeserializerBlock)deserializer + keyEncoder:(nullable PINDiskCacheKeyEncoderBlock)keyEncoder + keyDecoder:(nullable PINDiskCacheKeyDecoderBlock)keyDecoder + operationQueue:(nonnull PINOperationQueue *)operationQueue NS_DESIGNATED_INITIALIZER; #pragma mark - Asynchronous Methods /// @name Asynchronous Methods @@ -485,11 +492,6 @@ PIN_SUBCLASSING_RESTRICTED */ typedef void (^PINDiskCacheBlock)(PINDiskCache *cache); -/** - A callback block which provides the cache, key and object as arguments - */ -typedef void (^PINDiskCacheObjectBlock)(PINDiskCache *cache, NSString *key, id _Nullable object); - @interface PINDiskCache (Deprecated) - (void)lockFileAccessWhileExecutingBlock:(nullable PINCacheBlock)block __attribute__((deprecated)); - (void)containsObjectForKey:(NSString *)key block:(PINDiskCacheContainsBlock)block __attribute__((deprecated)); diff --git a/Carthage/Checkouts/PINCache/Source/PINDiskCache.m b/Carthage/Checkouts/PINCache/Source/PINDiskCache.m index 467e9ae2..53f31833 100644 --- a/Carthage/Checkouts/PINCache/Source/PINDiskCache.m +++ b/Carthage/Checkouts/PINCache/Source/PINDiskCache.m @@ -43,6 +43,9 @@ @interface PINDiskCache () { PINDiskCacheSerializerBlock _serializer; PINDiskCacheDeserializerBlock _deserializer; + + PINDiskCacheKeyEncoderBlock _keyEncoder; + PINDiskCacheKeyDecoderBlock _keyDecoder; } @property (copy, nonatomic) NSString *name; @@ -81,24 +84,19 @@ - (instancetype)init - (instancetype)initWithName:(NSString *)name { - return [self initWithName:name fileExtension:nil]; + return [self initWithName:name rootPath:[NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) objectAtIndex:0]]; } -- (instancetype)initWithName:(NSString *)name fileExtension:(NSString *)fileExtension +- (instancetype)initWithName:(NSString *)name rootPath:(NSString *)rootPath { - return [self initWithName:name rootPath:[NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) objectAtIndex:0] fileExtension:fileExtension]; + return [self initWithName:name rootPath:rootPath serializer:nil deserializer:nil]; } -- (instancetype)initWithName:(NSString *)name rootPath:(NSString *)rootPath fileExtension:(NSString *)fileExtension -{ - return [self initWithName:name rootPath:rootPath serializer:nil deserializer:nil fileExtension:fileExtension]; -} - -- (instancetype)initWithName:(NSString *)name rootPath:(NSString *)rootPath serializer:(PINDiskCacheSerializerBlock)serializer deserializer:(PINDiskCacheDeserializerBlock)deserializer fileExtension:(NSString *)fileExtension +- (instancetype)initWithName:(NSString *)name rootPath:(NSString *)rootPath serializer:(PINDiskCacheSerializerBlock)serializer deserializer:(PINDiskCacheDeserializerBlock)deserializer { #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdeprecated-declarations" - return [self initWithName:name rootPath:rootPath serializer:serializer deserializer:deserializer fileExtension:fileExtension operationQueue:[PINOperationQueue sharedOperationQueue]]; + return [self initWithName:name rootPath:rootPath serializer:serializer deserializer:deserializer operationQueue:[PINOperationQueue sharedOperationQueue]]; #pragma clang diagnostic pop } @@ -106,10 +104,16 @@ - (instancetype)initWithName:(NSString *)name rootPath:(NSString *)rootPath serializer:(PINDiskCacheSerializerBlock)serializer deserializer:(PINDiskCacheDeserializerBlock)deserializer - fileExtension:(NSString *)fileExtension operationQueue:(PINOperationQueue *)operationQueue { - return [self initWithName:name prefix:PINDiskCachePrefix rootPath:rootPath serializer:serializer deserializer:deserializer fileExtension:fileExtension operationQueue:operationQueue]; + return [self initWithName:name + prefix:PINDiskCachePrefix + rootPath:rootPath + serializer:serializer + deserializer:deserializer + keyEncoder:nil + keyDecoder:nil + operationQueue:operationQueue]; } - (instancetype)initWithName:(NSString *)name @@ -117,22 +121,23 @@ - (instancetype)initWithName:(NSString *)name rootPath:(NSString *)rootPath serializer:(PINDiskCacheSerializerBlock)serializer deserializer:(PINDiskCacheDeserializerBlock)deserializer - fileExtension:(NSString *)fileExtension + keyEncoder:(PINDiskCacheKeyEncoderBlock)keyEncoder + keyDecoder:(PINDiskCacheKeyDecoderBlock)keyDecoder operationQueue:(PINOperationQueue *)operationQueue { if (!name) return nil; - if ((serializer && !deserializer) || - (!serializer && deserializer)){ - @throw [NSException exceptionWithName:@"Must initialize with a both serializer and deserializer" reason:@"PINDiskCache must be initialized with a serializer and deserializer." userInfo:nil]; - return nil; - } + + NSAssert(((!serializer && !deserializer) || (serializer && deserializer)), + @"PINDiskCache must be initialized with a serializer AND deserializer."); + + NSAssert(((!keyEncoder && !keyDecoder) || (keyEncoder && keyDecoder)), + @"PINDiskCache must be initialized with a encoder AND decoder."); if (self = [super init]) { _name = [name copy]; _prefix = [prefix copy]; - _fileExtension = [fileExtension copy]; _operationQueue = operationQueue; _instanceLock = [[NSConditionLock alloc] initWithCondition:PINDiskCacheConditionNotReady]; _willAddObjectBlock = nil; @@ -167,6 +172,19 @@ - (instancetype)initWithName:(NSString *)name } else { _deserializer = self.defaultDeserializer; } + + //setup key encoder/decoder + if(keyEncoder) { + _keyEncoder = [keyEncoder copy]; + } else { + _keyEncoder = self.defaultKeyEncoder; + } + + if(keyDecoder) { + _keyDecoder = [keyDecoder copy]; + } else { + _keyDecoder = self.defaultKeyDecoder; + } //we don't want to do anything without setting up the disk cache, but we also don't want to block init, it can take a while to initialize. This must *not* be done on _operationQueue because other operations added may hold the lock and fill up the queue. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ @@ -226,74 +244,79 @@ - (NSString *)keyForEncodedFileURL:(NSURL *)url - (NSString *)encodedString:(NSString *)string { - if (![string length]) { - return @""; - } - - if ([string respondsToSelector:@selector(stringByAddingPercentEncodingWithAllowedCharacters:)]) { - NSString *encodedString = [string stringByAddingPercentEncodingWithAllowedCharacters:[[NSCharacterSet characterSetWithCharactersInString:@".:/%"] invertedSet]]; - if (self.fileExtension.length > 0) { - return [encodedString stringByAppendingPathExtension:self.fileExtension]; - } - else { - return encodedString; - } - } - else { - CFStringRef static const charsToEscape = CFSTR(".:/%"); -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wdeprecated-declarations" - CFStringRef escapedString = CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, - (__bridge CFStringRef)string, - NULL, - charsToEscape, - kCFStringEncodingUTF8); -#pragma clang diagnostic pop - - if (self.fileExtension.length > 0) { - return [(__bridge_transfer NSString *)escapedString stringByAppendingPathExtension:self.fileExtension]; - } - else { - return (__bridge_transfer NSString *)escapedString; - } - } + return _keyEncoder(string); } - (NSString *)decodedString:(NSString *)string { - if (![string length]) { - return @""; - } - - if ([string respondsToSelector:@selector(stringByRemovingPercentEncoding)]) { - return [string stringByRemovingPercentEncoding]; - } - else { -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wdeprecated-declarations" - CFStringRef unescapedString = CFURLCreateStringByReplacingPercentEscapesUsingEncoding(kCFAllocatorDefault, - (__bridge CFStringRef)string, - CFSTR(""), - kCFStringEncodingUTF8); -#pragma clang diagnostic pop - return (__bridge_transfer NSString *)unescapedString; - } + return _keyDecoder(string); } --(PINDiskCacheSerializerBlock) defaultSerializer +- (PINDiskCacheSerializerBlock)defaultSerializer { return ^NSData*(id object, NSString *key){ return [NSKeyedArchiver archivedDataWithRootObject:object]; }; } --(PINDiskCacheDeserializerBlock) defaultDeserializer +- (PINDiskCacheDeserializerBlock)defaultDeserializer { return ^id(NSData * data, NSString *key){ return [NSKeyedUnarchiver unarchiveObjectWithData:data]; }; } +- (PINDiskCacheKeyEncoderBlock)defaultKeyEncoder +{ + return ^NSString *(NSString *decodedKey) { + if (![decodedKey length]) { + return @""; + } + + if ([decodedKey respondsToSelector:@selector(stringByAddingPercentEncodingWithAllowedCharacters:)]) { + NSString *encodedString = [decodedKey stringByAddingPercentEncodingWithAllowedCharacters:[[NSCharacterSet characterSetWithCharactersInString:@".:/%"] invertedSet]]; + return encodedString; + } + else { + CFStringRef static const charsToEscape = CFSTR(".:/%"); +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" + CFStringRef escapedString = CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, + (__bridge CFStringRef)decodedKey, + NULL, + charsToEscape, + kCFStringEncodingUTF8); +#pragma clang diagnostic pop + + return (__bridge_transfer NSString *)escapedString; + } + }; +} + +- (PINDiskCacheKeyEncoderBlock)defaultKeyDecoder +{ + return ^NSString *(NSString *encodedKey) { + if (![encodedKey length]) { + return @""; + } + + if ([encodedKey respondsToSelector:@selector(stringByRemovingPercentEncoding)]) { + return [encodedKey stringByRemovingPercentEncoding]; + } + else { +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" + CFStringRef unescapedString = CFURLCreateStringByReplacingPercentEscapesUsingEncoding(kCFAllocatorDefault, + (__bridge CFStringRef)encodedKey, + CFSTR(""), + kCFStringEncodingUTF8); +#pragma clang diagnostic pop + return (__bridge_transfer NSString *)unescapedString; + } + }; +} + + #pragma mark - Private Trash Methods - + (dispatch_queue_t)sharedTrashQueue diff --git a/Carthage/Checkouts/PINCache/Tests/PINCacheTests.m b/Carthage/Checkouts/PINCache/Tests/PINCacheTests.m index fe88dfc7..2154211c 100644 --- a/Carthage/Checkouts/PINCache/Tests/PINCacheTests.m +++ b/Carthage/Checkouts/PINCache/Tests/PINCacheTests.m @@ -4,6 +4,8 @@ #import "PINCacheTests.h" #import +#import + #if TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR typedef UIImage PINImage; @@ -879,28 +881,6 @@ - (void)testAsyncDiskInitialization XCTAssertTrue([[NSFileManager defaultManager] fileExistsAtPath:[testCacheURL path]]); } -- (void)testCustomFileExtension { - - PINCache *cache = [[PINCache alloc] initWithName:[[NSUUID UUID] UUIDString] fileExtension:@"obj"]; - - NSString *key = @"key"; - __block NSURL *diskFileURL = nil; - dispatch_semaphore_t semaphore = dispatch_semaphore_create(0); - - [cache.diskCache setObjectAsync:[self image] forKey:key completion:^(PINDiskCache *cache, NSString *key, id object) { - [cache fileURLForKeyAsync:key completion:^(NSString * _Nonnull key, NSURL * _Nullable fileURL) { - diskFileURL = fileURL; - dispatch_semaphore_signal(semaphore); - }]; - }]; - - dispatch_semaphore_wait(semaphore, [self timeout]); - - XCTAssertNotNil(diskFileURL.pathExtension); - XCTAssertEqualObjects(diskFileURL.pathExtension, @"obj"); - -} - - (void)testDiskCacheSet { PINDiskCache *testCache = [[PINDiskCache alloc] initWithName:@"testDiskCacheSet"]; @@ -979,4 +959,30 @@ - (void)testDiskCacheEmptyTrash XCTAssert(success == 0, @"Timed out"); } +- (void)testCustomEncoderDecoder { + NSString *rootPath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) firstObject]; + PINDiskCacheKeyEncoderBlock encoder = ^NSString *(NSString *decodedKey) { + return decodedKey; + }; + PINDiskCacheKeyDecoderBlock decoder = ^NSString *(NSString *encodedKey) { + return encodedKey; + }; + PINDiskCache *testCache = [[PINDiskCache alloc] initWithName:@"testCustomEncoder" + prefix:PINDiskCachePrefix + rootPath:rootPath + serializer:NULL + deserializer:NULL + keyEncoder:encoder + keyDecoder:decoder + operationQueue:[PINOperationQueue sharedOperationQueue]]; + + [testCache setObject:@(1) forKey:@"test_key"]; + + XCTAssertNotNil([testCache objectForKey:@"test_key"], @"Object should not be nil"); + + NSString *encodedKey = [[testCache fileURLForKey:@"test_key"] lastPathComponent]; + XCTAssertEqualObjects(@"test_key", encodedKey, @"Encoded key should be equal to decoded one"); + +} + @end diff --git a/Carthage/Checkouts/PINCache/run_tests_update_status.sh b/Carthage/Checkouts/PINCache/run_tests_update_status.sh deleted file mode 100755 index 8ab840e5..00000000 --- a/Carthage/Checkouts/PINCache/run_tests_update_status.sh +++ /dev/null @@ -1,38 +0,0 @@ -#!/usr/bin/env bash -set -eo pipefail - -UPDATE_STATUS_PATH=$1 -BUILDKITE_PULL_REQUEST=$2 -BUILDKITE_BUILD_URL=$3 - -function updateStatus() { - if [ "${BUILDKITE_PULL_REQUEST}" != "false" ] ; then - ${UPDATE_STATUS_PATH} "pinterest" "PINCache" ${BUILDKITE_PULL_REQUEST} "$1" ${BUILDKITE_BUILD_URL} "$2" "CI/Pinterest" - fi -} - -if [[ -z "${UPDATE_STATUS_PATH}" || -z "${BUILDKITE_PULL_REQUEST}" || -z "${BUILDKITE_BUILD_URL}" ]] ; then - echo "Update status path (${UPDATE_STATUS_PATH}), pull request (${BUILDKITE_BUILD_URL}) or build url (${BUILDKITE_PULL_REQUEST}) unset." - trap - EXIT - exit 255 -fi - -trapped="false" -function trap_handler() { - if [[ "$trapped" = "false" ]]; then - updateStatus failure "Tests failed…" - echo "Tests failed, updated status to failure" - fi - trapped="true" -} -trap trap_handler INT TERM EXIT - -updateStatus pending "Starting build…" - -make all - -updateStatus success "Tests passed" - -echo "All tests succeeded, updated status to success" -trap - EXIT -exit 0 \ No newline at end of file