Merge pull request #420 from greatroar/chmod-setfstat

Implement File.Chmod via setfstat
This commit is contained in:
Cassondra Foesch 2021-03-17 17:56:06 +00:00 committed by GitHub
commit c6518c34c4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 1 deletions

View File

@ -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.

View File

@ -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) {