2021-12-20 04:02:48 -05:00
|
|
|
package gokwallet
|
|
|
|
|
2021-12-22 03:20:08 -05:00
|
|
|
import (
|
|
|
|
"github.com/godbus/dbus/v5"
|
|
|
|
)
|
|
|
|
|
2021-12-20 04:02:48 -05:00
|
|
|
/*
|
|
|
|
NewBlob returns a Blob. It requires a RecurseOpts
|
|
|
|
(you can use DefaultRecurseOpts, call NewRecurseOpts, or provide your own RecurseOpts struct).
|
|
|
|
It also requires a Folder.
|
|
|
|
*/
|
|
|
|
func NewBlob(f *Folder, keyName string, recursion *RecurseOpts) (blob *Blob, err error) {
|
|
|
|
|
|
|
|
if !f.isInit {
|
|
|
|
err = ErrNotInitialized
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
blob = &Blob{
|
|
|
|
DbusObject: f.DbusObject,
|
|
|
|
Name: keyName,
|
|
|
|
// Value: "",
|
|
|
|
Recurse: recursion,
|
|
|
|
wm: f.wallet.wm,
|
|
|
|
wallet: f.wallet,
|
|
|
|
folder: f,
|
|
|
|
isInit: false,
|
|
|
|
}
|
|
|
|
|
|
|
|
if blob.Recurse.AllWalletItems || blob.Recurse.Blobs {
|
|
|
|
if err = blob.Update(); err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
blob.isInit = true
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-12-23 04:21:21 -05:00
|
|
|
// Delete will delete this Blob from its parent Folder. You may want to run Folder.UpdateBlobs to update the existing map of Blob items.
|
|
|
|
func (b *Blob) Delete() (err error) {
|
|
|
|
|
|
|
|
if err = b.folder.RemoveEntry(b.Name); err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
b = nil
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetValue will replace this Blob's Blob.Value.
|
|
|
|
func (b *Blob) SetValue(newValue []byte) (err error) {
|
|
|
|
|
|
|
|
if _, err = b.folder.WriteBlob(b.Name, newValue); err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
b.Value = newValue
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-12-20 04:02:48 -05:00
|
|
|
// Update fetches a Blob's Blob.Value.
|
|
|
|
func (b *Blob) Update() (err error) {
|
|
|
|
|
2021-12-22 03:20:08 -05:00
|
|
|
var v dbus.Variant
|
|
|
|
|
|
|
|
if err = b.Dbus.Call(
|
|
|
|
DbusWMReadEntry, 0, b.folder.wallet.handle, b.folder.Name, b.Name, b.folder.wallet.wm.AppID,
|
|
|
|
).Store(&v); err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
b.Value = v.Value().([]byte)
|
2021-12-20 04:02:48 -05:00
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// isWalletItem is needed for interface membership.
|
|
|
|
func (b *Blob) isWalletItem() (isWalletItem bool) {
|
|
|
|
|
|
|
|
isWalletItem = true
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|