copy_irregular_unix.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. //go:build !windows && !freebsd
  2. // +build !windows,!freebsd
  3. /*
  4. Copyright The containerd Authors.
  5. Licensed under the Apache License, Version 2.0 (the "License");
  6. you may not use this file except in compliance with the License.
  7. You may obtain a copy of the License at
  8. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. */
  15. package fs
  16. import (
  17. "fmt"
  18. "os"
  19. "syscall"
  20. )
  21. // copyIrregular covers devices, pipes, and sockets
  22. func copyIrregular(dst string, fi os.FileInfo) error {
  23. st, ok := fi.Sys().(*syscall.Stat_t) // not *unix.Stat_t
  24. if !ok {
  25. return fmt.Errorf("unsupported stat type: %s: %v", dst, fi.Mode())
  26. }
  27. var rDev int
  28. if fi.Mode()&os.ModeDevice == os.ModeDevice {
  29. rDev = int(st.Rdev)
  30. }
  31. //nolint:unconvert
  32. return syscall.Mknod(dst, uint32(st.Mode), rDev)
  33. }