commit 529c62c9b81f88f07d060489c8d09c3634e55c64
parent 9f77e937b5bf1bdd7a69377f4027d61f248022ba
Author: Matsuda Kenji <info@mtkn.jp>
Date: Fri, 20 Oct 2023 08:34:14 +0900
gofmt
Diffstat:
15 files changed, 69 insertions(+), 79 deletions(-)
diff --git a/client2.go b/client2.go
@@ -47,10 +47,10 @@ func (c *Client) walkFile(name string) (*ClientFile, error) {
return nil, fmt.Errorf("invalid wqid: %v", wqid)
}
f := &ClientFile{
- name: path.Base(name),
- path: name,
- fid: fid,
- qid: qid,
+ name: path.Base(name),
+ path: name,
+ fid: fid,
+ qid: qid,
client: c,
}
fid.file = f
diff --git a/client_test.go b/client_test.go
@@ -29,11 +29,11 @@ func newClientForTest(msize uint32, uname string, tmsgc chan<- Msg, rmsgc <-chan
func TestClientVersion(t *testing.T) {
tests := []struct {
- name string
- mSize uint32
- version string
- rmsg Msg
- wantmsize uint32
+ name string
+ mSize uint32
+ version string
+ rmsg Msg
+ wantmsize uint32
wantversion string
}{
{"0", mSize, "9P2000",
@@ -51,10 +51,10 @@ func TestClientVersion(t *testing.T) {
defer c.Stop()
bg := context.Background()
var (
- gotmsize uint32
+ gotmsize uint32
gotversion string
- goterr error
- wg sync.WaitGroup
+ goterr error
+ wg sync.WaitGroup
)
wg.Add(1)
go func() {
@@ -86,7 +86,6 @@ func TestClientVersion(t *testing.T) {
}
}
-
// the following tests are test for both client and server.
// should be moved to propper file.
func TestTransaction(t *testing.T) {
@@ -145,4 +144,4 @@ func TestClient2(t *testing.T) {
t.Errorf("read: %v", err)
}
t.Log(string(b[:n]))
-}
-\ No newline at end of file
+}
diff --git a/cmd/numfs/main.go b/cmd/numfs/main.go
@@ -15,12 +15,10 @@ import (
"lib9p"
)
-
-type numFS struct{
+type numFS struct {
root *numFile
}
-
func (fsys *numFS) String() string {
if fsys.root == nil {
return "<empty>"
@@ -173,8 +171,8 @@ func main() {
fsys := new(numFS)
fsys.root = &numFile{
- fs: fsys,
- id: -1,
+ fs: fsys,
+ id: -1,
reader: nil,
children: []*numFile{
&numFile{fsys, 0, bytes.NewReader([]byte("0\n")), nil},
diff --git a/fcall.go b/fcall.go
@@ -1173,8 +1173,8 @@ func (msg *RWrite) String() string {
}
type TClunk struct {
- tag uint16
- fid uint32
+ tag uint16
+ fid uint32
}
func newTClunk(buf []byte) *TClunk {
diff --git a/fcall_test.go b/fcall_test.go
@@ -49,4 +49,4 @@ func TestFcallParse(t *testing.T) {
t.Errorf("data mismatch: %v, %v != %v", msgs[i], msgs[i].marshal(), raws[i])
}
}
-}
-\ No newline at end of file
+}
diff --git a/fid.go b/fid.go
@@ -119,7 +119,7 @@ func newClientFid(fid uint32) *clientFid {
}
type clientFidPool struct {
- m map[uint32]*clientFid
+ m map[uint32]*clientFid
lock *sync.Mutex
}
@@ -141,7 +141,7 @@ func (pool *clientFidPool) lookup(fid uint32) (*clientFid, bool) {
func (pool *clientFidPool) nextFid() (uint32, error) {
pool.lock.Lock()
defer pool.lock.Unlock()
- for i := uint32(0); i < i + 1; i++ {
+ for i := uint32(0); i < i+1; i++ {
if _, ok := pool.m[i]; !ok {
return i, nil
}
@@ -188,4 +188,4 @@ func (pool *clientFidPool) String() string {
}
s += "}"
return s
-}
-\ No newline at end of file
+}
diff --git a/file.go b/file.go
@@ -46,7 +46,6 @@ type ReadDirFile interface {
ReadDir(n int) ([]*DirEntry, error)
}
-
type ClientFile struct {
name string
path string // must not contain trailing slash.
@@ -94,7 +93,7 @@ func (cf *ClientFile) Read(b []byte) (int, error) {
buf, err := cf.client.Read(context.TODO(), cf.fid.fid, cf.fid.offset, c)
var i int
for i = 0; i < len(buf); i++ {
- b[cur + i] = buf[i]
+ b[cur+i] = buf[i]
}
cf.fid.offset += uint64(i)
cur += i
diff --git a/fs.go b/fs.go
@@ -61,6 +61,7 @@ func FSModeToQidType(fm fs.FileMode) QidType {
// are not in QidType.
return qt
}
+
/*
func FSModeTo9Mode(mode fs.FileMode) FileMode {
mode9 := FileMode(mode & fs.ModePerm)
@@ -95,4 +96,4 @@ func Mode9ToFSMode(mode FileMode) fs.FileMode {
}
return fsmode
}
-*/
-\ No newline at end of file
+*/
diff --git a/qid_test.go b/qid_test.go
@@ -19,4 +19,4 @@ func TestQidMarshal(t *testing.T) {
t.Errorf("%s: got: %v, want: %v", test.name, got, test.qid)
}
}
-}
-\ No newline at end of file
+}
diff --git a/req.go b/req.go
@@ -7,16 +7,16 @@ import (
)
type Req struct {
- tag uint16
+ tag uint16
tagDeleted chan struct{}
- srv *Server
- ifcall Msg
- ofcall Msg
- fid *Fid
- afid *Fid
- oldReq *Req
- pool *ReqPool
- cancel context.CancelFunc
+ srv *Server
+ ifcall Msg
+ ofcall Msg
+ fid *Fid
+ afid *Fid
+ oldReq *Req
+ pool *ReqPool
+ cancel context.CancelFunc
}
func (r *Req) flush() {
@@ -47,7 +47,7 @@ func (rp *ReqPool) add(tag uint16) (*Req, error) {
return nil, ErrDupTag
}
req := &Req{
- pool: rp,
+ pool: rp,
tagDeleted: make(chan struct{}),
}
rp.m[tag] = req
diff --git a/server_test.go b/server_test.go
@@ -8,7 +8,6 @@ import (
"testing"
)
-
func newReq(s *Server, msg Msg) (*Req, error) {
r, err := s.rPool.add(msg.Tag())
if err != nil {
@@ -95,10 +94,10 @@ func TestServer(t *testing.T) {
fid: 0,
},
&TWalk{
- tag: 0,
- fid: 0,
+ tag: 0,
+ fid: 0,
newFid: 1,
- wname: []string{},
+ wname: []string{},
},
&TOpen{
tag: 0,
@@ -115,14 +114,14 @@ func TestServer(t *testing.T) {
fid: 1,
},
&TWalk{
- tag: 0,
- fid: 0,
+ tag: 0,
+ fid: 0,
newFid: 1,
- wname: []string{"dir", "file"},
+ wname: []string{"dir", "file"},
},
&TOpen{
- tag: 0,
- fid: 1,
+ tag: 0,
+ fid: 1,
mode: ORDWR,
},
&TRead{
diff --git a/stat.go b/stat.go
@@ -38,12 +38,12 @@ const (
)
type Stat struct {
- Type uint16
- Dev uint32
- Qid Qid
- Mode FileMode
- Atime uint32
- Mtime uint32
+ Type uint16
+ Dev uint32
+ Qid Qid
+ Mode FileMode
+ Atime uint32
+ Mtime uint32
//TODO: In 9P protocol Length is unsigned integer.
Length int64
Name string
@@ -168,14 +168,15 @@ type FileInfo struct {
Stat Stat
}
-func (fi *FileInfo) Name() string { return fi.Stat.Name }
-func (fi *FileInfo) Size() int64 { return fi.Stat.Length }
-func (fi *FileInfo) Mode() fs.FileMode { return fi.Stat.Mode }
-func (fi *FileInfo) ModTime() time.Time { return time.Unix(int64(fi.Stat.Mtime), 0) }
-func (fi *FileInfo) IsDir() bool { return fi.Stat.Mode&fs.ModeDir != 0 }
+func (fi *FileInfo) Name() string { return fi.Stat.Name }
+func (fi *FileInfo) Size() int64 { return fi.Stat.Length }
+func (fi *FileInfo) Mode() fs.FileMode { return fi.Stat.Mode }
+func (fi *FileInfo) ModTime() time.Time { return time.Unix(int64(fi.Stat.Mtime), 0) }
+func (fi *FileInfo) IsDir() bool { return fi.Stat.Mode&fs.ModeDir != 0 }
+
// Sys returns *Stat
-func (fi *FileInfo) Sys() any { return &fi.Stat }
-func (fi *FileInfo) Qid() Qid { return fi.Stat.Qid }
+func (fi *FileInfo) Sys() any { return &fi.Stat }
+func (fi *FileInfo) Qid() Qid { return fi.Stat.Qid }
type DirEntry = FileInfo
diff --git a/stat_test.go b/stat_test.go
@@ -7,7 +7,7 @@ import (
)
func TestStatMarshal(t *testing.T) {
- tests := []struct{
+ tests := []struct {
name string
stat *Stat
}{
@@ -22,4 +22,4 @@ func TestStatMarshal(t *testing.T) {
t.Errorf("%s: got: %v, want: %v", test.name, got, test.stat)
}
}
-}
-\ No newline at end of file
+}
diff --git a/test_fs.go b/test_fs.go
@@ -4,8 +4,8 @@ import (
"bytes"
"fmt"
"io/fs"
- "strings"
"path"
+ "strings"
)
type testFile struct {
@@ -15,7 +15,7 @@ type testFile struct {
content []byte
reader *bytes.Reader
- stat Stat
+ stat Stat
}
func (f *testFile) Stat() (*FileInfo, error) { return &FileInfo{Stat: f.stat}, nil }
@@ -48,7 +48,7 @@ func (f *testFile) WriteAt(p []byte, off int64) (int, error) {
return 0, fmt.Errorf("bad offset")
}
- if off + int64(len(p)) > int64(len(f.content)) {
+ if off+int64(len(p)) > int64(len(f.content)) {
newcon := make([]byte, off+int64(len(p)))
copy(newcon, f.content)
f.content = newcon
@@ -103,6 +103,7 @@ func split9path(path string) []string {
}
var fsys *testFS
+
func init() {
fsys = &testFS{
root: &testFile{
@@ -180,4 +181,3 @@ func setFsysAndParent(fsys *testFS, file *testFile) {
setFsysAndParent(fsys, child)
}
}
-
diff --git a/uid_test.go b/uid_test.go
@@ -12,14 +12,14 @@ type permFile struct {
gid string
}
-func (f permFile) Parent() (File, error) { return nil, nil }
+func (f permFile) Parent() (File, error) { return nil, nil }
func (f permFile) Child() ([]File, error) { return nil, nil }
func (f permFile) Stat() (*FileInfo, error) {
return &FileInfo{Stat: Stat{Mode: f.mode, Uid: f.uid, Gid: f.gid}}, nil
}
-func (f permFile) Qid() Qid { return Qid{} }
-func (f permFile) Open(mode OpenMode) error { return nil }
-func (f permFile) Close() error { return nil }
+func (f permFile) Qid() Qid { return Qid{} }
+func (f permFile) Open(mode OpenMode) error { return nil }
+func (f permFile) Close() error { return nil }
func (f permFile) Read(b []byte) (int, error) { return 0, io.EOF }
func TestHasPerm(t *testing.T) {
@@ -42,4 +42,4 @@ func TestHasPerm(t *testing.T) {
continue
}
}
-}
-\ No newline at end of file
+}