Allow creating a new file in PasswordFile::save()
to ease saving a file under a different location
This commit is contained in:
parent
b6ad06faa2
commit
a1b694a50b
|
@ -405,7 +405,15 @@ void PasswordFile::save(PasswordFileSaveFlags options)
|
|||
if (m_file.is_open()) {
|
||||
m_file.close();
|
||||
}
|
||||
m_file.open(m_path, ios_base::in | ios_base::out | ios_base::trunc | ios_base::binary);
|
||||
try {
|
||||
m_file.open(m_path, ios_base::in | ios_base::out | ios_base::trunc | ios_base::binary);
|
||||
} catch (const ios_base::failure &) {
|
||||
// try to create a new file if configured via \a options
|
||||
if (!(options & PasswordFileSaveFlags::AllowToCreateNewFile)) {
|
||||
throw;
|
||||
}
|
||||
m_file.open(m_path, ios_base::out | ios_base::trunc | ios_base::binary);
|
||||
}
|
||||
}
|
||||
|
||||
write(options);
|
||||
|
|
|
@ -48,7 +48,8 @@ enum class PasswordFileSaveFlags : std::uint64_t {
|
|||
Encryption = 1,
|
||||
Compression = 2,
|
||||
PasswordHashing = 4,
|
||||
Default = Encryption | Compression | PasswordHashing,
|
||||
AllowToCreateNewFile = 8,
|
||||
Default = Encryption | Compression | PasswordHashing | AllowToCreateNewFile,
|
||||
};
|
||||
|
||||
std::string PASSWORD_FILE_EXPORT flagsToString(PasswordFileSaveFlags flags);
|
||||
|
|
Loading…
Reference in New Issue