private async Task DeleteOrphanedBackupFilesAsync(HashSet <string> backupPaths) { foreach (StorageFile backupFile in await SessionUtility.GetAllBackupFilesAsync()) { if (!backupPaths.Contains(backupFile.Path)) { try { await backupFile.DeleteAsync(); } catch { // Best effort } } } }
private async Task DeleteOrphanedBackupFilesAsync(NotepadsSessionDataV1 sessionData) { HashSet <string> backupPaths = sessionData.TextEditors .SelectMany(te => new[] { te.LastSaved?.BackupFilePath, te.Pending?.BackupFilePath }) .ToHashSet(StringComparer.OrdinalIgnoreCase); foreach (StorageFile backupFile in await SessionUtility.GetAllBackupFilesAsync()) { if (!backupPaths.Contains(backupFile.Path)) { try { await backupFile.DeleteAsync(); } catch (Exception ex) { LoggingService.LogError($"Failed to delete backup file: {ex.Message}"); } } } }
private async Task DeleteOrphanedBackupFilesAsync(NotepadsSessionDataV1 sessionData) { HashSet <string> backupPaths = sessionData.TextEditors .SelectMany(te => new[] { te.LastSaved?.BackupFilePath, te.Pending?.BackupFilePath }) .ToHashSet(StringComparer.OrdinalIgnoreCase); foreach (StorageFile backupFile in await SessionUtility.GetAllBackupFilesAsync()) { if (!backupPaths.Contains(backupFile.Path)) { try { await backupFile.DeleteAsync(); } catch { // Best effort } } } }
// Cleanup orphaned/dangling backup files private async Task DeleteOrphanedBackupFilesAsync(NotepadsSessionDataV1 sessionData) { HashSet <string> backupPaths = sessionData.TextEditors .SelectMany(editor => new[] { editor.LastSavedBackupFilePath, editor.PendingBackupFilePath }) .Where(path => path != null) .ToHashSet(StringComparer.OrdinalIgnoreCase); foreach (StorageFile backupFile in await SessionUtility.GetAllBackupFilesAsync(_backupFolderName)) { if (!backupPaths.Contains(backupFile.Path)) { try { await backupFile.DeleteAsync(); } catch (Exception ex) { LoggingService.LogError($"[{nameof(SessionManager)}] Failed to delete orphaned backup file: {ex.Message}"); } } } }