mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2025-01-26 06:26:11 -05:00
Fix entry clone modification time update (#3602)
* Add test for (unwanted) history timeinfo update when cloning entries. * Add timeInfo test for clone with rename. * Fixed modification time update when cloning an entry with renaming.
This commit is contained in:
parent
1ceacdf636
commit
058b4da954
@ -762,14 +762,13 @@ Entry* Entry::clone(CloneFlags flags) const
|
||||
entry->m_autoTypeAssociations->copyDataFrom(m_autoTypeAssociations);
|
||||
if (flags & CloneIncludeHistory) {
|
||||
for (Entry* historyItem : m_history) {
|
||||
Entry* historyItemClone = historyItem->clone(flags & ~CloneIncludeHistory & ~CloneNewUuid);
|
||||
Entry* historyItemClone = historyItem->clone(flags & ~CloneIncludeHistory & ~CloneNewUuid & ~CloneResetTimeInfo);
|
||||
historyItemClone->setUpdateTimeinfo(false);
|
||||
historyItemClone->setUuid(entry->uuid());
|
||||
historyItemClone->setUpdateTimeinfo(true);
|
||||
entry->addHistoryItem(historyItemClone);
|
||||
}
|
||||
}
|
||||
entry->setUpdateTimeinfo(true);
|
||||
|
||||
if (flags & CloneResetTimeInfo) {
|
||||
QDateTime now = Clock::currentDateTimeUtc();
|
||||
@ -782,6 +781,8 @@ Entry* Entry::clone(CloneFlags flags) const
|
||||
if (flags & CloneRenameTitle)
|
||||
entry->setTitle(tr("%1 - Clone").arg(entry->title()));
|
||||
|
||||
entry->setUpdateTimeinfo(true);
|
||||
|
||||
return entry;
|
||||
}
|
||||
|
||||
|
@ -107,18 +107,44 @@ void TestEntry::testClone()
|
||||
QCOMPARE(entryCloneNewUuid->historyItems().size(), 0);
|
||||
QCOMPARE(entryCloneNewUuid->timeInfo().creationTime(), entryOrg->timeInfo().creationTime());
|
||||
|
||||
// Reset modification time
|
||||
entryOrgTime.setLastModificationTime(Clock::datetimeUtc(60));
|
||||
entryOrg->setTimeInfo(entryOrgTime);
|
||||
|
||||
QScopedPointer<Entry> entryCloneRename(entryOrg->clone(Entry::CloneRenameTitle));
|
||||
QCOMPARE(entryCloneRename->uuid(), entryOrg->uuid());
|
||||
QCOMPARE(entryCloneRename->title(), QString("New Title - Clone"));
|
||||
// Cloning should not modify time info unless explicity requested
|
||||
QCOMPARE(entryCloneRename->timeInfo(), entryOrg->timeInfo());
|
||||
|
||||
QScopedPointer<Entry> entryCloneResetTime(entryOrg->clone(Entry::CloneResetTimeInfo));
|
||||
QCOMPARE(entryCloneResetTime->uuid(), entryOrg->uuid());
|
||||
QCOMPARE(entryCloneResetTime->title(), QString("New Title"));
|
||||
QCOMPARE(entryCloneResetTime->historyItems().size(), 0);
|
||||
QVERIFY(entryCloneResetTime->timeInfo().creationTime() != entryOrg->timeInfo().creationTime());
|
||||
|
||||
QScopedPointer<Entry> entryCloneHistory(entryOrg->clone(Entry::CloneIncludeHistory));
|
||||
// Date back history of original entry
|
||||
Entry * firstHistoryItem = entryOrg->historyItems()[0];
|
||||
TimeInfo entryOrgHistoryTimeInfo = firstHistoryItem->timeInfo();
|
||||
QDateTime datedBackEntryOrgModificationTime = entryOrgHistoryTimeInfo.lastModificationTime().addMSecs(-10);
|
||||
entryOrgHistoryTimeInfo.setLastModificationTime(datedBackEntryOrgModificationTime);
|
||||
entryOrgHistoryTimeInfo.setCreationTime(datedBackEntryOrgModificationTime);
|
||||
firstHistoryItem->setTimeInfo(entryOrgHistoryTimeInfo);
|
||||
|
||||
QScopedPointer<Entry> entryCloneHistory(entryOrg->clone(Entry::CloneIncludeHistory | Entry::CloneResetTimeInfo));
|
||||
QCOMPARE(entryCloneHistory->uuid(), entryOrg->uuid());
|
||||
QCOMPARE(entryCloneHistory->title(), QString("New Title"));
|
||||
QCOMPARE(entryCloneHistory->historyItems().size(), 1);
|
||||
QCOMPARE(entryCloneHistory->historyItems().size(), entryOrg->historyItems().size());
|
||||
QCOMPARE(entryCloneHistory->historyItems().at(0)->title(), QString("Original Title"));
|
||||
QCOMPARE(entryCloneHistory->timeInfo().creationTime(), entryOrg->timeInfo().creationTime());
|
||||
QVERIFY(entryCloneHistory->timeInfo().creationTime() != entryOrg->timeInfo().creationTime());
|
||||
// Timeinfo of history items should not be modified
|
||||
QList<Entry*> entryOrgHistory = entryOrg->historyItems(), clonedHistory = entryCloneHistory->historyItems();
|
||||
auto entryOrgHistoryItem = entryOrgHistory.constBegin();
|
||||
for(auto entryCloneHistoryItem = clonedHistory.constBegin()
|
||||
;entryCloneHistoryItem != clonedHistory.constEnd()
|
||||
;++entryCloneHistoryItem, ++entryOrgHistoryItem) {
|
||||
QCOMPARE((*entryOrgHistoryItem)->timeInfo(), (*entryCloneHistoryItem)->timeInfo());
|
||||
}
|
||||
|
||||
Database db;
|
||||
auto* entryOrgClone = entryOrg->clone(Entry::CloneNoFlags);
|
||||
|
Loading…
x
Reference in New Issue
Block a user