Cull orphan sticker files.
This commit is contained in:
parent
9c72514db1
commit
dc0b1bc223
@ -12,6 +12,7 @@
|
||||
#import <SignalServiceKit/OWSContact.h>
|
||||
#import <SignalServiceKit/OWSFileSystem.h>
|
||||
#import <SignalServiceKit/OWSPrimaryStorage.h>
|
||||
#import <SignalServiceKit/SignalServiceKit-Swift.h>
|
||||
#import <SignalServiceKit/TSAttachmentStream.h>
|
||||
#import <SignalServiceKit/TSInteraction.h>
|
||||
#import <SignalServiceKit/TSMessage.h>
|
||||
@ -268,11 +269,18 @@ typedef void (^OrphanDataBlock)(OWSOrphanData *);
|
||||
return nil;
|
||||
}
|
||||
|
||||
NSString *stickersDirPath = StickerManager.cacheDirUrl.path;
|
||||
NSSet<NSString *> *_Nullable allStickerFilePaths = [self filePathsInDirectorySafe:stickersDirPath];
|
||||
if (!allStickerFilePaths || !self.isMainAppAndActive) {
|
||||
return nil;
|
||||
}
|
||||
|
||||
NSMutableSet<NSString *> *allOnDiskFilePaths = [NSMutableSet new];
|
||||
[allOnDiskFilePaths unionSet:legacyAttachmentFilePaths];
|
||||
[allOnDiskFilePaths unionSet:sharedDataAttachmentFilePaths];
|
||||
[allOnDiskFilePaths unionSet:legacyProfileAvatarsFilePaths];
|
||||
[allOnDiskFilePaths unionSet:sharedDataProfileAvatarFilePaths];
|
||||
[allOnDiskFilePaths unionSet:allStickerFilePaths];
|
||||
[allOnDiskFilePaths addObjectsFromArray:tempFilePaths];
|
||||
|
||||
NSSet<NSString *> *profileAvatarFilePaths = [OWSUserProfile allProfileAvatarFilePaths];
|
||||
@ -298,6 +306,8 @@ typedef void (^OrphanDataBlock)(OWSOrphanData *);
|
||||
// Messages
|
||||
NSMutableSet<NSString *> *orphanInteractionIds = [NSMutableSet new];
|
||||
NSMutableSet<NSString *> *allMessageAttachmentIds = [NSMutableSet new];
|
||||
// Stickers
|
||||
NSMutableSet<NSString *> *activeStickerFilePaths = [NSMutableSet new];
|
||||
[databaseConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) {
|
||||
[transaction
|
||||
enumerateKeysAndObjectsInCollection:TSAttachmentStream.collection
|
||||
@ -351,6 +361,13 @@ typedef void (^OrphanDataBlock)(OWSOrphanData *);
|
||||
TSMessage *message = (TSMessage *)interaction;
|
||||
[allMessageAttachmentIds addObjectsFromArray:message.allAttachmentIds];
|
||||
}];
|
||||
|
||||
if (shouldAbort) {
|
||||
return;
|
||||
}
|
||||
|
||||
[activeStickerFilePaths
|
||||
addObjectsFromArray:[StickerManager filepathsForAllInstalledStickersWithTransaction:transaction.asAnyRead]];
|
||||
}];
|
||||
if (shouldAbort) {
|
||||
return nil;
|
||||
@ -364,6 +381,7 @@ typedef void (^OrphanDataBlock)(OWSOrphanData *);
|
||||
NSMutableSet<NSString *> *orphanFilePaths = [allOnDiskFilePaths mutableCopy];
|
||||
[orphanFilePaths minusSet:allAttachmentFilePaths];
|
||||
[orphanFilePaths minusSet:profileAvatarFilePaths];
|
||||
[orphanFilePaths minusSet:activeStickerFilePaths];
|
||||
NSMutableSet<NSString *> *missingAttachmentFilePaths = [allAttachmentFilePaths mutableCopy];
|
||||
[missingAttachmentFilePaths minusSet:allOnDiskFilePaths];
|
||||
|
||||
|
||||
@ -457,6 +457,18 @@ public class StickerManager: NSObject {
|
||||
}
|
||||
}
|
||||
|
||||
@objc
|
||||
public class func filepathsForAllInstalledStickers(transaction: SDSAnyReadTransaction) -> [String] {
|
||||
|
||||
var filePaths = [String]()
|
||||
let installedStickers = InstalledSticker.anyFetchAll(transaction: transaction)
|
||||
for installedSticker in installedStickers {
|
||||
let filePath = stickerUrl(stickerInfo: installedSticker.info).path
|
||||
filePaths.append(filePath)
|
||||
}
|
||||
return filePaths
|
||||
}
|
||||
|
||||
@objc
|
||||
public class func isStickerInstalled(stickerInfo: StickerInfo) -> Bool {
|
||||
var result = false
|
||||
@ -700,7 +712,6 @@ public class StickerManager: NSObject {
|
||||
|
||||
// MARK: - Known Sticker Packs
|
||||
|
||||
// TODO: We may want to cull these in the orphan data cleaner.
|
||||
@objc
|
||||
public class func addKnownStickerInfo(_ stickerInfo: StickerInfo,
|
||||
transaction: SDSAnyWriteTransaction) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user