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

     1  package forwarding
     2  
     3  import (
     4  	"fmt"
     5  	"path/filepath"
     6  
     7  	"github.com/mutagen-io/mutagen/pkg/filesystem"
     8  )
     9  
    10  const (
    11  	// sessionsDirectoryName is the name of the session storage directory within
    12  	// the forwarding data directory.
    13  	sessionsDirectoryName = "sessions"
    14  )
    15  
    16  // pathForSession computes the path to the serialized session for the given
    17  // session identifier. An empty session identifier will return the sessions
    18  // directory path.
    19  func pathForSession(sessionIdentifier string) (string, error) {
    20  	// Compute/create the sessions directory.
    21  	sessionsDirectoryPath, err := filesystem.Mutagen(
    22  		true,
    23  		filesystem.MutagenForwardingDirectoryName,
    24  		sessionsDirectoryName,
    25  	)
    26  	if err != nil {
    27  		return "", fmt.Errorf("unable to compute/create sessions directory: %w", err)
    28  	}
    29  
    30  	// Success.
    31  	return filepath.Join(sessionsDirectoryPath, sessionIdentifier), nil
    32  }