Skip to content
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
9 changes: 3 additions & 6 deletions fileutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,19 +139,16 @@ func CopyDirectory(source string, dest string) error {
return nil
}

// Copy the file.
if err := CopyFile(path, filepath.Join(dest, relPath)); err != nil {
return err
}

return nil
return CopyFile(path, filepath.Join(dest, relPath))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here I just noted that checking for the error was a bit redundant, if there's was a reason for that just let me know and I'll send without this

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

})
}

// Gives a number indicating the device driver to be used to access the passed device
func major(device uint64) uint64 {
return (device >> 8) & 0xfff
}

// Gives a number that serves as a flag to the device driver for the passed device
func minor(device uint64) uint64 {
return (device & 0xff) | ((device >> 12) & 0xfff00)
}
Expand Down
68 changes: 68 additions & 0 deletions fileutils_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package fileutils

import (
"os"
"syscall"
"testing"
)

type device struct {
device string
major uint64
minor uint64
}

func TestDeviceNumbers(t *testing.T) {
devices := []device{
{
device: "/dev/mem",
major: 1,
minor: 1,
},
{
device: "/dev/urandom",
major: 1,
minor: 9,
},
{
device: "/dev/tty0",
major: 4,
minor: 0,
},
{
device: "/dev/tty",
major: 5,
minor: 0,
},
}

for _, device := range devices {
si, err := os.Lstat(device.device)
if err != nil {
t.Errorf("not able to Lstat the device: %v", err)
}

st, ok := si.Sys().(*syscall.Stat_t)

if !ok {
t.Errorf("could not convert to syscall.Stat_t")
}

internalDevice := uint64(st.Rdev)

givenMajor := major(internalDevice)
if givenMajor != device.major {
t.Errorf("%s major not matching - expected: %d - given: %d", device.device, device.major, givenMajor)
}

givenMinor := minor(internalDevice)
if givenMinor != device.minor {
t.Errorf("%s minor not matching - expected: %d - given: %d", device.device, device.minor, givenMinor)
}

givenMkdev := mkdev(int64(device.major), int64(device.minor))
if givenMkdev != uint32(internalDevice) {
t.Errorf("%s mkdev not matching - expected: %d - given: %d", device.device, uint32(internalDevice), givenMkdev)
}
}
}