@ ls works phew

This commit is contained in:
Kovid Goyal
2022-08-25 14:08:27 +05:30
parent fa4711bd04
commit c86f8a698c
4 changed files with 43 additions and 6 deletions

View File

@@ -66,8 +66,22 @@ func get_pubkey(encoded_key string) (encryption_version string, pubkey []byte, e
return
}
func wrap_in_escape_code(data []byte) []byte {
const prefix = "\x1bP@kitty-cmd"
const suffix = "\x1b\\"
ans := make([]byte, len(prefix)+len(data)+len(suffix))
n := copy(ans, []byte(prefix))
n += copy(ans[n:], data)
copy(ans[n:], []byte(suffix))
return ans
}
func simple_serializer(rc *utils.RemoteControlCmd) (ans []byte, err error) {
ans, err = json.Marshal(rc)
if err != nil {
return
}
ans = wrap_in_escape_code(ans)
return
}
@@ -84,7 +98,14 @@ func create_serializer(password string, encoded_pubkey string, io_data *rc_io_da
}
io_data.serializer = func(rc *utils.RemoteControlCmd) (ans []byte, err error) {
ec, err := crypto.Encrypt_cmd(rc, global_options.password, pubkey, encryption_version)
if err != nil {
return
}
ans, err = json.Marshal(ec)
if err != nil {
return
}
ans = wrap_in_escape_code(ans)
return
}
if io_data.timeout < 120*time.Second {
@@ -159,6 +180,14 @@ func (self *rc_io_data) next_chunk(limit_size bool) (chunk []byte, err error) {
return
}
func single_rc_sender(rc *utils.RemoteControlCmd, serializer serializer_func) ([]byte, error) {
if rc.SingleSent() {
return make([]byte, 0), nil
}
rc.SetSingleSent()
return serializer(rc)
}
func get_response(do_io func(io_data *rc_io_data) ([]byte, error), io_data *rc_io_data) (ans *Response, err error) {
serialized_response, err := do_io(io_data)
if err != nil {
@@ -166,9 +195,7 @@ func get_response(do_io func(io_data *rc_io_data) ([]byte, error), io_data *rc_i
io_data.rc.Payload = nil
io_data.rc.CancelAsync = true
io_data.rc.NoResponse = true
io_data.next_block = func(rc *utils.RemoteControlCmd, serializer serializer_func) ([]byte, error) {
return serializer(rc)
}
io_data.next_block = single_rc_sender
_, err = do_io(io_data)
}
return
@@ -252,6 +279,10 @@ func get_password(password string, password_file string, password_env string, us
q, err = os.ReadFile(password_file)
if err == nil {
ans = strings.TrimRight(string(q), " \n\t")
} else {
if errors.Is(err, os.ErrNotExist) {
err = nil
}
}
}
if err != nil {