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