Don't suppress IO errors when writing files

* Close or flush streams explicitely so writing is not
  deferred
    * to catch errors in the right place
    * to avoid suppressing errors completely when writing
      would be deferred to the destructor invocation
* Improve comments
This commit is contained in:
Martchus 2019-12-15 19:43:31 +01:00
parent 3afa954ebd
commit fb8c99b2d4
2 changed files with 3 additions and 1 deletions

View File

@ -10,7 +10,7 @@ set(META_APP_URL "https://github.com/${META_APP_AUTHOR}/${META_PROJECT_NAME}")
set(META_APP_DESCRIPTION "C++ library to read/write passwords from/to encrypted files")
set(META_VERSION_MAJOR 5)
set(META_VERSION_MINOR 0)
set(META_VERSION_PATCH 1)
set(META_VERSION_PATCH 2)
set(META_ADD_DEFAULT_CPP_UNIT_TEST_APPLICATION ON)
# add project files

View File

@ -507,6 +507,7 @@ void PasswordFile::write(PasswordFileSaveFlags options)
if (!(options & PasswordFileSaveFlags::Encryption)) {
// write data to file
m_file.write(decryptedData.data(), static_cast<streamsize>(size));
m_file.flush();
return;
}
@ -560,6 +561,7 @@ void PasswordFile::write(PasswordFileSaveFlags options)
}
m_file.write(reinterpret_cast<char *>(iv), aes256cbcIvSize);
m_file.write(encryptedData.data(), static_cast<streamsize>(outlen1 + outlen2));
m_file.flush();
}
/*!