Merge pull request #38 from jesuiscamille/master

Allow receiving directories
This commit is contained in:
Zack 2017-10-22 09:26:08 -06:00 committed by GitHub
commit c7698e5b86
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
}