mirror of
https://github.com/kovidgoyal/kitty
synced 2026-06-09 07:07:19 +02:00
Finish serialization of FTC
This commit is contained in:
@@ -214,45 +214,44 @@ func (self *FileTransmissionCommand) Serialize(prefix_with_osc_code ...bool) str
|
||||
found = true
|
||||
}
|
||||
for _, field := range fields {
|
||||
if name := field.Tag.Get("name"); name != "" {
|
||||
if name := field.Tag.Get("name"); name != "" && field.IsExported() {
|
||||
val := v.FieldByIndex(field.Index)
|
||||
encoded_val := ""
|
||||
switch val.Kind() {
|
||||
case reflect.String:
|
||||
sval := val.String()
|
||||
if sval != "" {
|
||||
if sval := val.String(); sval != "" {
|
||||
enc := field.Tag.Get("encoding")
|
||||
switch enc {
|
||||
case "base64":
|
||||
encoded_val = base64.StdEncoding.EncodeToString(utils.UnsafeStringToBytes(sval))
|
||||
encoded_val = base64.RawStdEncoding.EncodeToString(utils.UnsafeStringToBytes(sval))
|
||||
default:
|
||||
encoded_val = escape_semicolons(wcswidth.StripEscapeCodes(sval))
|
||||
}
|
||||
}
|
||||
case reflect.Slice:
|
||||
switch val.Elem().Type().Kind() {
|
||||
switch val.Type().Elem().Kind() {
|
||||
case reflect.Uint8:
|
||||
bval := val.Bytes()
|
||||
if len(bval) > 0 {
|
||||
encoded_val = base64.StdEncoding.EncodeToString(bval)
|
||||
if bval := val.Bytes(); len(bval) > 0 {
|
||||
encoded_val = base64.RawStdEncoding.EncodeToString(bval)
|
||||
}
|
||||
}
|
||||
case reflect.Uint64:
|
||||
encoded_val = strconv.FormatUint(val.Uint(), 10)
|
||||
if uival := val.Uint(); uival != 0 {
|
||||
encoded_val = strconv.FormatUint(uival, 10)
|
||||
}
|
||||
default:
|
||||
if val.CanInterface() {
|
||||
i := val.Interface()
|
||||
if field, ok := i.(Field); ok {
|
||||
switch field := val.Interface().(type) {
|
||||
case Field:
|
||||
if !field.IsDefault() {
|
||||
encoded_val = field.Serialize()
|
||||
}
|
||||
} else if field, ok := i.(time.Duration); ok {
|
||||
case time.Duration:
|
||||
if field != 0 {
|
||||
encoded_val = strconv.FormatInt(int64(field), 10)
|
||||
}
|
||||
} else if field, ok := i.(fs.FileMode); ok {
|
||||
field = field.Perm()
|
||||
if field != 0 {
|
||||
case fs.FileMode:
|
||||
if field = field.Perm(); field != 0 {
|
||||
encoded_val = strconv.FormatInt(int64(field), 10)
|
||||
}
|
||||
}
|
||||
|
||||
32
kittens/transfer/ftc_test.go
Normal file
32
kittens/transfer/ftc_test.go
Normal file
@@ -0,0 +1,32 @@
|
||||
// License: GPLv3 Copyright: 2023, Kovid Goyal, <kovid at kovidgoyal.net>
|
||||
|
||||
package transfer
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/google/go-cmp/cmp"
|
||||
)
|
||||
|
||||
var _ = fmt.Print
|
||||
|
||||
func TestFTCSerialization(t *testing.T) {
|
||||
ftc := FileTransmissionCommand{}
|
||||
q := func(expected string) {
|
||||
actual := ftc.Serialize()
|
||||
if diff := cmp.Diff(expected, actual); diff != "" {
|
||||
t.Fatalf("Failed to Serialize:\n%s", diff)
|
||||
}
|
||||
}
|
||||
q("")
|
||||
ftc.Action = Action_send
|
||||
q("ac=send")
|
||||
ftc.File_id = "fid"
|
||||
ftc.Name = "moose"
|
||||
ftc.Mtime = time.Second
|
||||
ftc.Permissions = 0o600
|
||||
ftc.Data = []byte("moose")
|
||||
q("ac=send;fid=fid;n=bW9vc2U;mod=1000000000;prm=384;d=bW9vc2U")
|
||||
}
|
||||
@@ -305,6 +305,10 @@ type SendManager struct {
|
||||
progress_tracker *ProgressTracker
|
||||
}
|
||||
|
||||
func (self *SendManager) start_transfer() string {
|
||||
panic("TODO: Implement this")
|
||||
}
|
||||
|
||||
func (self *SendManager) initialize() {
|
||||
if self.bypass != "" {
|
||||
self.bypass = encode_bypass(self.request_id, self.bypass)
|
||||
@@ -341,6 +345,11 @@ type SendHandler struct {
|
||||
progress_update_timer loop.IdType
|
||||
}
|
||||
|
||||
func (self *SendHandler) refresh_progress(timer_id loop.IdType) (err error) {
|
||||
self.progress_update_timer = 0
|
||||
panic("TODO: Implement this")
|
||||
}
|
||||
|
||||
func (self *SendHandler) schedule_progress_update(delay time.Duration) {
|
||||
if self.progress_update_timer != 0 {
|
||||
self.lp.RemoveTimer(self.progress_update_timer)
|
||||
@@ -370,12 +379,16 @@ func (self *SendHandler) send_payload(payload string) {
|
||||
self.lp.QueueWriteString(self.manager.suffix)
|
||||
}
|
||||
|
||||
func (self *SendHandler) send_file_metadata() error {
|
||||
panic("TODO: Implement this")
|
||||
}
|
||||
|
||||
func (self *SendHandler) initialize() error {
|
||||
self.manager.initialize()
|
||||
self.send_payload(self.manager.start_transfer())
|
||||
if self.opts.PermissionsBypass != "" {
|
||||
// dont wait for permission, not needed with a bypass and avoids a roundtrip
|
||||
self.send_file_metadata()
|
||||
return self.send_file_metadata()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -93,10 +93,10 @@ func TestPathMappingSend(t *testing.T) {
|
||||
f = first_file(filepath.Join(b, "s"), filepath.Join(b, "r"), "dest")
|
||||
ae(f.symbolic_link_target, "fid:2")
|
||||
f = first_file(filepath.Join(b, "h"), "dest")
|
||||
ae(f.file_type, REGULAR_FILE)
|
||||
ae(f.file_type, FileType_regular)
|
||||
file_idx = 1
|
||||
f = first_file(filepath.Join(b, "h"), filepath.Join(b, "r"), "dest")
|
||||
ae(f.hard_link_target, "1")
|
||||
ae(f.file_type, LINK_FILE)
|
||||
ae(f.file_type, FileType_link)
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user