receive directories to \'croc_received\'

This commit is contained in:
Camille Eyriès 2017-10-22 12:14:46 +02:00
parent 94a4b23bae
commit b8d2e1bede
1 changed files with 14 additions and 0 deletions

View File

@ -42,6 +42,7 @@ type FileMetaData struct {
}
const (
crocReceiveDir = "croc_received"
tmpTarGzFileName = "to_send.tmp.tar.gz"
)
@ -76,6 +77,7 @@ func NewConnection(flags *Flags) *Connection {
flags.File = tmpTarGzFileName
// we set the value IsDir to true
c.File.IsDir = true
fmt.Println("Done !")
c.File.Name = path.Base(tmpTarGzFileName)
} else {
@ -390,6 +392,18 @@ func (c *Connection) runClient() error {
fmt.Printf("\nReceived file written to %s\n", c.File.Name)
}
if c.File.IsDir { // if the file was originally a dir
fmt.Print("Since the receive file was originally a directory, uncompressing... ")
tarinator.UnTarinate(crocReceiveDir, tmpTarGzFileName)
fmt.Println("Done !\nDirectory written into " + crocReceiveDir)
// we remove the old tar.gz file
err := os.RemoveAll(tmpTarGzFileName)
if err != nil {
log.Error(err)
}
}
}
return nil
}