Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bug] PosixRename and Hardlink don’t convert remote paths to local paths #492

Merged
merged 3 commits into from Feb 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 19 additions & 2 deletions client_integration_test.go
Expand Up @@ -19,6 +19,7 @@ import (
"path/filepath"
"reflect"
"regexp"
"runtime"
"sort"
"strconv"
"sync"
Expand Down Expand Up @@ -359,7 +360,7 @@ func TestClientOpenIsNotExist(t *testing.T) {
defer cmd.Wait()
defer sftp.Close()

if _, err := sftp.Open("/doesnt/exist/"); !os.IsNotExist(err) {
if _, err := sftp.Open("/doesnt/exist"); !os.IsNotExist(err) {
t.Errorf("os.IsNotExist(%v) = false, want true", err)
}
}
Expand All @@ -369,7 +370,7 @@ func TestClientStatIsNotExist(t *testing.T) {
defer cmd.Wait()
defer sftp.Close()

if _, err := sftp.Stat("/doesnt/exist/"); !os.IsNotExist(err) {
if _, err := sftp.Stat("/doesnt/exist"); !os.IsNotExist(err) {
t.Errorf("os.IsNotExist(%v) = false, want true", err)
}
}
Expand Down Expand Up @@ -758,6 +759,11 @@ func TestClientGetwd(t *testing.T) {
}

func TestClientReadLink(t *testing.T) {
if runtime.GOOS == "windows" && *testServerImpl {
// os.Symlink requires privilege escalation.
t.Skip()
}

sftp, cmd := testClient(t, READWRITE, NODELAY)
defer cmd.Wait()
defer sftp.Close()
Expand Down Expand Up @@ -810,6 +816,11 @@ func TestClientLink(t *testing.T) {
}

func TestClientSymlink(t *testing.T) {
if runtime.GOOS == "windows" && *testServerImpl {
// os.Symlink requires privilege escalation.
t.Skip()
}

sftp, cmd := testClient(t, READWRITE, NODELAY)
defer cmd.Wait()
defer sftp.Close()
Expand Down Expand Up @@ -1600,6 +1611,7 @@ func clientWriteDeadlock(t *testing.T, N int, badfunc func(*File)) {
if !*testServerImpl {
t.Skipf("skipping without -testserver")
}

sftp, cmd := testClient(t, READWRITE, NODELAY)
defer cmd.Wait()
defer sftp.Close()
Expand Down Expand Up @@ -2241,18 +2253,23 @@ func TestServerRoughDisconnectEOF(t *testing.T) {
// sftp/issue/26 writing to a read only file caused client to loop.
func TestClientWriteToROFile(t *testing.T) {
skipIfWindows(t)

sftp, cmd := testClient(t, READWRITE, NODELAY)
defer cmd.Wait()

defer func() {
err := sftp.Close()
assert.NoError(t, err)
}()

// TODO (puellanivis): /dev/zero is not actually a read-only file.
// So, this test works purely by accident.
f, err := sftp.Open("/dev/zero")
if err != nil {
t.Fatal(err)
}
defer f.Close()

_, err = f.Write([]byte("hello"))
if err == nil {
t.Fatal("expected error, got", err)
Expand Down
4 changes: 2 additions & 2 deletions packet.go
Expand Up @@ -1242,7 +1242,7 @@ func (p *sshFxpExtendedPacketPosixRename) UnmarshalBinary(b []byte) error {
}

func (p *sshFxpExtendedPacketPosixRename) respond(s *Server) responsePacket {
err := os.Rename(p.Oldpath, p.Newpath)
err := os.Rename(toLocalPath(p.Oldpath), toLocalPath(p.Newpath))
return statusFromError(p.ID, err)
}

Expand Down Expand Up @@ -1271,6 +1271,6 @@ func (p *sshFxpExtendedPacketHardlink) UnmarshalBinary(b []byte) error {
}

func (p *sshFxpExtendedPacketHardlink) respond(s *Server) responsePacket {
err := os.Link(p.Oldpath, p.Newpath)
err := os.Link(toLocalPath(p.Oldpath), toLocalPath(p.Newpath))
return statusFromError(p.ID, err)
}