10000 use correct param type instead of asserting · etherscan-io/sftp@048358f · GitHub
[go: up one dir, main page]

Skip to content

Commit 048358f

Browse files
committed
use correct param type instead of asserting
Instead of accepting a more general type and then asserting it to the proper type, just take the proper type as the argument. Also clean up some of the use of it where it checked old direct sending code's return error (error is now always nil).
1 parent 4cad28b commit 048358f

File tree

3 files changed

+7
-21
lines changed

3 files changed

+7
-21
lines changed

packet-typing.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ func (p sshFxpStatusPacket) id() uint32 { return p.ID }
7575
func (p sshFxpStatResponse) id() uint32 { return p.ID }
7676
func (p sshFxpNamePacket) id() uint32 { return p.ID }
7777
func (p sshFxpHandlePacket) id() uint32 { return p.ID }
78+
func (p StatVFS) id() uint32 { return p.ID }
7879
func (p sshFxVersionPacket) id() uint32 { return 0 }
7980

8081
// take raw incoming packet data and build packet objects

request-server.go

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package sftp
22

33
import (
44
"context"
5-
"encoding"
65
"io"
76
"os"
87
"path"
@@ -209,10 +208,7 @@ func (rs *RequestServer) packetWorker(
209208
return errors.Errorf("unexpected packet type %T", pkt)
210209
}
211210

212-
err := rs.sendPacket(rpkt)
213-
if err != nil {
214-
return err
215-
}
211+
rs.sendPacket(rpkt)
216212
}
217213
return nil
218214
}
@@ -246,11 +242,6 @@ func cleanPath(p string) string {
246242
}
247243

248244
// Wrap underlying connection methods to use packetManager
249-
func (rs *RequestServer) sendPacket(m encoding.BinaryMarshaler) error {
250-
if pkt, ok := m.(responsePacket); ok {
251-
rs.pktMgr.readyPacket(pkt)
252-
} else {
253-
return errors.Errorf("unexpected packet type %T", m)
254-
}
255-
return nil
245+
func (rs *RequestServer) sendPacket(pkt responsePacket) {
246+
rs.pktMgr.readyPacket(pkt)
256247
}

server.go

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,7 @@ func (svr *Server) sftpServerWorker(pktChan chan requestPacket) error {
140140
// If server is operating read-only and a write operation is requested,
141141
// return permission denied
142142
if !readonly && svr.readOnly {
143-
if err := svr.sendError(pkt, syscall.EPERM); err != nil {
144-
return errors.Wrap(err, "failed to send read only packet response")
145-
}
143+
svr.sendError(pkt, syscall.EPERM)
146144
continue
147145
}
148146

@@ -339,12 +337,8 @@ func (svr *Server) Serve() error {
339337
}
340338

341339
// Wrap underlying connection methods to use packetManager
342-
func (svr *Server) sendPacket(m encoding.BinaryMarshaler) error {
343-
if pkt, ok := m.(responsePacket); ok {
344-
svr.pktMgr.readyPacket(pkt)
345-
} else {
346-
return errors.Errorf("unexpected packet type %T", m)
347-
}
340+
func (svr *Server) sendPacket(pkt responsePacket) error {
341+
svr.pktMgr.readyPacket(pkt)
348342
return nil
349343
}
350344

0 commit comments

Comments
 (0)
0