Skip to content

Commit

Permalink
Add SetAttributes as an alternate option.
Browse files Browse the repository at this point in the history
This would replace the SetStat public function from the last commit.

Instead, this makes it practical to construct a Setstat request.

From some quick testing, this appears to do the job correctly, and it
feels like a lot less of hack.

It still doesn't feel entirely right, but it's closer.
  • Loading branch information
Zeph / Liz Loss-Cutler-Hull committed Oct 31, 2023
1 parent 7bf7a25 commit 6b2b978
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions request-attrs.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,37 @@ func newFileAttrFlags(flags uint32) FileAttrFlags {
}
}

func (r *Request) SetAttributes(flags FileAttrFlags, attrs FileStat) error {
r.Method = "Setstat"

buf := []byte{}

r.Flags = 0

if flags.Size {
r.Flags |= sshFileXferAttrSize
buf = marshalUint64(buf, attrs.Size)
}
if flags.UidGid {
r.Flags |= sshFileXferAttrUIDGID
buf = marshalUint32(buf, attrs.UID)
buf = marshalUint32(buf, attrs.GID)
}
if flags.Permissions {
r.Flags |= sshFileXferAttrPermissions
buf = marshalUint32(buf, attrs.Mode)
}

if flags.Acmodtime {
r.Flags |= sshFileXferAttrACmodTime
buf = marshalUint32(buf, attrs.Atime)
buf = marshalUint32(buf, attrs.Mtime)
}

r.Attrs = buf
return nil
}

// AttrFlags returns a FileAttrFlags boolean struct based on the
// bitmap/uint32 file attribute flags from the SFTP packaet.
func (r *Request) AttrFlags() FileAttrFlags {
Expand Down

0 comments on commit 6b2b978

Please sign in to comment.