Skip to content

Commit 3331c25

Browse files
committed
Format automatic wallet backup file names in ISO 8601 basic format
1 parent c32a208 commit 3331c25

File tree

6 files changed

+16
-2
lines changed

6 files changed

+16
-2
lines changed

doc/release-notes.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ The `addnode=`, `connect=`, `port=`, `bind=`, `rpcport=`, `rpcbind=`, and `walle
7676
The log timestamp format is now ISO 8601 (e.g. "2021-02-28T12:34:56Z").
7777

7878

79+
#### Automatic Backup File Naming
80+
81+
The file extension applied to automatic backups is now in ISO 8601 basic notation (e.g. "20210228T123456Z"). The basic notation is used to prevent illegal `:` characters from appearing in the filename.
82+
7983
*version* Change log
8084
==============
8185

src/init.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1288,7 +1288,7 @@ bool AppInitMain()
12881288
if (nWalletBackups > 0) {
12891289
if (fs::exists(backupDir)) {
12901290
// Create backup of the wallet
1291-
std::string dateTimeStr = DateTimeStrFormat(".%Y-%m-%d-%H-%M", GetTime());
1291+
std::string dateTimeStr = FormatISO8601DateTimeForBackup(GetTime());
12921292
std::string backupPathStr = backupDir.string();
12931293
backupPathStr += "/" + strWalletFile;
12941294
std::string sourcePathStr = GetDataDir().string();

src/test/util_tests.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,11 @@ BOOST_AUTO_TEST_CASE(util_FormatISO8601DateTime)
101101
BOOST_CHECK_EQUAL(FormatISO8601DateTime(1317425777), "2011-09-30T23:36:17Z");
102102
}
103103

104+
BOOST_AUTO_TEST_CASE(util_FormatISO8601DateTimeForBackup)
105+
{
106+
BOOST_CHECK_EQUAL(FormatISO8601DateTimeForBackup(1586310600), ".20200408T0150Z");
107+
}
108+
104109
BOOST_AUTO_TEST_CASE(util_FormatISO8601Date)
105110
{
106111
BOOST_CHECK_EQUAL(FormatISO8601Date(1317425777), "2011-09-30");

src/utiltime.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ std::string FormatISO8601DateTime(int64_t nTime) {
9595
return DateTimeStrFormat("%Y-%m-%dT%H:%M:%SZ", nTime);
9696
}
9797

98+
std::string FormatISO8601DateTimeForBackup(int64_t nTime) {
99+
return DateTimeStrFormat(".%Y%m%dT%H%MZ", nTime);
100+
}
101+
98102
std::string FormatISO8601Date(int64_t nTime) {
99103
return DateTimeStrFormat("%Y-%m-%d", nTime);
100104
}

src/utiltime.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ std::string DateTimeStrFormat(const char* pszFormat, int64_t nTime);
3636
std::string DurationToDHMS(int64_t nDurationTime);
3737

3838
std::string FormatISO8601DateTime(int64_t nTime);
39+
std::string FormatISO8601DateTimeForBackup(int64_t nTime);
3940
std::string FormatISO8601Date(int64_t nTime);
4041
std::string FormatISO8601Time(int64_t nTime);
4142

src/wallet/wallet.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4419,7 +4419,7 @@ bool CWalletTx::AcceptToMemoryPool(CValidationState& state, bool fLimitFree, boo
44194419

44204420
std::string CWallet::GetUniqueWalletBackupName() const
44214421
{
4422-
return strprintf("%s%s", (dbw ? dbw->GetName() : "null"), DateTimeStrFormat(".%Y-%m-%d-%H-%M", GetTime()));
4422+
return strprintf("%s%s", (dbw ? dbw->GetName() : "null"), FormatISO8601DateTimeForBackup(GetTime()));
44234423
}
44244424

44254425
CWallet::CWallet() : dbw(new CWalletDBWrapper())

0 commit comments

Comments
 (0)