Skip to content

Commit

Permalink
remove RealPathLister interface
Browse files Browse the repository at this point in the history
This is a backward incompatible change but the RealPathLister was useless:
even if you implement this interface you can customize the response for
SSH_FXP_REALPATH packets, but response for other packets still convert paths
using "/" as base
  • Loading branch information
drakkan committed Mar 2, 2022
1 parent e74f5a6 commit 0d10697
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 47 deletions.
13 changes: 2 additions & 11 deletions request-example.go
Expand Up @@ -464,19 +464,10 @@ func (fs *root) Lstat(r *Request) (ListerAt, error) {
return listerat{file}, nil
}

// implements RealpathFileLister interface
func (fs *root) Realpath(p string) string {
if fs.startDirectory == "" || fs.startDirectory == "/" {
return cleanPath(p)
}
return cleanPathWithBase(fs.startDirectory, p)
}

// In memory file-system-y thing that the Hanlders live on
type root struct {
rootFile *memFile
mockErr error
startDirectory string
rootFile *memFile
mockErr error

mu sync.Mutex
files map[string]*memFile
Expand Down
9 changes: 0 additions & 9 deletions request-interfaces.go
Expand Up @@ -86,15 +86,6 @@ type LstatFileLister interface {
Lstat(*Request) (ListerAt, error)
}

// RealPathFileLister is a FileLister that implements the Realpath method.
// We use "/" as start directory for relative paths, implementing this
// interface you can customize the start directory.
// You have to return an absolute POSIX path.
type RealPathFileLister interface {
FileLister
RealPath(string) string
}

// NameLookupFileLister is a FileLister that implmeents the LookupUsername and LookupGroupName methods.
// If this interface is implemented, then longname ls formatting will use these to convert usernames and groupnames.
type NameLookupFileLister interface {
Expand Down
8 changes: 1 addition & 7 deletions request-server.go
Expand Up @@ -218,13 +218,7 @@ func (rs *RequestServer) packetWorker(ctx context.Context, pktChan chan orderedR
handle := pkt.getHandle()
rpkt = statusFromError(pkt.ID, rs.closeRequest(handle))
case *sshFxpRealpathPacket:
var realPath string
if realPather, ok := rs.Handlers.FileList.(RealPathFileLister); ok {
realPath = realPather.RealPath(pkt.getPath())
} else {
realPath = cleanPathWithBase(rs.startDirectory, pkt.getPath())
}
rpkt = cleanPacketPath(pkt, realPath)
rpkt = cleanPacketPath(pkt, cleanPathWithBase(rs.startDirectory, pkt.getPath()))
case *sshFxpOpendirPacket:
request := requestFromPacket(ctx, pkt, rs.startDirectory)
handle := rs.nextRequest(request)
Expand Down
20 changes: 0 additions & 20 deletions request-server_test.go
Expand Up @@ -7,7 +7,6 @@ import (
"io/ioutil"
"net"
"os"
"path"
"runtime"
"testing"
"time"
Expand Down Expand Up @@ -809,25 +808,6 @@ func TestUncleanDisconnect(t *testing.T) {
checkRequestServerAllocator(t, p)
}

func TestRealPath(t *testing.T) {
root := &root{
rootFile: &memFile{name: "/", modtime: time.Now(), isdir: true},
files: make(map[string]*memFile),
startDirectory: "/apath",
}

p := root.Realpath(".")
assert.Equal(t, root.startDirectory, p)
p = root.Realpath("/")
assert.Equal(t, "/", p)
p = root.Realpath("..")
assert.Equal(t, "/", p)
p = root.Realpath("../../..")
assert.Equal(t, "/", p)
p = root.Realpath("relpath")
assert.Equal(t, path.Join(root.startDirectory, "relpath"), p)
}

func TestCleanPath(t *testing.T) {
assert.Equal(t, "/", cleanPath("/"))
assert.Equal(t, "/", cleanPath("."))
Expand Down

0 comments on commit 0d10697

Please sign in to comment.