Cockatrice/cockatrice
Christo e674a39b87
Fix #6952: prevent deck loss when saving to a full disk (#6978)
* Fix #6952: prevent deck loss when saving to a full disk

DeckLoader::saveToFile() opened the target with QFile in WriteOnly mode,
which truncates the existing file to 0 bytes the moment it is opened. The
serializers (DeckList::saveToFile_Native/_Plain) always return true and the
result of flush() was ignored, so a write that failed part-way -- e.g.
because the disk was full -- left a 0-byte file behind yet was still
reported (and logged) as a successful save. The same truncate-then-write
pattern in updateLastLoadedTimestamp() could destroy a deck on load.

Switch both paths to QSaveFile, which writes to a temporary file and only
atomically replaces the target if commit() succeeds. On any write or flush
failure commit() returns false, the original deck is left untouched, and
the failure is logged instead of being reported as success.

* Use QSaveFile in convertToCockatriceFormat() too

convertToCockatriceFormat() had the same data-loss pattern: QFile WriteOnly
truncated the .cod, saveToFile_Native() always returns true, and the original
file was then removed unconditionally -- so a full disk during conversion wrote
a 0-byte .cod and then deleted the source deck.

Switch to QSaveFile (write + atomic commit), remove the original only after a
successful commit, and move the format check ahead of the file open so an
already-Cockatrice or unsupported deck never truncates or deletes anything.

Raised in review by ZeldaZach.
2026-06-09 07:54:01 +02:00
..
resources [DlgSettings] Refactor: split SettingsPage into separate files (#6899) 2026-05-18 01:59:02 -07:00
sounds Add cmake format (#4618) 2022-05-08 21:22:43 +02:00
src Fix #6952: prevent deck loss when saving to a full disk (#6978) 2026-06-09 07:54:01 +02:00
themes Update CMakeLists.txt (#6898) 2026-05-17 16:15:15 +02:00
translations Update translation files (#6920) 2026-05-21 19:14:58 -04:00
.qdevelop icon_draw and icon_untap added, icon_general and icon_messages modified 2009-07-31 13:37:16 +02:00
CMakeLists.txt [Game] [Arrows] Use arrowData/registry and generate unique server-side ids (#6973) 2026-06-07 21:11:02 +02:00
cockatrice.desktop Updated Spanish translation 2011-07-16 11:38:57 +02:00
cockatrice.qrc Add generic colorless mana symbol (#6873) 2026-05-17 19:48:48 +02:00
cockatrice.rc Included uninstaller for Windows version 2010-09-17 15:26:07 +02:00
cockatrice_en@source.ts Update translation source strings (#6762) 2026-04-01 05:49:17 +02:00