Merge pull request #54 from otiai10/fix/preservetimes

Do not preserve times when Untouchable
tree: 2c3893db32c5beae11014b118ca45e2acf916022
  1. .github/
  2. test/
  3. .gitignore
  4. all_test.go
  5. copy.go
  6. copy_namedpipes.go
  7. copy_namedpipes_windows.go
  8. example_test.go
  9. go.mod
  10. go.sum
  11. LICENSE
  12. options.go
  13. patherror_go1.15_test.go
  14. patherror_go1.16_test.go
  15. preserve_times.go
  16. README.md
  17. stat_times.go
  18. stat_times_darwin.go
  19. stat_times_freebsd.go
  20. stat_times_windows.go
  21. test_setup.go
  22. test_setup_windows.go
README.md

copy

Go Reference Actions Status codecov License: MIT Go Report Card GitHub tag (latest SemVer)

copy copies directories recursively.

Example Usage

err := Copy("your/directory", "your/directory.copy")

Advanced Usage

// Options specifies optional actions on copying.
type Options struct {

	// OnSymlink can specify what to do on symlink
	OnSymlink func(src string) SymlinkAction

	// OnDirExists can specify what to do when there is a directory already existing in destination.
	OnDirExists func(src, dest string) DirExistsAction

	// Skip can specify which files should be skipped
	Skip func(src string) (bool, error)

	// AddPermission to every entities,
	// NO MORE THAN 0777
	AddPermission os.FileMode

	// Sync file after copy.
	// Useful in case when file must be on the disk
	// (in case crash happens, for example),
	// at the expense of some performance penalty
	Sync bool

	// Preserve the atime and the mtime of the entries
	// On linux we can preserve only up to 1 millisecond accuracy
	PreserveTimes bool

}
// For example...
opt := Options{
	Skip: func(src string) {
		return strings.HasSuffix(src, ".git")
	},
}
err := Copy("your/directory", "your/directory.copy", opt)

Issues