Skip to content

Commit 705b76e

Browse files
authored
Merge pull request #84 from otiai10/feature/fix-78
Skip device files by default: Use opt.Specials
2 parents b96fe43 + ae3e4ab commit 705b76e

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
@@ -197,6 +197,13 @@ func TestOptions_Skip(t *testing.T) {
197197
})
198198
}
199199

200+
func TestOptions_Specials(t *testing.T) {
201+
if runtime.GOOS == "linux" || runtime.GOOS == "darwin" {
202+
err := Copy("/dev/null", "test/data.copy/dev-null", Options{Specials: false})
203+
Expect(t, err).ToBe(nil)
204+
}
205+
}
206+
200207
func TestOptions_PermissionControl(t *testing.T) {
201208
info, err := os.Stat("test/data/case07/dir_0555")
202209
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
@@ -17,6 +17,9 @@ type Options struct {
1717
// Skip can specify which files should be skipped
1818
Skip func(src string) (bool, error)
1919

20+
// Specials includes special files to be copied. default false.
21+
Specials bool
22+
2023
// AddPermission to every entities,
2124
// NO MORE THAN 0777
2225
// @OBSOLETE
@@ -98,6 +101,7 @@ func getDefaultOptions(src, dest string) Options {
98101
AddPermission: 0, // Add nothing
99102
PermissionControl: PerservePermission, // Just preserve permission
100103
Sync: false, // Do not sync
104+
Specials: false, // Do not copy special files
101105
PreserveTimes: false, // Do not preserve the modification time
102106
CopyBufferSize: 0, // Do not specify, use default bufsize (32*1024)
103107
WrapReader: nil, // Do not wrap src files, use them as they are.

0 commit comments

Comments
 (0)