0
0
Fork 0
mirror of https://github.com/schollz/croc.git synced 2025-10-11 13:21:00 +02:00

Bug fix: only send file name not file path

Fixes #32
This commit is contained in:
Zack Scholl 2017-10-21 12:45:44 -06:00
parent 3f34717a61
commit ed82893767

View file

@ -7,6 +7,7 @@ import (
"io" "io"
"net" "net"
"os" "os"
"path"
"strconv" "strconv"
"strings" "strings"
"sync" "sync"
@ -35,6 +36,7 @@ type FileMetaData struct {
Name string Name string
Size int Size int
Hash string Hash string
Path string
} }
func NewConnection(flags *Flags) *Connection { func NewConnection(flags *Flags) *Connection {
@ -47,7 +49,8 @@ func NewConnection(flags *Flags) *Connection {
c.NumberOfConnections = flags.NumberOfConnections c.NumberOfConnections = flags.NumberOfConnections
c.rate = flags.Rate c.rate = flags.Rate
if len(flags.File) > 0 { if len(flags.File) > 0 {
c.File.Name = flags.File c.File.Name = path.Base(flags.File)
c.File.Path = path.Dir(flags.File)
c.IsSender = true c.IsSender = true
} else { } else {
c.IsSender = false c.IsSender = false
@ -66,7 +69,7 @@ func NewConnection(flags *Flags) *Connection {
func (c *Connection) Run() error { func (c *Connection) Run() error {
forceSingleThreaded := false forceSingleThreaded := false
if c.IsSender { if c.IsSender {
fsize, err := FileSize(c.File.Name) fsize, err := FileSize(path.Join(c.File.Path, c.File.Name))
if err != nil { if err != nil {
return err return err
} }
@ -117,11 +120,11 @@ func (c *Connection) Run() error {
if c.IsSender { if c.IsSender {
if c.DontEncrypt { if c.DontEncrypt {
// don't encrypt // don't encrypt
CopyFile(c.File.Name, c.File.Name+".enc") CopyFile(path.Join(c.File.Path, c.File.Name), c.File.Name+".enc")
} else { } else {
// encrypt // encrypt
log.Debug("encrypting...") log.Debug("encrypting...")
if err := EncryptFile(c.File.Name, c.File.Name+".enc", c.Code); err != nil { if err := EncryptFile(path.Join(c.File.Path, c.File.Name), c.File.Name+".enc", c.Code); err != nil {
return err return err
} }
if err := SplitFile(c.File.Name+".enc", c.NumberOfConnections); err != nil { if err := SplitFile(c.File.Name+".enc", c.NumberOfConnections); err != nil {
@ -130,7 +133,7 @@ func (c *Connection) Run() error {
} }
// get file hash // get file hash
var err error var err error
c.File.Hash, err = HashFile(c.File.Name) c.File.Hash, err = HashFile(path.Join(c.File.Path, c.File.Name))
if err != nil { if err != nil {
return err return err
} }
@ -337,7 +340,7 @@ func (c *Connection) runClient() error {
if c.File.Hash != fileHash { if c.File.Hash != fileHash {
return fmt.Errorf("\nUh oh! %s is corrupted! Sorry, try again.\n", c.File.Name) return fmt.Errorf("\nUh oh! %s is corrupted! Sorry, try again.\n", c.File.Name)
} else { } else {
fmt.Printf("\nReceived file written to %s", c.File.Name) fmt.Printf("\nReceived file written to %s\n", c.File.Name)
} }
} }
return nil return nil