From 0d10697a917eb21821a4ea0fea79920332a22db0 Mon Sep 17 00:00:00 2001 From: Nicola Murino Date: Wed, 2 Mar 2022 11:08:36 +0100 Subject: [PATCH] remove RealPathLister interface 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 --- request-example.go | 13 ++----------- request-interfaces.go | 9 --------- request-server.go | 8 +------- request-server_test.go | 20 -------------------- 4 files changed, 3 insertions(+), 47 deletions(-) diff --git a/request-example.go b/request-example.go index ba22bcd0..ab6c675e 100644 --- a/request-example.go +++ b/request-example.go @@ -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 diff --git a/request-interfaces.go b/request-interfaces.go index c8c424c9..31699ede 100644 --- a/request-interfaces.go +++ b/request-interfaces.go @@ -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 { diff --git a/request-server.go b/request-server.go index 31301db3..b72ff645 100644 --- a/request-server.go +++ b/request-server.go @@ -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) diff --git a/request-server_test.go b/request-server_test.go index 88862fb0..eb1a5332 100644 --- a/request-server_test.go +++ b/request-server_test.go @@ -7,7 +7,6 @@ import ( "io/ioutil" "net" "os" - "path" "runtime" "testing" "time" @@ -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("."))