@@ -572,8 +572,16 @@ func (c *context) Apply(resource Resource) error {
572572// the context. Otherwise identical to filepath.Walk, the path argument is
573573// corrected to be contained within the context.
574574func (c * context ) Walk (fn filepath.WalkFunc ) error {
575- return c .pathDriver .Walk (c .root , func (p string , fi os.FileInfo , err error ) error {
576- contained , err := c .contain (p )
575+ root := c .root
576+ fi , err := c .driver .Lstat (c .root )
577+ if err == nil && fi .Mode ()& os .ModeSymlink != 0 {
578+ root , err = c .driver .Readlink (c .root )
579+ if err != nil {
580+ return err
581+ }
582+ }
583+ return c .pathDriver .Walk (root , func (p string , fi os.FileInfo , err error ) error {
584+ contained , err := c .containWithRoot (p , root )
577585 return fn (contained , fi , err )
578586 })
579587}
@@ -592,7 +600,15 @@ func (c *context) fullpath(p string) (string, error) {
592600// contain cleans and santizes the filesystem path p to be an absolute path,
593601// effectively relative to the context root.
594602func (c * context ) contain (p string ) (string , error ) {
595- sanitized , err := c .pathDriver .Rel (c .root , p )
603+ return c .containWithRoot (p , c .root )
604+ }
605+
606+ // containWithRoot cleans and santizes the filesystem path p to be an absolute path,
607+ // effectively relative to the passed root. Extra care should be used when calling this
608+ // instead of contain. This is needed for Walk, as if context root is a symlink,
609+ // it must be evaluated prior to the Walk
610+ func (c * context ) containWithRoot (p string , root string ) (string , error ) {
611+ sanitized , err := c .pathDriver .Rel (root , p )
596612 if err != nil {
597613 return "" , err
598614 }
0 commit comments