Add resume support to mirroring

This commit is contained in:
Tony Blyler 2016-05-14 11:31:12 -04:00
parent 101a3ff39c
commit f6eb173a4f
No known key found for this signature in database
GPG key ID: 25C9D3A655D1A65C

View file

@ -247,12 +247,32 @@ func (c *Client) Mirror(path string, localParentPath string, resume bool) error
return err
}
localFile, err := os.OpenFile(localPath, os.O_RDWR|os.O_CREATE|os.O_TRUNC, c.config.FileMode)
flags := os.O_RDWR | os.O_CREATE
if resume {
flags |= os.O_APPEND
} else {
flags |= os.O_TRUNC
}
localFile, err := os.OpenFile(localPath, flags, c.config.FileMode)
if err != nil {
remoteFile.Close()
return err
}
if resume {
info, err := localFile.Stat()
if err != nil {
return err
}
_, err = remoteFile.Seek(info.Size(), 0)
if err != nil {
return err
}
}
_, err = io.Copy(localFile, remoteFile)
remoteFile.Close()
localFile.Close()