Start work on porting the transfer kitten to Go

This commit is contained in:
Kovid Goyal
2023-04-27 15:40:26 +05:30
parent 02c9205061
commit 7cec9016d3
5 changed files with 68 additions and 1 deletions

62
kittens/transfer/main.go Normal file
View File

@@ -0,0 +1,62 @@
// License: GPLv3 Copyright: 2023, Kovid Goyal, <kovid at kovidgoyal.net>
package transfer
import (
"fmt"
"io"
"os"
"strconv"
"strings"
"kitty/tools/cli"
"kitty/tools/utils"
)
var _ = fmt.Print
func read_bypass(loc string) (string, error) {
if loc == "" {
return "", nil
}
fdnum, err := strconv.Atoi(loc)
if err == nil && fdnum >= 0 && fdnum < 256 && loc[0] >= '0' && loc[0] <= '9' {
file := os.NewFile(uintptr(fdnum), loc)
defer file.Close()
raw, err := io.ReadAll(file)
return utils.UnsafeBytesToString(raw), err
}
if loc == "-" {
raw, err := io.ReadAll(os.Stdin)
defer os.Stdin.Close()
return utils.UnsafeBytesToString(raw), err
}
switch loc[0] {
case '.', '~', '/':
if loc[0] == '~' {
loc = utils.Expanduser(loc)
}
raw, err := os.ReadFile(loc)
return utils.UnsafeBytesToString(raw), err
default:
return loc, nil
}
}
func main(cmd *cli.Command, opts *Options, args []string) (rc int, err error) {
if err != nil {
rc = 1
}
if opts.PermissionsBypass != "" {
val, err := read_bypass(opts.PermissionsBypass)
if err != nil {
return 1, err
}
opts.PermissionsBypass = strings.TrimSpace(val)
}
return
}
func EntryPoint(parent *cli.Command) {
create_cmd(parent, main)
}

View File

@@ -102,3 +102,4 @@ elif __name__ == '__doc__':
cd['usage'] = usage
cd['options'] = option_text
cd['help_text'] = help_text
cd['short_desc'] = help_text

View File

@@ -1,3 +1,4 @@
//go:build exclude
/*
* rsync.c
* Copyright (C) 2021 Kovid Goyal <kovid at kovidgoyal.net>