Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add fileinfo to skip function #40

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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