Delete PDF files from cache when documents deleted

This commit is contained in:
Jackson Harper
2023-10-04 14:19:58 +08:00
parent 581c6c179b
commit 07702b61af

View File

@ -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)
}
}
}