Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't set file protection unless requested. #220

Merged
merged 2 commits into from
Mar 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* Add your own contributions to the next release on the line below this with your name.
- [fix] Fix up warnings and upgrade to PINOperation 1.1.1: [#213](https://github.com/pinterest/PINCache/pull/213)
- [performance] Reduce locking churn in cleanup methods. [#212](https://github.com/pinterest/PINCache/pull/212)
- [fix] Don't set file protection unless requested. [#220](https://github.com/pinterest/PINCache/pull/220)

## 3.0.1 -- Beta 6
- [fix] Add some sane limits to the disk cache: [#201]https://github.com/pinterest/PINCache/pull/201
Expand Down
34 changes: 22 additions & 12 deletions Source/PINDiskCache.m
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ @interface PINDiskCache () {
@property (assign, nonatomic) BOOL diskWritable;
@property (assign, nonatomic) pthread_cond_t diskStateKnownCondition;
@property (assign, nonatomic) BOOL diskStateKnown;
@property (assign, nonatomic) BOOL writingProtectionOptionSet;
@end

@implementation PINDiskCache
Expand All @@ -81,6 +82,7 @@ @implementation PINDiskCache

#if TARGET_OS_IPHONE
@synthesize writingProtectionOption = _writingProtectionOption;
@synthesize writingProtectionOptionSet = _writingProtectionOptionSet;
#endif

#pragma mark - Initialization -
Expand Down Expand Up @@ -174,7 +176,9 @@ - (instancetype)initWithName:(NSString *)name
_ageLimit = 60 * 60 * 24 * 30;

#if TARGET_OS_IPHONE
_writingProtectionOption = NSDataWritingFileProtectionNone;
_writingProtectionOptionSet = NO;
// This is currently the default for files, but we'd rather not write it if it's unspecified.
_writingProtectionOption = NSDataWritingFileProtectionCompleteUntilFirstUserAuthentication;
#endif

_metadata = [[NSMutableDictionary alloc] init];
Expand Down Expand Up @@ -985,10 +989,11 @@ - (void)setObject:(id <NSCoding>)object forKey:(NSString *)key fileURL:(NSURL **
if (!key || !object)
return;

NSDataWritingOptions writeOptions = NSDataWritingAtomic;
#if TARGET_OS_IPHONE
NSDataWritingOptions writeOptions = NSDataWritingAtomic | self.writingProtectionOption;
#else
NSDataWritingOptions writeOptions = NSDataWritingAtomic;
if (self.writingProtectionOptionSet) {
writeOptions |= self.writingProtectionOption;
}
#endif

// Remain unlocked here so that we're not locked while serializing.
Expand Down Expand Up @@ -1334,7 +1339,8 @@ - (void)setAgeLimit:(NSTimeInterval)ageLimit
} withPriority:PINOperationQueuePriorityHigh];
}

- (BOOL)isTTLCache {
- (BOOL)isTTLCache
{
BOOL isTTLCache;

[self lock];
Expand All @@ -1344,7 +1350,8 @@ - (BOOL)isTTLCache {
return isTTLCache;
}

- (void)setTtlCache:(BOOL)ttlCache {
- (void)setTtlCache:(BOOL)ttlCache
{
[self.operationQueue scheduleOperation:^{
[self lock];
self->_ttlCache = ttlCache;
Expand All @@ -1353,7 +1360,8 @@ - (void)setTtlCache:(BOOL)ttlCache {
}

#if TARGET_OS_IPHONE
- (NSDataWritingOptions)writingProtectionOption {
- (NSDataWritingOptions)writingProtectionOption
{
NSDataWritingOptions option;

[self lock];
Expand All @@ -1363,13 +1371,15 @@ - (NSDataWritingOptions)writingProtectionOption {
return option;
}

- (void)setWritingProtectionOption:(NSDataWritingOptions)writingProtectionOption {
- (void)setWritingProtectionOption:(NSDataWritingOptions)writingProtectionOption
{
[self.operationQueue scheduleOperation:^{
NSDataWritingOptions option = NSDataWritingFileProtectionMask & writingProtectionOption;
NSDataWritingOptions option = NSDataWritingFileProtectionMask & writingProtectionOption;

[self lock];
self->_writingProtectionOption = option;
[self unlock];
[self lock];
self->_writingProtectionOptionSet = YES;
self->_writingProtectionOption = option;
[self unlock];
} withPriority:PINOperationQueuePriorityHigh];
}
#endif
Expand Down