mirror of https://github.com/pkg/sftp.git
Merge pull request #420 from greatroar/chmod-setfstat
Implement File.Chmod via setfstat
This commit is contained in:
commit
c6518c34c4
|
@ -1721,7 +1721,7 @@ func (f *File) Chown(uid, gid int) error {
|
|||
//
|
||||
// See Client.Chmod for details.
|
||||
func (f *File) Chmod(mode os.FileMode) error {
|
||||
return f.c.Chmod(f.path, mode)
|
||||
return f.c.setfstat(f.handle, sshFileXferAttrPermissions, toChmodPerm(mode))
|
||||
}
|
||||
|
||||
// Sync requests a flush of the contents of a File to stable storage.
|
||||
|
|
|
@ -853,6 +853,15 @@ func TestClientChmod(t *testing.T) {
|
|||
} else if stat.Mode()&os.ModePerm != 0531 {
|
||||
t.Fatalf("invalid perm %o\n", stat.Mode())
|
||||
}
|
||||
|
||||
sf, err := sftp.Open(f.Name())
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, sf.Chmod(0500))
|
||||
sf.Close()
|
||||
|
||||
stat, err := os.Stat(f.Name())
|
||||
require.NoError(t, err)
|
||||
require.EqualValues(t, 0500, stat.Mode())
|
||||
}
|
||||
|
||||
func TestClientChmodReadonly(t *testing.T) {
|
||||
|
|
Loading…
Reference in New Issue