Remove registry storage testdriver

Signed-off-by: glefloch <glfloch@gmail.com>
This commit is contained in:
glefloch
2018-11-15 10:36:19 +00:00
parent 29b5e79f82
commit 9fb201e23d
5 changed files with 43 additions and 91 deletions

View File

@@ -251,6 +251,8 @@ func (d *driver) Walk(ctx context.Context, path string, f storagedriver.WalkFn)
type writer struct {
d *driver
f *file
buffer []byte
buffSize int
closed bool
committed bool
cancelled bool
@@ -274,8 +276,17 @@ func (w *writer) Write(p []byte) (int, error) {
w.d.mutex.Lock()
defer w.d.mutex.Unlock()
if cap(w.buffer) < len(p)+w.buffSize {
data := make([]byte, len(w.buffer), len(p)+w.buffSize)
copy(data, w.buffer)
w.buffer = data
}
return w.f.WriteAt(p, int64(len(w.f.data)))
w.buffer = w.buffer[:w.buffSize+len(p)]
n := copy(w.buffer[w.buffSize:w.buffSize+len(p)], p)
w.buffSize += n
return n, nil
}
func (w *writer) Size() int64 {
@@ -290,6 +301,8 @@ func (w *writer) Close() error {
return fmt.Errorf("already closed")
}
w.closed = true
w.flush()
return nil
}
@@ -316,5 +329,16 @@ func (w *writer) Commit() error {
return fmt.Errorf("already cancelled")
}
w.committed = true
w.flush()
return nil
}
func (w *writer) flush() {
w.d.mutex.Lock()
defer w.d.mutex.Unlock()
w.f.WriteAt(w.buffer, int64(len(w.f.data)))
w.buffer = []byte{}
w.buffSize = 0
}