Skip to content

Commit

Permalink
add a private method to create a Request object
Browse files Browse the repository at this point in the history
the new method does not clean the received path, so we can use
this method internally and keep backward compatibility for the
public NewRequest method
  • Loading branch information
drakkan committed Mar 1, 2022
1 parent 616c993 commit e74f5a6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
8 changes: 4 additions & 4 deletions request-server.go
Expand Up @@ -247,7 +247,7 @@ func (rs *RequestServer) packetWorker(ctx context.Context, pktChan chan orderedR
if !ok {
rpkt = statusFromError(pkt.ID, EBADF)
} else {
request = NewRequest("Stat", cleanPathWithBase(rs.startDirectory, request.Filepath))
request = getRequest("Stat", cleanPathWithBase(rs.startDirectory, request.Filepath))
rpkt = request.call(rs.Handlers, pkt, rs.pktMgr.alloc, orderID)
}
case *sshFxpFsetstatPacket:
Expand All @@ -256,15 +256,15 @@ func (rs *RequestServer) packetWorker(ctx context.Context, pktChan chan orderedR
if !ok {
rpkt = statusFromError(pkt.ID, EBADF)
} else {
request = NewRequest("Setstat", cleanPathWithBase(rs.startDirectory, request.Filepath))
request = getRequest("Setstat", cleanPathWithBase(rs.startDirectory, request.Filepath))
rpkt = request.call(rs.Handlers, pkt, rs.pktMgr.alloc, orderID)
}
case *sshFxpExtendedPacketPosixRename:
request := NewRequest("PosixRename", cleanPathWithBase(rs.startDirectory, pkt.Oldpath))
request := getRequest("PosixRename", cleanPathWithBase(rs.startDirectory, pkt.Oldpath))
request.Target = cleanPathWithBase(rs.startDirectory, pkt.Newpath)
rpkt = request.call(rs.Handlers, pkt, rs.pktMgr.alloc, orderID)
case *sshFxpExtendedPacketStatVFS:
request := NewRequest("StatVFS", cleanPathWithBase(rs.startDirectory, pkt.Path))
request := getRequest("StatVFS", cleanPathWithBase(rs.startDirectory, pkt.Path))
rpkt = request.call(rs.Handlers, pkt, rs.pktMgr.alloc, orderID)
case hasHandle:
handle := pkt.getHandle()
Expand Down
8 changes: 6 additions & 2 deletions request.go
Expand Up @@ -142,9 +142,13 @@ type Request struct {

// NewRequest creates a new Request object.
func NewRequest(method, path string) *Request {
return getRequest(method, cleanPath(path))
}

func getRequest(method, cleanedPath string) *Request {
return &Request{
Method: method,
Filepath: path,
Filepath: cleanedPath,
}
}

Expand All @@ -170,7 +174,7 @@ func (r *Request) copy() *Request {
// New Request initialized based on packet data
func requestFromPacket(ctx context.Context, pkt hasPath, baseDir string) *Request {
method := requestMethod(pkt)
request := NewRequest(method, cleanPathWithBase(baseDir, pkt.getPath()))
request := getRequest(method, cleanPathWithBase(baseDir, pkt.getPath()))
request.ctx, request.cancelCtx = context.WithCancel(ctx)

switch p := pkt.(type) {
Expand Down

0 comments on commit e74f5a6

Please sign in to comment.