Skip to content

Commit

Permalink
#127 #123 #120 Fixes
Browse files Browse the repository at this point in the history
- Entry History is retained
- UUID is never changed
- Access Time, ModificationTime,  And Location Changed Time are all updated when appropiate.
  • Loading branch information
jkdba committed May 25, 2018
1 parent da66f07 commit 79b9471
Showing 1 changed file with 19 additions and 21 deletions.
40 changes: 19 additions & 21 deletions internal/Set-KPEntry.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,11 @@ function Set-KPEntry
{
if((Test-KPPasswordValue $KeePassPassword) -and (Test-KPConnection $KeePassConnection))
{

if($Force -or $PSCmdlet.ShouldProcess("Title: $($KeePassEntry.Strings.ReadSafe('Title')). `n`tUserName: $($KeePassEntry.Strings.ReadSafe('UserName')). `n`tGroup Path $($KeePassEntry.ParentGroup.GetFullPath('/', $true))"))
{
[KeePassLib.PwEntry] $OldEntry = $KeePassEntry.CloneDeep()

if($Title)
{
$SecureTitle = New-Object KeePassLib.Security.ProtectedString($KeePassConnection.MemoryProtection.ProtectTitle, $Title)
Expand Down Expand Up @@ -125,33 +128,28 @@ function Set-KPEntry
}
}

## If you are moving the entry to another group then take these actions.
$KeePassEntry.History.Add($OldEntry)

if($KeePassGroup)
{
## Make Full Copy of Entry
$NewKeePassEntry = $KeePassEntry.CloneDeep()
## Assign New Uuid to CloneDeep
$NewKeePassEntry.Uuid = New-Object KeePassLib.PwUuid($true)
## Add Clone to Specified group
$KeePassGroup.AddEntry($NewKeePassEntry, $true)
## Save for safety
$KeePassConnection.Save($null)
## Delete previous entry
## Hide output
$KeePassEntry.ParentGroup.Entries.Remove($KeePassEntry) > $null

$KeePassConnection.Save($null)

if($PassThru)
{
$NewKeePassEntry
}
$OldKeePassGroup = $KeePassEntry.ParentGroup
## Add to group and move
$KeePassGroup.AddEntry($KeePassEntry, $true, $true)
## delete old entry
$null = $OldKeePassGroup.Entries.Remove($KeePassEntry)
}

## user "colaloc" added this line. comment: we must change LastModificationTime to prevent synchronization problems
## Add History Entry
$KeePassEntry.LastModificationTime = Get-Date
## user "colaloc" added this line. comment: any changes must be saved!
$KeePassEntry.LastAccessTime = Get-Date

## Save for safety
$KeePassConnection.Save($null)

if($PassThru)
{
$KeePassEntry
}
}
}
}
Expand Down

0 comments on commit 79b9471

Please sign in to comment.