Skip to content

Commit 06342e8

Browse files
authored
Merge pull request #583 from peterverraedt/marshal-extended-client
Add SetExtendedAttrs to Client
2 parents 6370888 + 478aa2e commit 06342e8

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

client.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -593,6 +593,20 @@ func (c *Client) Truncate(path string, size int64) error {
593593
return c.setstat(path, sshFileXferAttrSize, uint64(size))
594594
}
595595

596+
// SetExtendedData sets extended attributes of the named file. It uses the
597+
// SSH_FILEXFER_ATTR_EXTENDED flag in the setstat request.
598+
//
599+
// This flag provides a general extension mechanism for vendor-specific extensions.
600+
// Names of the attributes should be a string of the format "name@domain", where "domain"
601+
// is a valid, registered domain name and "name" identifies the method. Server
602+
// implementations SHOULD ignore extended data fields that they do not understand.
603+
func (c *Client) SetExtendedData(path string, extended []StatExtended) error {
604+
attrs := &FileStat{
605+
Extended: extended,
606+
}
607+
return c.setstat(path, sshFileXferAttrExtended, attrs)
608+
}
609+
596610
// Open opens the named file for reading. If successful, methods on the
597611
// returned file can be used for reading; the associated file descriptor
598612
// has mode O_RDONLY.
@@ -2044,6 +2058,28 @@ func (f *File) Chmod(mode os.FileMode) error {
20442058
return f.c.fsetstat(f.handle, sshFileXferAttrPermissions, toChmodPerm(mode))
20452059
}
20462060

2061+
// SetExtendedData sets extended attributes of the current file. It uses the
2062+
// SSH_FILEXFER_ATTR_EXTENDED flag in the setstat request.
2063+
//
2064+
// This flag provides a general extension mechanism for vendor-specific extensions.
2065+
// Names of the attributes should be a string of the format "name@domain", where "domain"
2066+
// is a valid, registered domain name and "name" identifies the method. Server
2067+
// implementations SHOULD ignore extended data fields that they do not understand.
2068+
func (f *File) SetExtendedData(path string, extended []StatExtended) error {
2069+
f.mu.RLock()
2070+
defer f.mu.RUnlock()
2071+
2072+
if f.handle == "" {
2073+
return os.ErrClosed
2074+
}
2075+
2076+
attrs := &FileStat{
2077+
Extended: extended,
2078+
}
2079+
2080+
return f.c.fsetstat(f.handle, sshFileXferAttrExtended, attrs)
2081+
}
2082+
20472083
// Truncate sets the size of the current file. Although it may be safely assumed
20482084
// that if the size is less than its current size it will be truncated to fit,
20492085
// the SFTP protocol does not specify what behavior the server should do when setting

0 commit comments

Comments
 (0)