github.com/rohankumardubey/draft-classic@v0.16.0/pkg/plugin/installer/base.go (about)

     1  package installer // import "github.com/Azure/draft/pkg/plugin/installer"
     2  
     3  import (
     4  	"path/filepath"
     5  
     6  	"github.com/Azure/draft/pkg/draft/draftpath"
     7  	"github.com/Azure/draft/pkg/osutil"
     8  )
     9  
    10  type base struct {
    11  	// Source is the reference to a plugin
    12  	Source string
    13  
    14  	// DraftHome is the $DRAFT_HOME directory
    15  	DraftHome draftpath.Home
    16  }
    17  
    18  func newBase(source string, home draftpath.Home) base {
    19  	return base{source, home}
    20  }
    21  
    22  // link creates a symlink from the plugin source to $DRAFT_HOME
    23  func (b *base) link(from string) error {
    24  	origin, err := filepath.Abs(from)
    25  	if err != nil {
    26  		return err
    27  	}
    28  	dest, err := filepath.Abs(b.Path())
    29  	if err != nil {
    30  		return err
    31  	}
    32  	debug("symlinking %s to %s", origin, dest)
    33  	return osutil.SymlinkWithFallback(origin, dest)
    34  }
    35  
    36  // Path is where the plugin will be symlinked to.
    37  func (b *base) Path() string {
    38  	if b.Source == "" {
    39  		return ""
    40  	}
    41  	return filepath.Join(b.DraftHome.Plugins(), filepath.Base(b.Source))
    42  }