mirror of
https://github.com/schollz/croc.git
synced 2025-10-11 13:21:00 +02:00
Merge pull request #38 from jesuiscamille/master
Allow receiving directories
This commit is contained in:
commit
c7698e5b86
1 changed files with 14 additions and 0 deletions
14
connect.go
14
connect.go
|
@ -42,6 +42,7 @@ type FileMetaData struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
crocReceiveDir = "croc_received"
|
||||||
tmpTarGzFileName = "to_send.tmp.tar.gz"
|
tmpTarGzFileName = "to_send.tmp.tar.gz"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -76,6 +77,7 @@ func NewConnection(flags *Flags) *Connection {
|
||||||
flags.File = tmpTarGzFileName
|
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)
|
c.File.Name = path.Base(tmpTarGzFileName)
|
||||||
} else {
|
} else {
|
||||||
|
@ -390,6 +392,18 @@ func (c *Connection) runClient() error {
|
||||||
fmt.Printf("\nReceived file written to %s\n", c.File.Name)
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue