Skip to content

Commit ae3e4ab

Browse files
committed
Skip device files by default: Use opt.Specials
Fix #78
1 parent 8575144 commit ae3e4ab

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

all_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,13 @@ func TestOptions_Skip(t *testing.T) {
195195
})
196196
}
197197

198+
func TestOptions_Specials(t *testing.T) {
199+
if runtime.GOOS == "linux" || runtime.GOOS == "darwin" {
200+
err := Copy("/dev/null", "test/data.copy/dev-null", Options{Specials: false})
201+
Expect(t, err).ToBe(nil)
202+
}
203+
}
204+
198205
func TestOptions_PermissionControl(t *testing.T) {
199206
info, err := os.Stat("test/data/case07/dir_0555")
200207
Expect(t, err).ToBe(nil)

copy.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ func Copy(src, dest string, opt ...Options) error {
2626
// switchboard switches proper copy functions regarding file type, etc...
2727
// If there would be anything else here, add a case to this switchboard.
2828
func switchboard(src, dest string, info os.FileInfo, opt Options) (err error) {
29+
30+
if info.Mode()&os.ModeDevice != 0 && !opt.Specials {
31+
return err
32+
}
33+
2934
switch {
3035
case info.Mode()&os.ModeSymlink != 0:
3136
err = onsymlink(src, dest, opt)

options.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ type Options struct {
1414
// Skip can specify which files should be skipped
1515
Skip func(src string) (bool, error)
1616

17+
// Specials includes special files to be copied. default false.
18+
Specials bool
19+
1720
// AddPermission to every entities,
1821
// NO MORE THAN 0777
1922
// @OBSOLETE
@@ -90,6 +93,7 @@ func getDefaultOptions(src, dest string) Options {
9093
AddPermission: 0, // Add nothing
9194
PermissionControl: PerservePermission, // Just preserve permission
9295
Sync: false, // Do not sync
96+
Specials: false, // Do not copy special files
9397
PreserveTimes: false, // Do not preserve the modification time
9498
CopyBufferSize: 0, // Do not specify, use default bufsize (32*1024)
9599
intent: struct {

0 commit comments

Comments
 (0)