Disable iCloud backup once per directory creation instead of for each image save.

This commit is contained in:
Tim Johnsen 2023-04-18 16:27:30 -07:00
parent fb50c1d20f
commit 3fd19c16eb
1 changed files with 20 additions and 11 deletions

View File

@ -81,7 +81,7 @@ static NSString * const SDDiskCacheExtendedAttributeName = @"com.hackemist.SDDis
NSParameterAssert(data);
NSParameterAssert(key);
if (![self.fileManager fileExistsAtPath:self.diskCachePath]) {
[self.fileManager createDirectoryAtPath:self.diskCachePath withIntermediateDirectories:YES attributes:nil error:NULL];
[self createDirectory];
}
// get cache Path for image key
@ -90,12 +90,6 @@ static NSString * const SDDiskCacheExtendedAttributeName = @"com.hackemist.SDDis
NSURL *fileURL = [NSURL fileURLWithPath:cachePathForKey isDirectory:NO];
[data writeToURL:fileURL options:self.config.diskCacheWritingOptions error:nil];
// disable iCloud backup
if (self.config.shouldDisableiCloud) {
// ignore iCloud backup resource value error
[fileURL setResourceValue:@YES forKey:NSURLIsExcludedFromBackupKey error:nil];
}
}
- (NSData *)extendedDataForKey:(NSString *)key {
@ -131,10 +125,20 @@ static NSString * const SDDiskCacheExtendedAttributeName = @"com.hackemist.SDDis
- (void)removeAllData {
[self.fileManager removeItemAtPath:self.diskCachePath error:nil];
[self.fileManager createDirectoryAtPath:self.diskCachePath
withIntermediateDirectories:YES
attributes:nil
error:NULL];
[self createDirectory];
}
- (void)createDirectory {
[self.fileManager createDirectoryAtPath:self.diskCachePath
withIntermediateDirectories:YES
attributes:nil
error:NULL];
// disable iCloud backup
if (self.config.shouldDisableiCloud) {
// ignore iCloud backup resource value error
[[NSURL fileURLWithPath:self.diskCachePath isDirectory:YES] setResourceValue:@YES forKey:NSURLIsExcludedFromBackupKey error:nil];
}
}
- (void)removeExpiredData {
@ -285,6 +289,11 @@ static NSString * const SDDiskCacheExtendedAttributeName = @"com.hackemist.SDDis
}
// New directory does not exist, rename directory
[self.fileManager moveItemAtPath:srcPath toPath:dstPath error:nil];
// disable iCloud backup
if (self.config.shouldDisableiCloud) {
// ignore iCloud backup resource value error
[[NSURL fileURLWithPath:dstPath isDirectory:YES] setResourceValue:@YES forKey:NSURLIsExcludedFromBackupKey error:nil];
}
} else {
// New directory exist, merge the files
NSDirectoryEnumerator *dirEnumerator = [self.fileManager enumeratorAtPath:srcPath];