diff options
author | moneromooo-monero <moneromooo-monero@users.noreply.github.com> | 2017-12-07 12:07:18 +0000 |
---|---|---|
committer | moneromooo-monero <moneromooo-monero@users.noreply.github.com> | 2017-12-07 12:07:18 +0000 |
commit | 3f24e90149fd778dd9b16bfd967eb9de69e45a80 (patch) | |
tree | 69b4442792d6dc8ebb984c34c19c0ab0df8caebe /src/wallet/wallet2.cpp | |
parent | Merge pull request #2845 (diff) | |
download | monero-3f24e90149fd778dd9b16bfd967eb9de69e45a80.tar.xz |
wallet2: don't write a .new file when not needed
Diffstat (limited to 'src/wallet/wallet2.cpp')
-rw-r--r-- | src/wallet/wallet2.cpp | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index 181bb1852..e37cbb25d 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -2960,14 +2960,6 @@ void wallet2::store_to(const std::string &path, const std::string &password) const std::string old_keys_file = m_keys_file; const std::string old_address_file = m_wallet_file + ".address.txt"; - // save to new file - std::ofstream ostr; - ostr.open(new_file, std::ios_base::binary | std::ios_base::out | std::ios_base::trunc); - binary_archive<true> oar(ostr); - bool success = ::serialization::serialize(oar, cache_file_data); - ostr.close(); - THROW_WALLET_EXCEPTION_IF(!success || !ostr.good(), error::file_save_error, new_file); - // save keys to the new file // if we here, main wallet file is saved and we only need to save keys and address files if (!same_file) { @@ -2994,6 +2986,14 @@ void wallet2::store_to(const std::string &path, const std::string &password) LOG_ERROR("error removing file: " << old_address_file); } } else { + // save to new file + std::ofstream ostr; + ostr.open(new_file, std::ios_base::binary | std::ios_base::out | std::ios_base::trunc); + binary_archive<true> oar(ostr); + bool success = ::serialization::serialize(oar, cache_file_data); + ostr.close(); + THROW_WALLET_EXCEPTION_IF(!success || !ostr.good(), error::file_save_error, new_file); + // here we have "*.new" file, we need to rename it to be without ".new" std::error_code e = tools::replace_file(new_file, m_wallet_file); THROW_WALLET_EXCEPTION_IF(e, error::file_save_error, m_wallet_file, e); |