mirror of
https://github.com/schollz/croc.git
synced 2025-10-11 13:21:00 +02:00
fix weird bug and remove tmp file after use
This commit is contained in:
parent
4a66db57f0
commit
0df9890b8b
1 changed files with 18 additions and 4 deletions
22
connect.go
22
connect.go
|
@ -41,6 +41,10 @@ type FileMetaData struct {
|
||||||
isDir bool
|
isDir bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const (
|
||||||
|
tmpTarGzFileName = "to_send.tmp.tar.gz"
|
||||||
|
)
|
||||||
|
|
||||||
func NewConnection(flags *Flags) *Connection {
|
func NewConnection(flags *Flags) *Connection {
|
||||||
c := new(Connection)
|
c := new(Connection)
|
||||||
c.Debug = flags.Debug
|
c.Debug = flags.Debug
|
||||||
|
@ -61,22 +65,23 @@ func NewConnection(flags *Flags) *Connection {
|
||||||
if info.Mode().IsDir() { // if our file is a dir
|
if info.Mode().IsDir() { // if our file is a dir
|
||||||
fmt.Print("The file you are trying to send is a directory; compressing...")
|
fmt.Print("The file you are trying to send is a directory; compressing...")
|
||||||
|
|
||||||
tmpFileName := "to_send.tmp.tar.gz"
|
|
||||||
// we "tarify" the file
|
// we "tarify" the file
|
||||||
err = tarinator.Tarinate([]string{flags.File}, tmpFileName)
|
err = tarinator.Tarinate([]string{flags.File}, tmpTarGzFileName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("Error! Please submit the following error to https://github.com/schollz/croc/issues:\n\n'%s'\n\n", err.Error())
|
fmt.Printf("Error! Please submit the following error to https://github.com/schollz/croc/issues:\n\n'%s'\n\n", err.Error())
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
// now, we change the target file name to match the new archive created
|
// now, we change the target file name to match the new archive created
|
||||||
flags.File = tmpFileName
|
flags.File = tmpTarGzFileName
|
||||||
// we set the value isDir to true
|
// we set the value isDir to true
|
||||||
c.File.isDir = true
|
c.File.isDir = true
|
||||||
fmt.Println("Done !")
|
fmt.Println("Done !")
|
||||||
|
c.File.Name = path.Base(tmpTarGzFileName)
|
||||||
|
} else {
|
||||||
|
c.File.Name = path.Base(flags.File)
|
||||||
}
|
}
|
||||||
|
|
||||||
c.File.Name = path.Base(flags.File)
|
|
||||||
c.File.Path = path.Dir(flags.File)
|
c.File.Path = path.Dir(flags.File)
|
||||||
c.IsSender = true
|
c.IsSender = true
|
||||||
} else {
|
} else {
|
||||||
|
@ -173,6 +178,14 @@ func (c *Connection) Run() error {
|
||||||
if err := os.Remove(c.File.Name + ".enc"); err != nil {
|
if err := os.Remove(c.File.Name + ".enc"); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// remove compressed archive
|
||||||
|
if c.File.isDir {
|
||||||
|
if err := os.Remove(tmpTarGzFileName); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fmt.Printf("Sending %d byte file named '%s'\n", c.File.Size, c.File.Name)
|
fmt.Printf("Sending %d byte file named '%s'\n", c.File.Size, c.File.Name)
|
||||||
fmt.Printf("Code is: %s\n", c.Code)
|
fmt.Printf("Code is: %s\n", c.Code)
|
||||||
}
|
}
|
||||||
|
@ -374,6 +387,7 @@ func (c *Connection) runClient() error {
|
||||||
} else {
|
} else {
|
||||||
fmt.Printf("\nReceived file written to %s\n", c.File.Name)
|
fmt.Printf("\nReceived file written to %s\n", c.File.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue