-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathblob_funcs.go
119 lines (88 loc) · 2.14 KB
/
blob_funcs.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
package gokwallet
import (
"github.com/godbus/dbus/v5"
)
/*
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 = ErrInitFolder
return
}
blob = &Blob{
DbusObject: f.DbusObject,
Name: keyName,
// Value: "",
Recurse: recursion,
wm: f.wallet.wm,
wallet: f.wallet,
folder: f,
isInit: false,
}
blob.isInit = true
if blob.Recurse.AllWalletItems || blob.Recurse.Blobs {
if err = blob.Update(); err != nil {
return
}
}
blob.isInit = true
return
}
// 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
}
// Exists returns true if this Blob actually exists.
func (b *Blob) Exists() (exists bool, err error) {
if exists, err = b.folder.HasEntry(b.Name); err != nil {
return
}
return
}
// Rename renames this Blob (changes its key).
func (b *Blob) Rename(newName string) (err error) {
if err = b.folder.RenameEntry(b.Name, newName); err != nil {
return
}
b.Name = newName
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
}
// Update fetches a Blob's Blob.Value.
func (b *Blob) Update() (err error) {
var call *dbus.Call
var v dbus.Variant
if err = b.folder.wallet.walletCheck(); err != nil {
return
}
if call = b.Dbus.Call(
DbusWMReadEntry, 0, b.folder.wallet.handle, b.folder.Name, b.Name, b.folder.wallet.wm.AppID,
); call.Err != nil {
err = call.Err
return
}
if err = call.Store(&v); err != nil {
return
}
b.Value = v.Value().([]byte)
return
}
// isWalletItem is needed for interface membership.
func (b *Blob) isWalletItem() (isWalletItem bool) {
isWalletItem = true
return
}