Skip to content

Commit

Permalink
request: add raw paths
Browse files Browse the repository at this point in the history
  • Loading branch information
drakkan committed Feb 24, 2022
1 parent aa9a37d commit 41bbb8c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 16 deletions.
3 changes: 2 additions & 1 deletion request-server.go
Expand Up @@ -249,7 +249,8 @@ func (rs *RequestServer) packetWorker(ctx context.Context, pktChan chan orderedR
}
case *sshFxpExtendedPacketPosixRename:
request := NewRequest("PosixRename", pkt.Oldpath)
request.Target = pkt.Newpath
request.RawTarget = pkt.Newpath
request.Target = cleanPath(pkt.Newpath)
rpkt = request.call(rs.Handlers, pkt, rs.pktMgr.alloc, orderID)
case *sshFxpExtendedPacketStatVFS:
request := NewRequest("StatVFS", pkt.Path)
Expand Down
40 changes: 25 additions & 15 deletions request.go
Expand Up @@ -127,10 +127,14 @@ type Request struct {
// Rmdir, Mkdir, List, Readlink, Link, Symlink
Method string
Filepath string
Flags uint32
Attrs []byte // convert to sub-struct
Target string // for renames and sym-links
handle string
// raw file path as sent by the SFTP client
RawFilepath string
Flags uint32
Attrs []byte // convert to sub-struct
Target string // for renames and sym-links
// raw target path as sent by the SFTP client
RawTarget string
handle string

// reader/writer/readdir from handlers
state
Expand All @@ -143,8 +147,9 @@ type Request struct {
// NewRequest creates a new Request object.
func NewRequest(method, path string) *Request {
return &Request{
Method: method,
Filepath: cleanPath(path),
Method: method,
Filepath: cleanPath(path),
RawFilepath: path,
}
}

Expand All @@ -153,12 +158,14 @@ func NewRequest(method, path string) *Request {
// because we have to copy around the mutex in state.
func (r *Request) copy() *Request {
return &Request{
Method: r.Method,
Filepath: r.Filepath,
Flags: r.Flags,
Attrs: r.Attrs,
Target: r.Target,
handle: r.handle,
Method: r.Method,
Filepath: r.Filepath,
RawFilepath: r.RawFilepath,
Flags: r.Flags,
Attrs: r.Attrs,
Target: r.Target,
RawTarget: r.RawTarget,
handle: r.handle,

state: r.state.copy(),

Expand All @@ -180,12 +187,15 @@ func requestFromPacket(ctx context.Context, pkt hasPath) *Request {
request.Flags = p.Flags
request.Attrs = p.Attrs.([]byte)
case *sshFxpRenamePacket:
request.RawTarget = p.Newpath
request.Target = cleanPath(p.Newpath)
case *sshFxpSymlinkPacket:
// NOTE: given a POSIX compliant signature: symlink(target, linkpath string)
// this makes Request.Target the linkpath, and Request.Filepath the target.
request.RawTarget = p.Linkpath
request.Target = cleanPath(p.Linkpath)
case *sshFxpExtendedPacketHardlink:
request.RawTarget = p.Newpath
request.Target = cleanPath(p.Newpath)
}
return request
Expand Down Expand Up @@ -355,7 +365,7 @@ func (r *Request) opendir(h Handlers, pkt requestPacket) responsePacket {
r.Method = "List"
la, err := h.FileList.Filelist(r)
if err != nil {
return statusFromError(pkt.id(), wrapPathError(r.Filepath, err))
return statusFromError(pkt.id(), wrapPathError(r.RawFilepath, err))
}

r.setListerAt(la)
Expand Down Expand Up @@ -558,7 +568,7 @@ func filestat(h FileLister, r *Request, pkt requestPacket) responsePacket {
if n == 0 {
err = &os.PathError{
Op: strings.ToLower(r.Method),
Path: r.Filepath,
Path: r.RawFilepath,
Err: syscall.ENOENT,
}
return statusFromError(pkt.id(), err)
Expand All @@ -574,7 +584,7 @@ func filestat(h FileLister, r *Request, pkt requestPacket) responsePacket {
if n == 0 {
err = &os.PathError{
Op: "readlink",
Path: r.Filepath,
Path: r.RawFilepath,
Err: syscall.ENOENT,
}
return statusFromError(pkt.id(), err)
Expand Down

0 comments on commit 41bbb8c

Please sign in to comment.