Skip to content

Instantly share code, notes, and snippets.

@DenBeke
DenBeke / copy.go
Created August 24, 2017 18:54 — forked from r0l1/copy.go
Copy a directory tree (preserving permissions) in Go.
// CopyFile copies the contents of the file named src to the file named
// by dst. The file will be created if it does not already exist. If the
// destination file exists, all it's contents will be replaced by the contents
// of the source file. The file mode will be copied from the source and
// the copied data is synced/flushed to stable storage.
func CopyFile(src, dst string) (err error) {
in, err := os.Open(src)
if err != nil {
return