From: Sergey Matveev Date: Sun, 8 Jan 2017 15:35:58 +0000 (+0300) Subject: Ability to omit destination path X-Git-Tag: 0.1~14 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=4320c6e10ad24906f24cd9346aad66b5976bb720;p=nncp.git Ability to omit destination path --- diff --git a/src/cypherpunks.ru/nncp/tx.go b/src/cypherpunks.ru/nncp/tx.go index 799ddca..03e2df2 100644 --- a/src/cypherpunks.ru/nncp/tx.go +++ b/src/cypherpunks.ru/nncp/tx.go @@ -25,7 +25,6 @@ import ( "errors" "io" "os" - "path" "path/filepath" "strconv" "strings" @@ -98,8 +97,11 @@ func (ctx *Ctx) Tx(node *Node, pkt *Pkt, nice uint8, size int64, src io.Reader) } func (ctx *Ctx) TxFile(node *Node, nice uint8, srcPath, dstPath string) error { - dstPath = path.Clean(dstPath) - if path.IsAbs(dstPath) { + if dstPath == "" { + dstPath = filepath.Base(srcPath) + } + dstPath = filepath.Clean(dstPath) + if filepath.IsAbs(dstPath) { return errors.New("Relative destination path required") } pkt, err := NewPkt(PktTypeFile, dstPath) @@ -140,12 +142,12 @@ func (ctx *Ctx) TxFile(node *Node, nice uint8, srcPath, dstPath string) error { } func (ctx *Ctx) TxFreq(node *Node, nice uint8, srcPath, dstPath string) error { - dstPath = path.Clean(dstPath) - if path.IsAbs(dstPath) { + dstPath = filepath.Clean(dstPath) + if filepath.IsAbs(dstPath) { return errors.New("Relative destination path required") } - srcPath = path.Clean(srcPath) - if path.IsAbs(srcPath) { + srcPath = filepath.Clean(srcPath) + if filepath.IsAbs(srcPath) { return errors.New("Relative source path required") } pkt, err := NewPkt(PktTypeFreq, srcPath)