Skip to content

Commit

Permalink
httpfs: protect against concurrent writes
Browse files Browse the repository at this point in the history
  • Loading branch information
barnex committed Jan 7, 2015
1 parent 8e28923 commit 602384d
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions httpfs/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func Create(URL string) (WriteCloseFlusher, error) {
if err != nil {
return nil, err
}
return &bufWriter{bufio.NewWriterSize(&appendWriter{URL}, BUFSIZE)}, nil
return &bufWriter{bufio.NewWriterSize(&appendWriter{URL, 0}, BUFSIZE)}, nil
}

func MustCreate(URL string) WriteCloseFlusher {
Expand Down Expand Up @@ -64,19 +64,21 @@ func (w *bufWriter) Close() error { return w.buf.Flush() }
func (w *bufWriter) Flush() error { return w.buf.Flush() }

type appendWriter struct {
URL string
URL string
byteCount int64
}

// TODO: buffer heavily, Flush() on close
func (w *appendWriter) Write(p []byte) (int, error) {
err := Append(w.URL, p)
err := AppendSize(w.URL, p, w.byteCount)
if err != nil {
return 0, err // don't know how many bytes written
}
w.byteCount += int64(len(p))
return len(p), nil
}

// TODO: flush
func (w *appendWriter) Close() error {
return nil
}
//func (w *appendWriter) Close() error {
//return nil
//}

0 comments on commit 602384d

Please sign in to comment.