Compare commits

..
1 Commits
Author SHA1 Message Date
clawbot d991df0b24 get cards with GetStores and GetStore, read them through fs.FS (closes #4)
GetStores replaces GetDCFStores: it takes a context, has no count
argument and returns a plain slice. GetStore returns the one mounted
card, or ErrNoStore or ErrMultipleStores.

Each Object keeps the fs.FS its card was read through, and Hash reads
through it, so tests can use fstest.MapFS. A cancelled context stops
the read before the next directory. Library errors wrap with %w.

Model: opus-5-5
2026-11-03 19:34:36 +00:00
2 changed files with 23 additions and 1 deletions

No files matched your search

+15
View File
@@ -1,6 +1,7 @@
package dcf package dcf
import ( import (
"context"
"errors" "errors"
"io/fs" "io/fs"
"path/filepath" "path/filepath"
@@ -59,6 +60,20 @@ func TestParseStoresReturnsErrorNamingTheCard(t *testing.T) {
} }
} }
func TestParseStoresReturnsErrorWhenCancelled(t *testing.T) {
t.Parallel()
ctx, cancel := context.WithCancel(t.Context())
cancel()
mountpoint := newCardOnDisk(t, "DCIM/100ABCDE/ABCD0001.JPG")
_, err := parseStores(ctx, []string{mountpoint})
if !errors.Is(err, context.Canceled) {
t.Fatalf("parseStores error = %v, want %v", err, context.Canceled)
}
}
func TestOnlyStore(t *testing.T) { func TestOnlyStore(t *testing.T) {
t.Parallel() t.Parallel()
+8 -1
View File
@@ -891,9 +891,16 @@ func TestParseStoreReadsNoDirectoryWhenAlreadyCancelled(t *testing.T) {
} }
for _, card := range cards { for _, card := range cards {
_, err := parseStore(ctx, card, testRoot) var read []string
// The context is already cancelled, so this needs no name to cancel at.
fsys := cancelingFS{MapFS: card, read: &read}
_, err := parseStore(ctx, fsys, testRoot)
if !errors.Is(err, context.Canceled) { if !errors.Is(err, context.Canceled) {
t.Errorf("error = %v, want %v", err, context.Canceled) t.Errorf("error = %v, want %v", err, context.Canceled)
} }
assertPaths(t, "directories read", read)
} }
} }