From 07702b61afc2b2c0952551342269f9257744c65d Mon Sep 17 00:00:00 2001 From: Jackson Harper Date: Wed, 4 Oct 2023 14:19:58 +0800 Subject: [PATCH] Delete PDF files from cache when documents deleted --- .../Sources/App/Views/RemoveLibraryItemAction.swift | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/apple/OmnivoreKit/Sources/App/Views/RemoveLibraryItemAction.swift b/apple/OmnivoreKit/Sources/App/Views/RemoveLibraryItemAction.swift index 5d431e66f..60269a8e1 100644 --- a/apple/OmnivoreKit/Sources/App/Views/RemoveLibraryItemAction.swift +++ b/apple/OmnivoreKit/Sources/App/Views/RemoveLibraryItemAction.swift @@ -3,6 +3,7 @@ import CoreData import Foundation import Models import Services +import Utils import Views func removeLibraryItemAction(dataService: DataService, objectID: NSManagedObjectID) { @@ -10,6 +11,11 @@ func removeLibraryItemAction(dataService: DataService, objectID: NSManagedObject if let item = dataService.viewContext.object(with: objectID) as? LinkedItem { item.state = "DELETED" try? dataService.viewContext.save() + + // Delete local PDF file if it exists + if let localPdf = item.localPDF, let localPdfURL = PDFUtils.localPdfURL(filename: localPdf) { + try? FileManager.default.removeItem(at: localPdfURL) + } } }