1package copy 2 3import "os" 4 5// Options specifies optional actions on copying. 6type Options struct { 7 8 // OnSymlink can specify what to do on symlink 9 OnSymlink func(src string) SymlinkAction 10 11 // OnDirExists can specify what to do when there is a directory already existing in destination. 12 OnDirExists func(src, dest string) DirExistsAction 13 14 // Skip can specify which files should be skipped 15 Skip func(src string) (bool, error) 16 17 // AddPermission to every entities, 18 // NO MORE THAN 0777 19 AddPermission os.FileMode 20 21 // Sync file after copy. 22 // Useful in case when file must be on the disk 23 // (in case crash happens, for example), 24 // at the expense of some performance penalty 25 Sync bool 26 27 // Preserve the atime and the mtime of the entries. 28 // On linux we can preserve only up to 1 millisecond accuracy. 29 PreserveTimes bool 30 31 // Preserve the uid and the gid of all entries. 32 PreserveOwner bool 33 34 // The byte size of the buffer to use for copying files. 35 // If zero, the internal default buffer of 32KB is used. 36 // See https://golang.org/pkg/io/#CopyBuffer for more information. 37 CopyBufferSize uint 38 39 intent struct { 40 src string 41 dest string 42 } 43} 44 45// SymlinkAction represents what to do on symlink. 46type SymlinkAction int 47 48const ( 49 // Deep creates hard-copy of contents. 50 Deep SymlinkAction = iota 51 // Shallow creates new symlink to the dest of symlink. 52 Shallow 53 // Skip does nothing with symlink. 54 Skip 55) 56 57// DirExistsAction represents what to do on dest dir. 58type DirExistsAction int 59 60const ( 61 // Merge preserves or overwrites existing files under the dir (default behavior). 62 Merge DirExistsAction = iota 63 // Replace deletes all contents under the dir and copy src files. 64 Replace 65 // Untouchable does nothing for the dir, and leaves it as it is. 66 Untouchable 67) 68 69// getDefaultOptions provides default options, 70// which would be modified by usage-side. 71func getDefaultOptions(src, dest string) Options { 72 return Options{ 73 OnSymlink: func(string) SymlinkAction { 74 return Shallow // Do shallow copy 75 }, 76 OnDirExists: nil, // Default behavior is "Merge". 77 Skip: func(string) (bool, error) { 78 return false, nil // Don't skip 79 }, 80 AddPermission: 0, // Add nothing 81 Sync: false, // Do not sync 82 PreserveTimes: false, // Do not preserve the modification time 83 CopyBufferSize: 0, // Do not specify, use default bufsize (32*1024) 84 intent: struct { 85 src string 86 dest string 87 }{src, dest}, 88 } 89} 90