github.com/mutagen-io/mutagen@v0.18.0-rc1/pkg/agent/paths.go (about)

     1  package agent
     2  
     3  import (
     4  	"fmt"
     5  	"path/filepath"
     6  	"runtime"
     7  
     8  	"github.com/mutagen-io/mutagen/pkg/filesystem"
     9  	"github.com/mutagen-io/mutagen/pkg/mutagen"
    10  	"github.com/mutagen-io/mutagen/pkg/platform"
    11  )
    12  
    13  const (
    14  	// BaseName is the base name for agent executables (sans any
    15  	// platform-specific suffix like ".exe").
    16  	BaseName = "mutagen-agent"
    17  )
    18  
    19  // installPath computes and creates the parent directories of the path where the
    20  // current executable should be installed if it is an agent binary with the
    21  // current Mutagen version.
    22  func installPath() (string, error) {
    23  	// Compute (and create) the path to the agent parent directory.
    24  	parent, err := filesystem.Mutagen(true, filesystem.MutagenAgentsDirectoryName, mutagen.Version)
    25  	if err != nil {
    26  		return "", fmt.Errorf("unable to compute parent directory: %w", err)
    27  	}
    28  
    29  	// Compute the target executable name.
    30  	executableName := platform.ExecutableName(BaseName, runtime.GOOS)
    31  
    32  	// Compute the installation path.
    33  	return filepath.Join(parent, executableName), nil
    34  }