Merge pull request #1400 from dmcgowan/content-local-writer-locks
Ensure content writer only unlocks resource once
This commit is contained in:
commit
60fea11686
@ -55,6 +55,10 @@ func (w *writer) Write(p []byte) (n int, err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (w *writer) Commit(size int64, expected digest.Digest, opts ...content.Opt) error {
|
func (w *writer) Commit(size int64, expected digest.Digest, opts ...content.Opt) error {
|
||||||
|
if w.fp == nil {
|
||||||
|
return errors.Wrap(errdefs.ErrFailedPrecondition, "cannot commit on closed writer")
|
||||||
|
}
|
||||||
|
|
||||||
if err := w.fp.Sync(); err != nil {
|
if err := w.fp.Sync(); err != nil {
|
||||||
return errors.Wrap(err, "sync failed")
|
return errors.Wrap(err, "sync failed")
|
||||||
}
|
}
|
||||||
@ -115,8 +119,8 @@ func (w *writer) Commit(size int64, expected digest.Digest, opts ...content.Opt)
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
unlock(w.ref)
|
|
||||||
w.fp = nil
|
w.fp = nil
|
||||||
|
unlock(w.ref)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -130,12 +134,13 @@ func (w *writer) Commit(size int64, expected digest.Digest, opts ...content.Opt)
|
|||||||
//
|
//
|
||||||
// To abandon a transaction completely, first call close then `Store.Remove` to
|
// To abandon a transaction completely, first call close then `Store.Remove` to
|
||||||
// clean up the associated resources.
|
// clean up the associated resources.
|
||||||
func (cw *writer) Close() (err error) {
|
func (w *writer) Close() (err error) {
|
||||||
unlock(cw.ref)
|
if w.fp != nil {
|
||||||
|
w.fp.Sync()
|
||||||
if cw.fp != nil {
|
err = w.fp.Close()
|
||||||
cw.fp.Sync()
|
w.fp = nil
|
||||||
return cw.fp.Close()
|
unlock(w.ref)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
Loading…
Reference in New Issue
Block a user