// Copies the file at path src to path dst. // Returns the number of bytes written or an error if it occurred. func (gw *GhostWriter) copyFile(src string, dst string) (n int64, err error) { var ( fdst fauxfile.File fsrc fauxfile.File fi os.FileInfo ) if fsrc, err = gw.fs.Open(src); err != nil { return } defer func() { if err := fsrc.Close(); err != nil { gw.log.Printf("Problem closing %v: %v\n", src, err) } else { gw.log.Printf("Closed %v\n", src) } }() if fdst, err = gw.fs.Create(dst); err != nil { return } defer func() { if err := fdst.Close(); err != nil { gw.log.Printf("Problem closing %v: %v\n", dst, err) } else { gw.log.Printf("Closed %v\n", dst) } }() if fi, err = fsrc.Stat(); err != nil { return } fdst.Chmod(fi.Mode()) _, err = io.Copy(fdst, fsrc) return }