跳到主要内容

Claude Cage · 面向 Claude 的隔离开发环境,支持桌面工作台、多账号、远程部署与移动端连接。上游 Lee-xeo/Claude-Cage 完整源码镜像,非灵栈原创;主许可 MIT,第三方组件遵循各自许可。来源:https://github.com/Lee-xeo/Claude-Cage 。手动同步,不附带 Release 安装包。

浏览文件

fsync.go

73 行 · 2.2 KB历史下载
1package openssh
2
3import (
4 sshfx "github.com/pkg/sftp/internal/encoding/ssh/filexfer"
5)
6
7const extensionFSync = "[email protected]"
8
9// RegisterExtensionFSync registers the "[email protected]" extended packet with the encoding/ssh/filexfer package.
10func RegisterExtensionFSync() {
11 sshfx.RegisterExtendedPacketType(extensionFSync, func() sshfx.ExtendedData {
12 return new(FSyncExtendedPacket)
13 })
14}
15
16// ExtensionFSync returns an ExtensionPair suitable to append into an sshfx.InitPacket or sshfx.VersionPacket.
17func ExtensionFSync() *sshfx.ExtensionPair {
18 return &sshfx.ExtensionPair{
19 Name: extensionFSync,
20 Data: "1",
21 }
22}
23
24// FSyncExtendedPacket defines the [email protected] extend packet.
25type FSyncExtendedPacket struct {
26 Handle string
27}
28
29// Type returns the SSH_FXP_EXTENDED packet type.
30func (ep *FSyncExtendedPacket) Type() sshfx.PacketType {
31 return sshfx.PacketTypeExtended
32}
33
34// MarshalPacket returns ep as a two-part binary encoding of the full extended packet.
35func (ep *FSyncExtendedPacket) MarshalPacket(reqid uint32, b []byte) (header, payload []byte, err error) {
36 p := &sshfx.ExtendedPacket{
37 ExtendedRequest: extensionFSync,
38
39 Data: ep,
40 }
41 return p.MarshalPacket(reqid, b)
42}
43
44// MarshalInto encodes ep into the binary encoding of the [email protected] extended packet-specific data.
45func (ep *FSyncExtendedPacket) MarshalInto(buf *sshfx.Buffer) {
46 buf.AppendString(ep.Handle)
47}
48
49// MarshalBinary encodes ep into the binary encoding of the [email protected] extended packet-specific data.
50//
51// NOTE: This _only_ encodes the packet-specific data, it does not encode the full extended packet.
52func (ep *FSyncExtendedPacket) MarshalBinary() ([]byte, error) {
53 // string(handle)
54 size := 4 + len(ep.Handle)
55
56 buf := sshfx.NewBuffer(make([]byte, 0, size))
57 ep.MarshalInto(buf)
58 return buf.Bytes(), nil
59}
60
61// UnmarshalFrom decodes the [email protected] extended packet-specific data from buf.
62func (ep *FSyncExtendedPacket) UnmarshalFrom(buf *sshfx.Buffer) (err error) {
63 *ep = FSyncExtendedPacket{
64 Handle: buf.ConsumeString(),
65 }
66
67 return buf.Err
68}
69
70// UnmarshalBinary decodes the [email protected] extended packet-specific data into ep.
71func (ep *FSyncExtendedPacket) UnmarshalBinary(data []byte) (err error) {
72 return ep.UnmarshalFrom(sshfx.NewBuffer(data))
73}