Skip to content

Commit 8d8604a

Browse files
committed
Adding protection mode while writing content to the file
1 parent 2615d27 commit 8d8604a

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

FastImageCache/FastImageCache/FastImageCache/FICImageFormat.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,8 @@ NS_ASSUME_NONNULL_BEGIN
147147
*/
148148
@property (nonatomic, assign, readonly) NSString *protectionModeString;
149149

150+
@property (nonatomic, assign, readonly) NSDataWritingOptions protectionModeOption;
151+
150152
/**
151153
The dictionary representation of this image format.
152154
@@ -181,4 +183,4 @@ NS_ASSUME_NONNULL_BEGIN
181183
+ (instancetype)formatWithName:(NSString *)name family:(NSString *)family imageSize:(CGSize)imageSize style:(FICImageFormatStyle)style maximumCount:(NSInteger)maximumCount devices:(FICImageFormatDevices)devices protectionMode:(FICImageFormatProtectionMode)protectionMode;
182184

183185
@end
184-
NS_ASSUME_NONNULL_END
186+
NS_ASSUME_NONNULL_END

FastImageCache/FastImageCache/FastImageCache/FICImageFormat.m

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,22 @@ - (NSString *)protectionModeString {
143143
return protectionModeString;
144144
}
145145

146+
- (NSDataWritingOptions)protectionModeOption {
147+
NSDataWritingOptions protectionModeOption = NSDataWritingFileProtectionNone;
148+
switch (_protectionMode) {
149+
case FICImageFormatProtectionModeNone:
150+
protectionModeOption = NSDataWritingFileProtectionNone;
151+
break;
152+
case FICImageFormatProtectionModeComplete:
153+
protectionModeOption = NSDataWritingFileProtectionComplete;
154+
break;
155+
case FICImageFormatProtectionModeCompleteUntilFirstUserAuthentication:
156+
protectionModeOption = NSDataWritingFileProtectionCompleteUntilFirstUserAuthentication;
157+
break;
158+
}
159+
return protectionModeOption;
160+
}
161+
146162
#pragma mark - Object Lifecycle
147163

148164
+ (instancetype)formatWithName:(NSString *)name family:(NSString *)family imageSize:(CGSize)imageSize style:(FICImageFormatStyle)style maximumCount:(NSInteger)maximumCount devices:(FICImageFormatDevices)devices protectionMode:(FICImageFormatProtectionMode)protectionMode {

FastImageCache/FastImageCache/FastImageCache/FICImageTable.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -714,7 +714,7 @@ - (void)saveMetadata {
714714
return;
715715
}
716716

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

0 commit comments

Comments
 (0)