github.com/mgoltzsche/ctnr@v0.7.1-alpha/pkg/fs/source/sourcedevice.go (about) 1 package source 2 3 import ( 4 "github.com/mgoltzsche/ctnr/pkg/fs" 5 ) 6 7 var _ fs.Source = &sourceDevice{} 8 9 type sourceDevice struct { 10 attrs fs.DeviceAttrs 11 } 12 13 func NewSourceDevice(attrs fs.DeviceAttrs) fs.Source { 14 return &sourceDevice{attrs} 15 } 16 17 func (s *sourceDevice) Attrs() fs.NodeInfo { 18 return fs.NodeInfo{fs.TypeDevice, s.attrs.FileAttrs} 19 } 20 21 func (s *sourceDevice) DeriveAttrs() (fs.DerivedAttrs, error) { 22 return fs.DerivedAttrs{}, nil 23 } 24 25 func (s *sourceDevice) Write(path, name string, w fs.Writer, written map[fs.Source]string) (err error) { 26 if linkDest, ok := written[s]; ok { 27 err = w.Link(path, linkDest) 28 } else { 29 written[s] = path 30 err = w.Device(path, s.attrs) 31 } 32 return 33 }