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

     1  package daemon
     2  
     3  import (
     4  	"fmt"
     5  	"path/filepath"
     6  
     7  	"github.com/mutagen-io/mutagen/pkg/filesystem"
     8  )
     9  
    10  const (
    11  	// lockName is the name of the daemon lock. It resides within the daemon
    12  	// subdirectory of the Mutagen directory.
    13  	lockName = "daemon.lock"
    14  	// endpointName is the name of the daemon IPC endpoint. It resides within
    15  	// the daemon subdirectory of the Mutagen directory.
    16  	endpointName = "daemon.sock"
    17  )
    18  
    19  // subpath computes a subpath of the daemon subdirectory, creating the daemon
    20  // subdirectory in the process.
    21  func subpath(name string) (string, error) {
    22  	// Compute the daemon root directory path and ensure it exists.
    23  	daemonRoot, err := filesystem.Mutagen(true, filesystem.MutagenDaemonDirectoryName)
    24  	if err != nil {
    25  		return "", fmt.Errorf("unable to compute daemon directory: %w", err)
    26  	}
    27  
    28  	// Compute the combined path.
    29  	return filepath.Join(daemonRoot, name), nil
    30  }
    31  
    32  // lockPath computes the path to the daemon lock, creating any intermediate
    33  // directories as necessary.
    34  func lockPath() (string, error) {
    35  	return subpath(lockName)
    36  }
    37  
    38  // EndpointPath computes the path to the daemon IPC endpoint, creating any
    39  // intermediate directories as necessary.
    40  func EndpointPath() (string, error) {
    41  	return subpath(endpointName)
    42  }