fixing various race conditions and errors after refactoring
This commit is contained in:
@@ -81,15 +81,14 @@ func (c *Collection) CreateItem(label string, attrs map[string]string, secret *S
|
||||
props[DbusItemLabel] = dbus.MakeVariant(label)
|
||||
props[DbusItemType] = dbus.MakeVariant(typeString)
|
||||
props[DbusItemAttributes] = dbus.MakeVariant(attrs)
|
||||
props[DbusItemCreated] = dbus.MakeVariant(uint64(time.Now().Unix()))
|
||||
// props[DbusItemModified] = dbus.MakeVariant(uint64(time.Now().Unix()))
|
||||
|
||||
if err = c.Dbus.Call(
|
||||
DbusCollectionCreateItem, 0, props, secret, replace,
|
||||
).Store(&path, &promptPath); err != nil {
|
||||
return
|
||||
}
|
||||
if err = c.setModify(); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if isPrompt(promptPath) {
|
||||
prompt = NewPrompt(c.Conn, promptPath)
|
||||
@@ -102,9 +101,6 @@ func (c *Collection) CreateItem(label string, attrs map[string]string, secret *S
|
||||
}
|
||||
|
||||
item, err = NewItem(c, path)
|
||||
if err = item.setCreate(); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
@@ -196,6 +192,10 @@ func (c *Collection) Lock() (err error) {
|
||||
}
|
||||
c.IsLocked = true
|
||||
|
||||
if _, _, err = c.Modified(); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
@@ -225,6 +225,10 @@ func (c *Collection) Relabel(newLabel string) (err error) {
|
||||
}
|
||||
c.LabelName = newLabel
|
||||
|
||||
if _, _, err = c.Modified(); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
@@ -273,7 +277,15 @@ func (c *Collection) SetAlias(alias string) (err error) {
|
||||
DbusServiceSetAlias, 0, alias, c.Dbus.Path(),
|
||||
)
|
||||
|
||||
err = call.Err
|
||||
if err = call.Err; err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
c.Alias = alias
|
||||
|
||||
if _, _, err = c.Modified(); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
@@ -293,6 +305,10 @@ func (c *Collection) Unlock() (err error) {
|
||||
}
|
||||
c.IsLocked = false
|
||||
|
||||
if _, _, err = c.Modified(); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
@@ -309,6 +325,7 @@ func (c *Collection) Created() (created time.Time, err error) {
|
||||
timeInt = variant.Value().(uint64)
|
||||
|
||||
created = time.Unix(int64(timeInt), 0)
|
||||
c.CreatedAt = created
|
||||
|
||||
return
|
||||
}
|
||||
@@ -346,40 +363,6 @@ func (c *Collection) Modified() (modified time.Time, isChanged bool, err error)
|
||||
return
|
||||
}
|
||||
|
||||
/*
|
||||
setCreate updates the Collection's creation time (as specified by Collection.Created).
|
||||
It seems that this does not generate automatically.
|
||||
*/
|
||||
func (c *Collection) setCreate() (err error) {
|
||||
|
||||
var t time.Time = time.Now()
|
||||
|
||||
if err = c.Dbus.SetProperty(DbusCollectionCreated, uint64(t.Unix())); err != nil {
|
||||
return
|
||||
}
|
||||
c.CreatedAt = t
|
||||
|
||||
if err = c.setModify(); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
/*
|
||||
setModify updates the Collection's modification time (as specified by Collection.Modified).
|
||||
It seems that this does not update automatically.
|
||||
*/
|
||||
func (c *Collection) setModify() (err error) {
|
||||
|
||||
var t time.Time = time.Now()
|
||||
|
||||
err = c.Dbus.SetProperty(DbusCollectionModified, uint64(t.Unix()))
|
||||
c.LastModified = t
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// path is a *very* thin wrapper around Collection.Dbus.Path(). It is needed for LockableObject interface membership.
|
||||
func (c *Collection) path() (dbusPath dbus.ObjectPath) {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user