Skip to content

Commit

Permalink
Merge pull request #84 from otiai10/feature/fix-78
Browse files Browse the repository at this point in the history
Skip device files by default: Use opt.Specials
  • Loading branch information
otiai10 committed Nov 9, 2022
2 parents b96fe43 + ae3e4ab commit 705b76e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
7 changes: 7 additions & 0 deletions all_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,13 @@ func TestOptions_Skip(t *testing.T) {
})
}

func TestOptions_Specials(t *testing.T) {
if runtime.GOOS == "linux" || runtime.GOOS == "darwin" {
err := Copy("/dev/null", "test/data.copy/dev-null", Options{Specials: false})
Expect(t, err).ToBe(nil)
}
}

func TestOptions_PermissionControl(t *testing.T) {
info, err := os.Stat("test/data/case07/dir_0555")
Expect(t, err).ToBe(nil)
Expand Down
5 changes: 5 additions & 0 deletions copy.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ func Copy(src, dest string, opt ...Options) error {
// switchboard switches proper copy functions regarding file type, etc...
// If there would be anything else here, add a case to this switchboard.
func switchboard(src, dest string, info os.FileInfo, opt Options) (err error) {

if info.Mode()&os.ModeDevice != 0 && !opt.Specials {
return err
}

switch {
case info.Mode()&os.ModeSymlink != 0:
err = onsymlink(src, dest, opt)
Expand Down
4 changes: 4 additions & 0 deletions options.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ type Options struct {
// Skip can specify which files should be skipped
Skip func(src string) (bool, error)

// Specials includes special files to be copied. default false.
Specials bool

// AddPermission to every entities,
// NO MORE THAN 0777
// @OBSOLETE
Expand Down Expand Up @@ -98,6 +101,7 @@ func getDefaultOptions(src, dest string) Options {
AddPermission: 0, // Add nothing
PermissionControl: PerservePermission, // Just preserve permission
Sync: false, // Do not sync
Specials: false, // Do not copy special files
PreserveTimes: false, // Do not preserve the modification time
CopyBufferSize: 0, // Do not specify, use default bufsize (32*1024)
WrapReader: nil, // Do not wrap src files, use them as they are.
Expand Down

0 comments on commit 705b76e

Please sign in to comment.