Skip to content

Commit c1bc886

Browse files
authored
Merge pull request #1790 from nextcloud/disable-shared-avatar-cache
Don't use app-groups for caches anymore
2 parents a654c49 + c6964ca commit c1bc886

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

NextcloudTalk/NCAPIController.m

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,14 @@ - (void)initImageDownloaders
123123
// Make sure we support self-signed certificates we trusted before
124124
[[SDWebImageDownloader sharedDownloader].config setOperationClass:[NCWebImageDownloaderOperation class]];
125125

126-
// Set the caching path to be in our app group and limit size to 100 MB
127-
NSURL *avatarCacheURL = [[[NSFileManager defaultManager] containerURLForSecurityApplicationGroupIdentifier:groupIdentifier] URLByAppendingPathComponent:@"AvatarCache"];
128-
SDImageCache.defaultDiskCacheDirectory = avatarCacheURL.path;
126+
// Try to remove legacy avatar cache in app group
127+
NSURL *legacyCacheURL = [[[NSFileManager defaultManager] containerURLForSecurityApplicationGroupIdentifier:groupIdentifier] URLByAppendingPathComponent:@"AvatarCache"];
128+
if (legacyCacheURL != nil) {
129+
[[NSFileManager defaultManager] removeItemAtURL:legacyCacheURL error:nil];
130+
}
131+
132+
// Limit the cache size to 100 MB and prevent uploading to iCloud
133+
// Don't set the path to an app group in order to prevent crashes
129134
[SDImageCache sharedImageCache].config.shouldDisableiCloud = YES;
130135
[SDImageCache sharedImageCache].config.maxDiskSize = 100 * 1024 * 1024;
131136

NextcloudTalk/NCImageSessionManager.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,14 @@ import Foundation
1414
init() {
1515
let configuration = AFImageDownloader.defaultURLSessionConfiguration()
1616

17+
// Try to remove legacy ImageCache directory in app group
18+
if let legacyCacheURL = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: groupIdentifier)?.appendingPathComponent("ImageCache") {
19+
try? FileManager.default .removeItem(at: legacyCacheURL)
20+
}
21+
1722
// In case of images we want to use the cache and store it on disk
1823
// As we use the memory cache from AFImageDownloader, we only want disk cache here
19-
let imageCacheURL = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: groupIdentifier)?.appendingPathComponent("ImageCache")
24+
let imageCacheURL = FileManager.default.urls(for: .cachesDirectory, in: .userDomainMask).first?.appendingPathComponent("ImageCache")
2025
self.cache = URLCache(memoryCapacity: 0, diskCapacity: 100 * 1024 * 1024, directory: imageCacheURL)
2126

2227
configuration.urlCache = self.cache

0 commit comments

Comments
 (0)