Skip to content

Commit

Permalink
add fileinfo to skip function
Browse files Browse the repository at this point in the history
  • Loading branch information
tongjingran committed Dec 23, 2020
1 parent 2db1023 commit 255df98
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions all_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ func TestOptions_OnSymlink(t *testing.T) {
}

func TestOptions_Skip(t *testing.T) {
opt := Options{Skip: func(src string) (bool, error) {
opt := Options{Skip: func(src string, info os.FileInfo) (bool, error) {
switch {
case strings.HasSuffix(src, "_skip"):
return true, nil
Expand Down Expand Up @@ -186,7 +186,7 @@ func TestOptions_Skip(t *testing.T) {

Because(t, "if Skip func returns error, Copy should be interrupted", func(t *testing.T) {
errInsideSkipFunc := errors.New("Something wrong inside Skip")
opt := Options{Skip: func(src string) (bool, error) {
opt := Options{Skip: func(src string, info os.FileInfo) (bool, error) {
return false, errInsideSkipFunc
}}
err := Copy("testdata/case06", "testdata.copy/case06.01", opt)
Expand Down
2 changes: 1 addition & 1 deletion copy.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func switchboard(src, dest string, info os.FileInfo, opt Options) (err error) {
// Because this "copy" could be called recursively,
// "info" MUST be given here, NOT nil.
func copy(src, dest string, info os.FileInfo, opt Options) error {
skip, err := opt.Skip(src)
skip, err := opt.Skip(src, info)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func ExampleOptions() {
"testdata/example",
"testdata.copy/example_with_options",
Options{
Skip: func(src string) (bool, error) {
Skip: func(src string, info os.FileInfo) (bool, error) {
return strings.HasSuffix(src, ".git-like"), nil
},
OnSymlink: func(src string) SymlinkAction {
Expand Down
4 changes: 2 additions & 2 deletions options.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ type Options struct {
OnDirExists func(src, dest string) DirExistsAction

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

// AddPermission to every entities,
// NO MORE THAN 0777
Expand Down Expand Up @@ -66,7 +66,7 @@ func getDefaultOptions(src, dest string) Options {
return Shallow // Do shallow copy
},
OnDirExists: nil, // Default behavior is "Merge".
Skip: func(string) (bool, error) {
Skip: func(string, os.FileInfo) (bool, error) {
return false, nil // Don't skip
},
AddPermission: 0, // Add nothing
Expand Down

0 comments on commit 255df98

Please sign in to comment.