no need to double type switch

This commit is contained in:
Cassondra Foesch 2020-10-28 20:40:52 +00:00
parent fef2628887
commit afc8d7b11a
1 changed files with 5 additions and 9 deletions

View File

@ -314,9 +314,9 @@ func fileputget(h FileWriter, r *Request, pkt requestPacket, alloc *allocator, o
if writerReader == nil { if writerReader == nil {
return statusFromError(pkt, errors.New("unexpected write and read packet")) return statusFromError(pkt, errors.New("unexpected write and read packet"))
} }
switch pkt.(type) { switch p := pkt.(type) {
case *sshFxpReadPacket: case *sshFxpReadPacket:
data, offset, _ := packetData(pkt, alloc, orderID) data, offset := p.getDataSlice(alloc, orderID), int64(p.Offset)
n, err := writerReader.ReadAt(data, offset) n, err := writerReader.ReadAt(data, offset)
// only return EOF error if no data left to read // only return EOF error if no data left to read
if err != nil && (err != io.EOF || n == 0) { if err != nil && (err != io.EOF || n == 0) {
@ -328,7 +328,7 @@ func fileputget(h FileWriter, r *Request, pkt requestPacket, alloc *allocator, o
Data: data[:n], Data: data[:n],
} }
case *sshFxpWritePacket: case *sshFxpWritePacket:
data, offset, _ := packetData(pkt, alloc, orderID) data, offset := p.Data, int64(p.Offset)
_, err := writerReader.WriteAt(data, offset) _, err := writerReader.WriteAt(data, offset)
return statusFromError(pkt, err) return statusFromError(pkt, err)
default: default:
@ -340,13 +340,9 @@ func fileputget(h FileWriter, r *Request, pkt requestPacket, alloc *allocator, o
func packetData(p requestPacket, alloc *allocator, orderID uint32) (data []byte, offset int64, length uint32) { func packetData(p requestPacket, alloc *allocator, orderID uint32) (data []byte, offset int64, length uint32) {
switch p := p.(type) { switch p := p.(type) {
case *sshFxpReadPacket: case *sshFxpReadPacket:
length = p.Len return p.getDataSlice(alloc, orderID), int64(p.Offset), p.Len
offset = int64(p.Offset)
data = p.getDataSlice(alloc, orderID)
case *sshFxpWritePacket: case *sshFxpWritePacket:
data = p.Data return p.Data, int64(p.Offset), p.Length
length = p.Length
offset = int64(p.Offset)
} }
return return
} }