check whether the current file is empty before creating backup
This commit is contained in:
parent
3128d31536
commit
76b5abb5ba
|
@ -420,11 +420,16 @@ void PasswordFile::doBackup()
|
|||
if(!isOpen()) {
|
||||
open();
|
||||
}
|
||||
fstream backupFile(m_path + ".backup", ios::out | ios::binary);
|
||||
backupFile.exceptions(ios_base::failbit | ios_base::badbit);
|
||||
m_file.seekg(0);
|
||||
backupFile << m_file.rdbuf();
|
||||
backupFile.close();
|
||||
m_file.seekg(0, ios_base::end);
|
||||
if(m_file.tellg()) {
|
||||
m_file.seekg(0);
|
||||
fstream backupFile(m_path + ".backup", ios::out | ios::trunc | ios::binary);
|
||||
backupFile.exceptions(ios_base::failbit | ios_base::badbit);
|
||||
backupFile << m_file.rdbuf();
|
||||
backupFile.close();
|
||||
} else {
|
||||
// the current file is empty anyways
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
|
|
Loading…
Reference in New Issue