tobischo / gokeepasslib

A library to read and write keepass 2 files written in go
MIT License
251 stars 30 forks source link

Copy entries and groups #91

Closed korovan-software closed 1 year ago

korovan-software commented 1 year ago

Is there a simple way to copy items from one group to another?

tobischo commented 1 year ago

The simplest way would be general slice operations I suppose.

Could you elaborate on what use case you are trying to solve and why your current approach seems to be too complex?

korovan-software commented 1 year ago

I'm working on copy/move feature to let user possibility manage items via Copy/Cut/Paste comands.

In the case of move it is not very difficult, but also has some pitfalls. In the case of copy I have to clone (deep copy) entry or group stricture and define new UUIDs, because it is incorrect to have two identical UUIDs.

I just want to check if there is already some simple way which I don't see, because for me self-made deep copy is too difficult for such easy feature.

tobischo commented 1 year ago

Understood, right now there isn't any such functionality

We could add a 'Clone/DeepCopy' function on groups and entries which provides a new object but already takes care of the UUID replacement.

move/delete/copy would then just work with slice operations

One of the things to consider here (but I am sure you already consider that) is that any operation that creates, moves, or removed entries is only safe while entries are unlocked.

korovan-software commented 1 year ago

Sure, it would be great to have such functionality in the library. Thank you for quick reply!

tobischo commented 1 year ago

Take a look at #92 please.

That should cover the deep copy behaviour you asked for via the Clone function on Group and Entry structs

korovan-software commented 1 year ago

@tobischo Thanks a lot for the quick update! Works fine for me on a simple test cases. I'm a little bit confused by the size of changes, but it seems most of them are for tests.

tobischo commented 1 year ago

Yeah, it is 3 methods in 2 files for the actual functionality and another 2 files for the tests - everything else is for vendoring to make the testing easier

tobischo commented 1 year ago

Released as v3.5.0