diff --git a/changelog b/changelog index 5e7f26b..5b469f2 100644 --- a/changelog +++ b/changelog @@ -10,6 +10,7 @@ - fixed potential compilation problem in AES implementation (Bug #1905810) - fixed crash when re-arranging groups (Bug #1754998) - fixed size problems of some dialogs +- files are not longer truncated when saving fails (Bug #1648616) --------------- 0.3.0a diff --git a/src/Kdb3Database.cpp b/src/Kdb3Database.cpp index 00c5398..f7503bf 100644 --- a/src/Kdb3Database.cpp +++ b/src/Kdb3Database.cpp @@ -1101,6 +1101,7 @@ bool Kdb3Database::save(){ quint8 FinalRandomSeed[16]; quint8 ContentsHash[32]; quint8 EncryptionIV[16]; + if(!(File->openMode() & QIODevice::WriteOnly)){ File->close(); } @@ -1239,9 +1240,15 @@ bool Kdb3Database::save(){ return false; } - File->resize(0); //truncate + if(!File->resize(EncryptedPartSize+DB_HEADER_SIZE)){ + delete [] buffer; + error=decodeFileError(File->error()); + return false; + } + File->seek(0); if(File->write(buffer,EncryptedPartSize+DB_HEADER_SIZE)!=EncryptedPartSize+DB_HEADER_SIZE){ delete [] buffer; + error=decodeFileError(File->error()); return false; } File->flush();