Skip to content

Commit 2435c07

Browse files
committed
9p: migrate to generic.OptionFunc
1 parent 9d80602 commit 2435c07

File tree

10 files changed

+27
-49
lines changed

10 files changed

+27
-49
lines changed

internal/filesystem/9p/chan.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"fmt"
66

7+
"github.com/djdv/go-filesystem-utils/internal/generic"
78
perrors "github.com/djdv/p9/errors"
89
"github.com/djdv/p9/fsimpl/templatefs"
910
"github.com/djdv/p9/p9"
@@ -38,7 +39,7 @@ func NewChannelFile(ctx context.Context,
3839
) (p9.QID, *ChannelFile, <-chan []byte, error) {
3940
var settings channelFileSettings
4041
settings.metadata.initialize(p9.ModeRegular)
41-
if err := applyOptions(&settings, options...); err != nil {
42+
if err := generic.ApplyOptions(&settings, options...); err != nil {
4243
return p9.QID{}, nil, nil, err
4344
}
4445
var (
@@ -59,7 +60,7 @@ func NewChannelFile(ctx context.Context,
5960
}
6061

6162
func WithBuffer[
62-
OT optionFunc[T],
63+
OT generic.OptionFunc[T],
6364
T any,
6465
I channelSetter[T],
6566
](size int,

internal/filesystem/9p/directory.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func (ds *directorySettings) setCleanupElements(b bool) { ds.cleanupElements = b
5151
// after they are considered empty and the last reference
5252
// held by a Walk has been closed.
5353
func UnlinkWhenEmpty[
54-
OT optionFunc[T],
54+
OT generic.OptionFunc[T],
5555
T any,
5656
I directorySetter[T],
5757
](b bool,
@@ -65,7 +65,7 @@ func UnlinkWhenEmpty[
6565
// UnlinkEmptyChildren sets [UnlinkWhenEmpty]
6666
// on files created by this file.
6767
func UnlinkEmptyChildren[
68-
OT optionFunc[T],
68+
OT generic.OptionFunc[T],
6969
T any,
7070
I directorySetter[T],
7171
](b bool,
@@ -79,7 +79,7 @@ func UnlinkEmptyChildren[
7979
func NewDirectory(options ...DirectoryOption) (p9.QID, p9.File, error) {
8080
var settings directorySettings
8181
settings.metadata.initialize(p9.ModeDirectory)
82-
if err := applyOptions(&settings, options...); err != nil {
82+
if err := generic.ApplyOptions(&settings, options...); err != nil {
8383
return p9.QID{}, nil, err
8484
}
8585
return newDirectory(&settings)

internal/filesystem/9p/guest.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package p9
33
import (
44
"errors"
55

6+
"github.com/djdv/go-filesystem-utils/internal/generic"
67
perrors "github.com/djdv/p9/errors"
78
"github.com/djdv/p9/p9"
89
)
@@ -32,7 +33,7 @@ func NewGuestFile(makeMountPointFn MakeMountPointFunc,
3233
) (p9.QID, *GuestFile, error) {
3334
var settings guestSettings
3435
settings.metadata.initialize(p9.ModeDirectory)
35-
if err := applyOptions(&settings, options...); err != nil {
36+
if err := generic.ApplyOptions(&settings, options...); err != nil {
3637
return p9.QID{}, nil, err
3738
}
3839
qid, directory, err := newDirectory(&settings.directorySettings)

internal/filesystem/9p/host.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"errors"
55

66
"github.com/djdv/go-filesystem-utils/internal/filesystem"
7+
"github.com/djdv/go-filesystem-utils/internal/generic"
78
perrors "github.com/djdv/p9/errors"
89
"github.com/djdv/p9/p9"
910
)
@@ -30,7 +31,7 @@ func NewHostFile(makeGuestFn MakeGuestFunc,
3031
) (p9.QID, *HostFile, error) {
3132
var settings hosterSettings
3233
settings.metadata.initialize(p9.ModeDirectory)
33-
if err := applyOptions(&settings, options...); err != nil {
34+
if err := generic.ApplyOptions(&settings, options...); err != nil {
3435
return p9.QID{}, nil, err
3536
}
3637
qid, directory, err := newDirectory(&settings.directorySettings)

internal/filesystem/9p/link.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package p9
33
import (
44
"sync"
55

6+
"github.com/djdv/go-filesystem-utils/internal/generic"
67
perrors "github.com/djdv/p9/errors"
78
"github.com/djdv/p9/p9"
89
)
@@ -32,7 +33,7 @@ func (ls *linkSync) disableRename(disabled bool) { ls.renameDisabled
3233
func (ls *linkSync) setRenamedFunc(fn RenamedFunc) { ls.renamedFn = fn }
3334

3435
func WithParent[
35-
OT optionFunc[T],
36+
OT generic.OptionFunc[T],
3637
T any,
3738
I linkSetter[T],
3839
](parent p9.File, child string,
@@ -46,7 +47,7 @@ func WithParent[
4647
// WithoutRename causes rename operations
4748
// to return an error when called.
4849
func WithoutRename[
49-
OT optionFunc[T],
50+
OT generic.OptionFunc[T],
5051
T any,
5152
I linkSetter[T],
5253
](disabled bool,
@@ -60,7 +61,7 @@ func WithoutRename[
6061
// WithRenamedFunc provides a callback
6162
// which is called after a successful rename operation.
6263
func WithRenamedFunc[
63-
OT optionFunc[T],
64+
OT generic.OptionFunc[T],
6465
T any,
6566
I linkSetter[T],
6667
](fn RenamedFunc,

internal/filesystem/9p/listener.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"sync/atomic"
1919
"time"
2020

21+
"github.com/djdv/go-filesystem-utils/internal/generic"
2122
p9net "github.com/djdv/go-filesystem-utils/internal/net/9p"
2223
perrors "github.com/djdv/p9/errors"
2324
"github.com/djdv/p9/fsimpl/templatefs"
@@ -110,7 +111,7 @@ const (
110111
func NewListener(ctx context.Context, options ...ListenerOption) (p9.QID, *Listener, <-chan manet.Listener, error) {
111112
var settings listenerSettings
112113
settings.metadata.initialize(p9.ModeDirectory)
113-
if err := applyOptions(&settings, options...); err != nil {
114+
if err := generic.ApplyOptions(&settings, options...); err != nil {
114115
return p9.QID{}, nil, nil, err
115116
}
116117
settings.linkSync.renameDisabled = true

internal/filesystem/9p/mount.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"sync"
1010

1111
"github.com/djdv/go-filesystem-utils/internal/filesystem"
12+
"github.com/djdv/go-filesystem-utils/internal/generic"
1213
perrors "github.com/djdv/p9/errors"
1314
"github.com/djdv/p9/p9"
1415
)
@@ -54,7 +55,7 @@ func (ue unmountError) Error() string {
5455
func NewMounter(makeHostFn MakeHostFunc, options ...MounterOption) (p9.QID, *MountFile, error) {
5556
var settings mounterSettings
5657
settings.metadata.initialize(p9.ModeDirectory)
57-
if err := applyOptions(&settings, options...); err != nil {
58+
if err := generic.ApplyOptions(&settings, options...); err != nil {
5859
return p9.QID{}, nil, err
5960
}
6061
qid, directory, err := newDirectory(&settings.directorySettings)

internal/filesystem/9p/mountpoint.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ func NewMountPoint[
139139
) (p9.QID, *MountPointFile[MP], error) {
140140
var settings fileSettings
141141
settings.metadata.initialize(p9.ModeRegular)
142-
if err := applyOptions(&settings, options...); err != nil {
142+
if err := generic.ApplyOptions(&settings, options...); err != nil {
143143
return p9.QID{}, nil, err
144144
}
145145
file := &MountPointFile[MP]{

internal/filesystem/9p/options.go

Lines changed: 0 additions & 32 deletions
This file was deleted.

internal/filesystem/9p/stat.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ type (
3434
p9.Attr
3535
p9.QID
3636
}
37+
fileSettings struct {
38+
linkSync
39+
metadata
40+
}
3741
metadataSetter[T any] interface {
3842
*T
3943
setPath(ninePath)
@@ -77,7 +81,7 @@ func (md *metadata) fillDefaults() {
7781
// WithPath specifies the path
7882
// to be used by this file.
7983
func WithPath[
80-
OT optionFunc[T],
84+
OT generic.OptionFunc[T],
8185
T any,
8286
I metadataSetter[T],
8387
](path *atomic.Uint64,
@@ -94,7 +98,7 @@ func WithPath[
9498
// WithPermissions specifies the permission bits
9599
// for a file's mode status.
96100
func WithPermissions[
97-
OT optionFunc[T],
101+
OT generic.OptionFunc[T],
98102
T any,
99103
I metadataSetter[T],
100104
](permissions p9.FileMode,
@@ -108,7 +112,7 @@ func WithPermissions[
108112
// WithUID specifies a UID value for
109113
// a file's status information.
110114
func WithUID[
111-
OT optionFunc[T],
115+
OT generic.OptionFunc[T],
112116
T any,
113117
I metadataSetter[T],
114118
](uid p9.UID,
@@ -122,7 +126,7 @@ func WithUID[
122126
// WithGID specifies a GID value for
123127
// a file's status information.
124128
func WithGID[
125-
OT optionFunc[T],
129+
OT generic.OptionFunc[T],
126130
T any,
127131
I metadataSetter[T],
128132
](gid p9.GID,

0 commit comments

Comments
 (0)