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

Skip device files by default: Use opt.Specials #84

Merged
merged 1 commit into from
Nov 9, 2022
Merged
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
7 changes: 7 additions & 0 deletions all_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,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 @@ -14,6 +14,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 @@ -90,6 +93,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)
intent: struct {
Expand Down