mirror of
https://github.com/kovidgoyal/kitty
synced 2026-07-25 09:48:09 +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
|
found = true
|
||||||
}
|
}
|
||||||
for _, field := range fields {
|
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)
|
val := v.FieldByIndex(field.Index)
|
||||||
encoded_val := ""
|
encoded_val := ""
|
||||||
switch val.Kind() {
|
switch val.Kind() {
|
||||||
case reflect.String:
|
case reflect.String:
|
||||||
sval := val.String()
|
if sval := val.String(); sval != "" {
|
||||||
if sval != "" {
|
|
||||||
enc := field.Tag.Get("encoding")
|
enc := field.Tag.Get("encoding")
|
||||||
switch enc {
|
switch enc {
|
||||||
case "base64":
|
case "base64":
|
||||||
encoded_val = base64.StdEncoding.EncodeToString(utils.UnsafeStringToBytes(sval))
|
encoded_val = base64.RawStdEncoding.EncodeToString(utils.UnsafeStringToBytes(sval))
|
||||||
default:
|
default:
|
||||||
encoded_val = escape_semicolons(wcswidth.StripEscapeCodes(sval))
|
encoded_val = escape_semicolons(wcswidth.StripEscapeCodes(sval))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case reflect.Slice:
|
case reflect.Slice:
|
||||||
switch val.Elem().Type().Kind() {
|
switch val.Type().Elem().Kind() {
|
||||||
case reflect.Uint8:
|
case reflect.Uint8:
|
||||||
bval := val.Bytes()
|
if bval := val.Bytes(); len(bval) > 0 {
|
||||||
if len(bval) > 0 {
|
encoded_val = base64.RawStdEncoding.EncodeToString(bval)
|
||||||
encoded_val = base64.StdEncoding.EncodeToString(bval)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case reflect.Uint64:
|
case reflect.Uint64:
|
||||||
encoded_val = strconv.FormatUint(val.Uint(), 10)
|
if uival := val.Uint(); uival != 0 {
|
||||||
|
encoded_val = strconv.FormatUint(uival, 10)
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
if val.CanInterface() {
|
if val.CanInterface() {
|
||||||
i := val.Interface()
|
switch field := val.Interface().(type) {
|
||||||
if field, ok := i.(Field); ok {
|
case Field:
|
||||||
if !field.IsDefault() {
|
if !field.IsDefault() {
|
||||||
encoded_val = field.Serialize()
|
encoded_val = field.Serialize()
|
||||||
}
|
}
|
||||||
} else if field, ok := i.(time.Duration); ok {
|
case time.Duration:
|
||||||
if field != 0 {
|
if field != 0 {
|
||||||
encoded_val = strconv.FormatInt(int64(field), 10)
|
encoded_val = strconv.FormatInt(int64(field), 10)
|
||||||
}
|
}
|
||||||
} else if field, ok := i.(fs.FileMode); ok {
|
case fs.FileMode:
|
||||||
field = field.Perm()
|
if field = field.Perm(); field != 0 {
|
||||||
if field != 0 {
|
|
||||||
encoded_val = strconv.FormatInt(int64(field), 10)
|
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
|
progress_tracker *ProgressTracker
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (self *SendManager) start_transfer() string {
|
||||||
|
panic("TODO: Implement this")
|
||||||
|
}
|
||||||
|
|
||||||
func (self *SendManager) initialize() {
|
func (self *SendManager) initialize() {
|
||||||
if self.bypass != "" {
|
if self.bypass != "" {
|
||||||
self.bypass = encode_bypass(self.request_id, self.bypass)
|
self.bypass = encode_bypass(self.request_id, self.bypass)
|
||||||
@@ -341,6 +345,11 @@ type SendHandler struct {
|
|||||||
progress_update_timer loop.IdType
|
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) {
|
func (self *SendHandler) schedule_progress_update(delay time.Duration) {
|
||||||
if self.progress_update_timer != 0 {
|
if self.progress_update_timer != 0 {
|
||||||
self.lp.RemoveTimer(self.progress_update_timer)
|
self.lp.RemoveTimer(self.progress_update_timer)
|
||||||
@@ -370,12 +379,16 @@ func (self *SendHandler) send_payload(payload string) {
|
|||||||
self.lp.QueueWriteString(self.manager.suffix)
|
self.lp.QueueWriteString(self.manager.suffix)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (self *SendHandler) send_file_metadata() error {
|
||||||
|
panic("TODO: Implement this")
|
||||||
|
}
|
||||||
|
|
||||||
func (self *SendHandler) initialize() error {
|
func (self *SendHandler) initialize() error {
|
||||||
self.manager.initialize()
|
self.manager.initialize()
|
||||||
self.send_payload(self.manager.start_transfer())
|
self.send_payload(self.manager.start_transfer())
|
||||||
if self.opts.PermissionsBypass != "" {
|
if self.opts.PermissionsBypass != "" {
|
||||||
// dont wait for permission, not needed with a bypass and avoids a roundtrip
|
// dont wait for permission, not needed with a bypass and avoids a roundtrip
|
||||||
self.send_file_metadata()
|
return self.send_file_metadata()
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -93,10 +93,10 @@ func TestPathMappingSend(t *testing.T) {
|
|||||||
f = first_file(filepath.Join(b, "s"), filepath.Join(b, "r"), "dest")
|
f = first_file(filepath.Join(b, "s"), filepath.Join(b, "r"), "dest")
|
||||||
ae(f.symbolic_link_target, "fid:2")
|
ae(f.symbolic_link_target, "fid:2")
|
||||||
f = first_file(filepath.Join(b, "h"), "dest")
|
f = first_file(filepath.Join(b, "h"), "dest")
|
||||||
ae(f.file_type, REGULAR_FILE)
|
ae(f.file_type, FileType_regular)
|
||||||
file_idx = 1
|
file_idx = 1
|
||||||
f = first_file(filepath.Join(b, "h"), filepath.Join(b, "r"), "dest")
|
f = first_file(filepath.Join(b, "h"), filepath.Join(b, "r"), "dest")
|
||||||
ae(f.hard_link_target, "1")
|
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