Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion client/fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,18 +116,27 @@ type FileFetcher struct {
Root string
}

func (f FileFetcher) ReadCheckpoint(_ context.Context) ([]byte, error) {
func (f FileFetcher) ReadCheckpoint(ctx context.Context) ([]byte, error) {
if err := ctx.Err(); err != nil {
return nil, err
}
return os.ReadFile(path.Join(f.Root, layout.CheckpointPath))
}

func (f FileFetcher) ReadTile(ctx context.Context, l, i uint64, p uint8) ([]byte, error) {
return fetcher.PartialOrFullResource(ctx, p, func(ctx context.Context, p uint8) ([]byte, error) {
if err := ctx.Err(); err != nil {
return nil, err
}
return os.ReadFile(path.Join(f.Root, layout.TilePath(l, i, p)))
})
}

func (f FileFetcher) ReadEntryBundle(ctx context.Context, i uint64, p uint8) ([]byte, error) {
return fetcher.PartialOrFullResource(ctx, p, func(ctx context.Context, p uint8) ([]byte, error) {
if err := ctx.Err(); err != nil {
return nil, err
}
return os.ReadFile(path.Join(f.Root, layout.EntriesPath(i, p)))
})
}
33 changes: 33 additions & 0 deletions client/fetcher_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package client

import (
"context"
"errors"
"testing"
)

func TestFileFetcherContextCancellation(t *testing.T) {
d := t.TempDir()

f := FileFetcher{
Root: d,
}

ctx, cancel := context.WithCancel(context.Background())
cancel() // Cancel immediately

_, err := f.ReadCheckpoint(ctx)
if !errors.Is(err, context.Canceled) {
t.Errorf("ReadCheckpoint: got error %v, want %v", err, context.Canceled)
}

_, err = f.ReadTile(ctx, 0, 0, 255)
if !errors.Is(err, context.Canceled) {
t.Errorf("ReadTile: got error %v, want %v", err, context.Canceled)
}

_, err = f.ReadEntryBundle(ctx, 0, 255)
if !errors.Is(err, context.Canceled) {
t.Errorf("ReadEntryBundle: got error %v, want %v", err, context.Canceled)
}
}
1 change: 1 addition & 0 deletions fsck/status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ func TestUpdate(t *testing.T) {
for i, want := range test.wantRanges {
if p == nil {
t.Fatalf("got %d entry ranges, want %d", i-1, len(test.wantRanges))
return // To make the linter happy
}
got := p.Value.(*Range)
if !reflect.DeepEqual(*got, want) {
Expand Down
2 changes: 1 addition & 1 deletion internal/fetcher/fallback.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func PartialOrFullResource(ctx context.Context, p uint8, f func(context.Context,
}
return sRaw, nil
case err != nil:
return sRaw, fmt.Errorf("failed to fetch resource: %v", err)
return sRaw, fmt.Errorf("failed to fetch resource: %w", err)
default:
return sRaw, nil
}
Expand Down
Loading