From 4320c6e10ad24906f24cd9346aad66b5976bb720 Mon Sep 17 00:00:00 2001 From: Sergey Matveev Date: Sun, 8 Jan 2017 18:35:58 +0300 Subject: [PATCH] Ability to omit destination path --- src/cypherpunks.ru/nncp/tx.go | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) 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) -- 2.48.1