Skip to content

Commit 5235585

Browse files
committed
Added remove all backuped containers
1 parent f732794 commit 5235585

2 files changed

Lines changed: 24 additions & 2 deletions

File tree

LBox/ContentView.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ struct ContentView: View {
5353
}
5454
}
5555
Button("Cancel Update (Restore)") { downloadManager.restoreBackup(backup) }
56-
Button("Delete Backup", role: .destructive) { downloadManager.discardBackup(backup) }
56+
// Modified to separate delete logic to optionally delete containers
57+
Button("Delete Backup", role: .destructive) { downloadManager.discardBackup(backup, deleteContainers: true) }
5758
} message: { backup in
5859
Text("Please run '\(backup.appName)' in LiveContainer to finalize the update, and then return to LBox.\n\nIf you have already run it and the update is not detected, you can try again or restore the previous version.")
5960
}

LBox/DownloadManager.swift

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,9 +299,30 @@ class DownloadManager: NSObject, ObservableObject {
299299
}
300300
}
301301

302-
func discardBackup(_ backup: AppBackup) {
302+
func discardBackup(_ backup: AppBackup, deleteContainers: Bool = false) {
303303
let fileManager = FileManager.default
304304
let backupFolder = backupDirectory.appendingPathComponent(backup.backupPath)
305+
306+
if deleteContainers {
307+
let backupAppURL = backupFolder.appendingPathComponent(backup.originalInstallPath)
308+
let lcInfoURL = backupAppURL.appendingPathComponent("LCAppInfo.plist")
309+
310+
if fileManager.fileExists(atPath: lcInfoURL.path),
311+
let data = try? Data(contentsOf: lcInfoURL),
312+
let plist = try? PropertyListSerialization.propertyList(from: data, format: nil) as? [String: Any],
313+
let containers = plist["LCContainers"] as? [[String: Any]],
314+
let dataAppFolder = currentDataApplicationFolder {
315+
316+
for container in containers {
317+
if let folderName = container["folderName"] as? String {
318+
let folderURL = dataAppFolder.appendingPathComponent(folderName)
319+
try? fileManager.removeItem(at: folderURL)
320+
print("Deleted backup container: \(folderName)")
321+
}
322+
}
323+
}
324+
}
325+
305326
try? fileManager.removeItem(at: backupFolder)
306327

307328
if let index = pendingBackups.firstIndex(where: { $0.id == backup.id }) {

0 commit comments

Comments
 (0)