report the proper lock id from a state lock error
Fix the now failing state unlock test by reporting the correct ID. The ID used by GCS is the generation number of the info object, which isn't known until the info is already written out. While we can't get the correct ID from the info data for the error rmessage, we can update it with the generation number after it's read.
This commit is contained in:
parent
1fee5ae172
commit
112c37458f
|
@ -80,6 +80,10 @@ func (c *remoteClient) Delete() error {
|
||||||
// Lock writes to a lock file, ensuring file creation. Returns the generation
|
// Lock writes to a lock file, ensuring file creation. Returns the generation
|
||||||
// number, which must be passed to Unlock().
|
// number, which must be passed to Unlock().
|
||||||
func (c *remoteClient) Lock(info *state.LockInfo) (string, error) {
|
func (c *remoteClient) Lock(info *state.LockInfo) (string, error) {
|
||||||
|
// update the path we're using
|
||||||
|
// we can't set the ID until the info is written
|
||||||
|
info.Path = c.lockFileURL()
|
||||||
|
|
||||||
infoJson, err := json.Marshal(info)
|
infoJson, err := json.Marshal(info)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
|
@ -93,12 +97,12 @@ func (c *remoteClient) Lock(info *state.LockInfo) (string, error) {
|
||||||
}
|
}
|
||||||
return w.Close()
|
return w.Close()
|
||||||
}()
|
}()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", c.lockError(fmt.Errorf("writing %q failed: %v", c.lockFileURL(), err))
|
return "", c.lockError(fmt.Errorf("writing %q failed: %v", c.lockFileURL(), err))
|
||||||
}
|
}
|
||||||
|
|
||||||
info.ID = strconv.FormatInt(w.Attrs().Generation, 10)
|
info.ID = strconv.FormatInt(w.Attrs().Generation, 10)
|
||||||
info.Path = c.lockFileURL()
|
|
||||||
|
|
||||||
return info.ID, nil
|
return info.ID, nil
|
||||||
}
|
}
|
||||||
|
@ -149,6 +153,15 @@ func (c *remoteClient) lockInfo() (*state.LockInfo, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// We use the Generation as the ID, so overwrite the ID in the json.
|
||||||
|
// This can't be written into the Info, since the generation isn't known
|
||||||
|
// until it's written.
|
||||||
|
attrs, err := c.lockFile().Attrs(c.storageContext)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
info.ID = strconv.FormatInt(attrs.Generation, 10)
|
||||||
|
|
||||||
return info, nil
|
return info, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue