Skip to content

Commit

Permalink
Adding protection mode while writing content to the file
Browse files Browse the repository at this point in the history
  • Loading branch information
gbansal-spr committed Jan 18, 2017
1 parent 2615d27 commit 8d8604a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ NS_ASSUME_NONNULL_BEGIN
*/
@property (nonatomic, assign, readonly) NSString *protectionModeString;

@property (nonatomic, assign, readonly) NSDataWritingOptions protectionModeOption;

/**
The dictionary representation of this image format.
Expand Down Expand Up @@ -181,4 +183,4 @@ NS_ASSUME_NONNULL_BEGIN
+ (instancetype)formatWithName:(NSString *)name family:(NSString *)family imageSize:(CGSize)imageSize style:(FICImageFormatStyle)style maximumCount:(NSInteger)maximumCount devices:(FICImageFormatDevices)devices protectionMode:(FICImageFormatProtectionMode)protectionMode;

@end
NS_ASSUME_NONNULL_END
NS_ASSUME_NONNULL_END
16 changes: 16 additions & 0 deletions FastImageCache/FastImageCache/FastImageCache/FICImageFormat.m
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,22 @@ - (NSString *)protectionModeString {
return protectionModeString;
}

- (NSDataWritingOptions)protectionModeOption {
NSDataWritingOptions protectionModeOption = NSDataWritingFileProtectionNone;
switch (_protectionMode) {
case FICImageFormatProtectionModeNone:
protectionModeOption = NSDataWritingFileProtectionNone;
break;
case FICImageFormatProtectionModeComplete:
protectionModeOption = NSDataWritingFileProtectionComplete;
break;
case FICImageFormatProtectionModeCompleteUntilFirstUserAuthentication:
protectionModeOption = NSDataWritingFileProtectionCompleteUntilFirstUserAuthentication;
break;
}
return protectionModeOption;
}

#pragma mark - Object Lifecycle

+ (instancetype)formatWithName:(NSString *)name family:(NSString *)family imageSize:(CGSize)imageSize style:(FICImageFormatStyle)style maximumCount:(NSInteger)maximumCount devices:(FICImageFormatDevices)devices protectionMode:(FICImageFormatProtectionMode)protectionMode {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,7 @@ - (void)saveMetadata {
return;
}

BOOL fileWriteResult = [data writeToFile:[self metadataFilePath] atomically:NO];
BOOL fileWriteResult = [data writeToFile:[self metadataFilePath] options:[_imageFormat protectionModeOption] error:nil];
if (fileWriteResult == NO) {
NSString *message = [NSString stringWithFormat:@"*** FIC Error: %s couldn't write metadata for format %@", __PRETTY_FUNCTION__, [_imageFormat name]];
[self.imageCache _logMessage:message];
Expand Down

0 comments on commit 8d8604a

Please sign in to comment.