Skip to content

Commit

Permalink
Fix a bug when w.Resume is set.
Browse files Browse the repository at this point in the history
If w.Resume is set but there is no file to resume, then we erronously
return io.EOF.  Also, while we're in here, remove a dependency on the
old object listing code.

Fixes #59.
  • Loading branch information
kurin committed Jan 26, 2019
1 parent 61f182d commit bfa7981
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 11 deletions.
14 changes: 14 additions & 0 deletions b2/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,20 @@ func TestResumeWriter(t *testing.T) {
}
}

func TestResumeWriterWithoutExtantFile(t *testing.T) {
ctx := context.Background()
bucket, done := startLiveTest(ctx, t)
defer done()

r := io.LimitReader(zReader{}, 15e6)
w := bucket.Object("foo").NewWriter(ctx)
w.ChunkSize = 5e6
w.Resume = true
if _, err := io.Copy(w, r); err != nil {
t.Fatalf("io.Copy: %v", err)
}
}

func TestAttrs(t *testing.T) {
ctx := context.Background()
ctx, cancel := context.WithTimeout(ctx, 10*time.Minute)
Expand Down
29 changes: 18 additions & 11 deletions b2/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,21 +303,28 @@ func (w *Writer) getLargeFile() (beLargeFileInterface, error) {
}
return w.o.b.b.startLargeFile(w.ctx, w.name, ctype, w.info)
}
var got bool
iter := w.o.b.List(w.ctx, ListPrefix(w.name), ListUnfinished())
var fi beFileInterface
for iter.Next() {
obj := iter.Object()
if obj.Name() == w.name {
got = true
fi = obj.f
}
}
if iter.Err() != nil {
return nil, iter.Err()
}
if !got {
w.Resume = false
return w.getLargeFile()
}

next := 1
seen := make(map[int]string)
var size int64
var fi beFileInterface
for {
cur := &Cursor{name: w.name}
objs, _, err := w.o.b.ListObjects(w.ctx, 1, cur)
if err != nil {
return nil, err
}
if len(objs) < 1 || objs[0].name != w.name {
w.Resume = false
return w.getLargeFile()
}
fi = objs[0].f
parts, n, err := fi.listParts(w.ctx, next, 100)
if err != nil {
return nil, err
Expand Down

0 comments on commit bfa7981

Please sign in to comment.