lib9p

Go 9P library.
Log | Files | Refs | LICENSE

commit ae000ecdadca76c8206f5451f980f4b173d8f568
parent e9ee50f736c593762580dec92f9d4f2e8c2a401a
Author: Matsuda Kenji <info@mtkn.jp>
Date:   Wed, 10 Jan 2024 16:33:44 +0900

review

Diffstat:
Mserver.go | 28++++++++++++++--------------
1 file changed, 14 insertions(+), 14 deletions(-)

diff --git a/server.go b/server.go @@ -623,7 +623,6 @@ func sCreate(ctx context.Context, c *conn, rc <-chan *request) { st fs.FileInfo dirstat fs.FileInfo err error - file File cfs CreaterFS cpath string perm FileMode @@ -665,12 +664,11 @@ func sCreate(ctx context.Context, c *conn, rc <-chan *request) { perm &= ^FileMode(0777) | (dirperm & FileMode(0777)) } cpath = path.Join(r.fid.path, ifcall.Name) - file, err = cfs.Create(cpath, r.fid.uid, ifcall.Mode, perm) + r.fid.file, err = cfs.Create(cpath, r.fid.uid, ifcall.Mode, perm) if err != nil { r.err = fmt.Errorf("create: %v", err) goto resp } - r.fid.file = file r.fid.path = cpath r.fid.omode = ifcall.Mode st, err = r.fid.file.Stat() @@ -703,6 +701,9 @@ func sRead(ctx context.Context, c *conn, rc <-chan *request) { case <-ctx.Done(): return case r, ok := <-rc: + if !ok { + return + } var ( fi fs.FileInfo err error @@ -710,9 +711,6 @@ func sRead(ctx context.Context, c *conn, rc <-chan *request) { done chan struct{} n int ) - if !ok { - return - } ifcall := r.ifcall.(*TRead) r.fid, ok = c.fPool.lookup(ifcall.Fid) if !ok { @@ -732,6 +730,9 @@ func sRead(ctx context.Context, c *conn, rc <-chan *request) { r.err = fmt.Errorf("stat: %v", err) goto resp } + if c.mSize() - IOHDRSZ < ifcall.Count { + ifcall.Count = c.mSize() - IOHDRSZ + } data = make([]byte, ifcall.Count) done = make(chan struct{}) go func() { @@ -779,14 +780,13 @@ func sRead(ctx context.Context, c *conn, rc <-chan *request) { r.fid.dirOffset += uint64(n) r.fid.dirIndex += k } else { - var err error if reader, ok := r.fid.file.(io.ReaderAt); ok { n, err = reader.ReadAt(data, int64(ifcall.Offset)) } else { n, err = r.fid.file.Read(data) } - if err != io.EOF && err != nil { - return + if err == io.EOF { + err = nil } } }() @@ -840,7 +840,7 @@ func sWrite(ctx context.Context, c *conn, rc <-chan *request) { r.err = ErrUnknownFid goto resp } - if ifcall.Count > c.mSize()-IOHDRSZ { + if c.mSize()-IOHDRSZ < ifcall.Count { ifcall.Count = c.mSize() - IOHDRSZ } omode = r.fid.omode & 3 @@ -906,14 +906,14 @@ func sClunk(ctx context.Context, c *conn, rc <-chan *request) { return } ifcall := r.ifcall.(*TClunk) - fid, ok := c.fPool.lookup(ifcall.Fid) + r.fid, ok = c.fPool.lookup(ifcall.Fid) if !ok { r.err = ErrUnknownFid goto resp } c.fPool.delete(ifcall.Fid) - if fid.omode != -1 { - if err := fid.file.Close(); err != nil { + if r.fid.omode != -1 { + if err := r.fid.file.Close(); err != nil { r.err = fmt.Errorf("close: %v", err) goto resp } @@ -972,7 +972,7 @@ func sRemove(ctx context.Context, c *conn, rc <-chan *request) { r.err = ErrOperation goto resp } - // TODO: this assumes the file can be identified by its path. + // TODO: this assumes files can be identified by its path. // I think the argument of RemoverFS.Remove should be Qid.Path. if err = rfs.Remove(r.fid.path); err != nil { r.err = fmt.Errorf("remove: %v", err)