Use NativeFileStream and actually throw exceptions in export
This commit is contained in:
parent
b1a55def8b
commit
f7c6db0132
|
@ -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_APP_DESCRIPTION "C++ library to read/write passwords from/to encrypted files")
|
||||||
set(META_VERSION_MAJOR 5)
|
set(META_VERSION_MAJOR 5)
|
||||||
set(META_VERSION_MINOR 0)
|
set(META_VERSION_MINOR 0)
|
||||||
set(META_VERSION_PATCH 3)
|
set(META_VERSION_PATCH 4)
|
||||||
set(META_ADD_DEFAULT_CPP_UNIT_TEST_APPLICATION ON)
|
set(META_ADD_DEFAULT_CPP_UNIT_TEST_APPLICATION ON)
|
||||||
|
|
||||||
# add project files
|
# add project files
|
||||||
|
|
|
@ -589,15 +589,16 @@ void PasswordFile::clear()
|
||||||
/*!
|
/*!
|
||||||
* \brief Writes the current root entry to a plain text file. No encryption is used.
|
* \brief Writes the current root entry to a plain text file. No encryption is used.
|
||||||
* \param targetPath Specifies the path of the text file.
|
* \param targetPath Specifies the path of the text file.
|
||||||
* \throws Throws ios_base::failure when an IO error occurs.
|
* \throws Throws std::ios_base::failure when an IO error occurs and std::runtime_error when no root entry is present.
|
||||||
* \throws Throws runtime_error when no root entry is present.
|
|
||||||
*/
|
*/
|
||||||
void PasswordFile::exportToTextfile(const string &targetPath) const
|
void PasswordFile::exportToTextfile(const string &targetPath) const
|
||||||
{
|
{
|
||||||
if (!m_rootEntry) {
|
if (!m_rootEntry) {
|
||||||
throw runtime_error("Root entry has not been created.");
|
throw runtime_error("Root entry has not been created.");
|
||||||
}
|
}
|
||||||
fstream output(targetPath.c_str(), ios_base::out);
|
NativeFileStream output;
|
||||||
|
output.exceptions(std::ios_base::failbit | std::ios_base::badbit);
|
||||||
|
output.open(targetPath, std::ios_base::out);
|
||||||
const auto printIndention = [&output](int level) {
|
const auto printIndention = [&output](int level) {
|
||||||
for (int i = 0; i < level; ++i) {
|
for (int i = 0; i < level; ++i) {
|
||||||
output << " ";
|
output << " ";
|
||||||
|
|
Loading…
Reference in New Issue