mirror of https://github.com/pkg/sftp.git
use ssh_FXP_STAT for Stat(); previously Stat() and Lstat() were both Lstat()
This commit is contained in:
parent
e84cc8c755
commit
7e2e721fdf
|
|
@ -465,6 +465,66 @@ func TestClientFileStat(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestClientStatLink(t *testing.T) {
|
||||
sftp, cmd := testClient(t, READONLY, NO_DELAY)
|
||||
defer cmd.Wait()
|
||||
defer sftp.Close()
|
||||
|
||||
f, err := ioutil.TempFile("", "sftptest")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer os.Remove(f.Name())
|
||||
|
||||
realName := f.Name()
|
||||
linkName := f.Name() + ".softlink"
|
||||
|
||||
// create a symlink that points at sftptest
|
||||
if err := os.Symlink(realName, linkName); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer os.Remove(linkName)
|
||||
|
||||
// compare Lstat of links
|
||||
wantLstat, err := os.Lstat(linkName)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
wantStat, err := os.Stat(linkName)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
gotLstat, err := sftp.Lstat(linkName)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
gotStat, err := sftp.Stat(linkName)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// check that stat is not lstat from os package
|
||||
if sameFile(wantLstat, wantStat) {
|
||||
t.Fatalf("Lstat / Stat(%q): both %#v %#v", f.Name(), wantLstat, wantStat)
|
||||
}
|
||||
|
||||
// compare Lstat of links
|
||||
if !sameFile(wantLstat, gotLstat) {
|
||||
t.Fatalf("Lstat(%q): want %#v, got %#v", f.Name(), wantLstat, gotLstat)
|
||||
}
|
||||
|
||||
// compare Stat of links
|
||||
if !sameFile(wantStat, gotStat) {
|
||||
t.Fatalf("Stat(%q): want %#v, got %#v", f.Name(), wantStat, gotStat)
|
||||
}
|
||||
|
||||
// check that stat is not lstat
|
||||
if sameFile(gotLstat, gotStat) {
|
||||
t.Fatalf("Lstat / Stat(%q): both %#v %#v", f.Name(), gotLstat, gotStat)
|
||||
}
|
||||
}
|
||||
|
||||
func TestClientRemove(t *testing.T) {
|
||||
sftp, cmd := testClient(t, READWRITE, NO_DELAY)
|
||||
defer cmd.Wait()
|
||||
|
|
|
|||
|
|
@ -318,7 +318,7 @@ type sshFxpStatPacket struct {
|
|||
func (p sshFxpStatPacket) id() uint32 { return p.ID }
|
||||
|
||||
func (p sshFxpStatPacket) MarshalBinary() ([]byte, error) {
|
||||
return marshalIDString(ssh_FXP_LSTAT, p.ID, p.Path)
|
||||
return marshalIDString(ssh_FXP_STAT, p.ID, p.Path)
|
||||
}
|
||||
|
||||
func (p *sshFxpStatPacket) UnmarshalBinary(b []byte) error {
|
||||
|
|
|
|||
Loading…
Reference in New Issue