Skip to content

Commit 967584d

Browse files
committed
9p: make FieldParser optional for mount points
This interface needs more consideration and is likely to change in the future. For now, we'll make it an optional extension.
1 parent 2468ce9 commit 967584d

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

internal/filesystem/9p/mountpoint.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"sync"
1212

1313
"github.com/djdv/go-filesystem-utils/internal/filesystem"
14+
"github.com/djdv/go-filesystem-utils/internal/generic"
1415
perrors "github.com/djdv/p9/errors"
1516
"github.com/djdv/p9/fsimpl/templatefs"
1617
"github.com/djdv/p9/p9"
@@ -51,7 +52,6 @@ type (
5152
GuestID() filesystem.ID
5253
}
5354
MountPoint interface {
54-
FieldParser
5555
SystemMaker
5656
Mounter
5757
HostIdentifier
@@ -228,11 +228,17 @@ func (mf *MountPointFile[MP]) parseFieldsLocked(b []byte) error {
228228
for _, fields := range tokenize(b) {
229229
switch fields.typ() {
230230
case keyAndValue:
231-
var (
232-
key, value = fields[key], fields[value]
233-
mountPoint = mf.mountPoint
234-
)
235-
if err := mountPoint.ParseField(key, value); err != nil {
231+
parser, ok := any(mf.mountPoint).(FieldParser)
232+
if !ok {
233+
// TODO: [Go 1.21] use [errors.ErrUnsupported].
234+
const unsupported = generic.ConstError("unsupported operation")
235+
return fmt.Errorf(
236+
"%w - %w: %T does not implement field parser",
237+
perrors.EINVAL, unsupported, mf.mountPoint,
238+
)
239+
}
240+
key, value := fields[key], fields[value]
241+
if err := parser.ParseField(key, value); err != nil {
236242
return errors.Join(perrors.EINVAL, err)
237243
}
238244
mf.modified = true

0 commit comments

Comments
 (0)