sftpd: add SSH_FXP_FSETSTAT support

This change will fix file editing from sshfs, we need this patch

https://github.com/pkg/sftp/pull/373

for pkg/sftp to support this feature
This commit is contained in:
Nicola Murino
2020-08-20 13:54:36 +02:00
parent 933427310d
commit f41ce6619f
16 changed files with 222 additions and 45 deletions

View File

@@ -529,6 +529,30 @@ func TestSetStat(t *testing.T) {
Flags: StatAttrTimes,
})
assert.Error(t, err)
// truncate
err = c.SetStat(filepath.Join(user.GetHomeDir(), "missing"), "/missing", &StatAttributes{
Size: 1,
Flags: StatAttrSize,
})
assert.Error(t, err)
err = c.SetStat(filepath.Join(dir3, "afile.txt"), "/dir3/afile.txt", &StatAttributes{
Size: 1,
Flags: StatAttrSize,
})
assert.Error(t, err)
filePath := filepath.Join(user.GetHomeDir(), "afile.txt")
err = ioutil.WriteFile(filePath, []byte("hello"), os.ModePerm)
assert.NoError(t, err)
err = c.SetStat(filePath, "/afile.txt", &StatAttributes{
Flags: StatAttrSize,
Size: 1,
})
assert.NoError(t, err)
fi, err := os.Stat(filePath)
if assert.NoError(t, err) {
assert.Equal(t, int64(1), fi.Size())
}
err = os.RemoveAll(user.GetHomeDir())
assert.NoError(t, err)