github.com/gkstretton/dark/services/goo@v0.0.0-20231114224855-2d1a2074d446/filesystem/session_content.go (about)

     1  package filesystem
     2  
     3  import (
     4  	"fmt"
     5  	"os"
     6  	"path/filepath"
     7  	"strconv"
     8  )
     9  
    10  // InitSessionContent creates a session folder on disk that content uses
    11  // It also sets the 'latest' symlink to point to this session folder
    12  func InitSessionContent(sessionId uint64, productionId uint64) error {
    13  	p := filepath.Join(*basePath, *contentPath, strconv.Itoa(int(sessionId)))
    14  	if err := os.MkdirAll(p, 0777); err != nil {
    15  		return fmt.Errorf("failed to mkdir: %v", err)
    16  	}
    17  
    18  	latestPath := filepath.Join(*basePath, *contentPath, "latest")
    19  	if err := CreateSymlink(p, latestPath); err != nil {
    20  		return fmt.Errorf("failed to symlink latest session folder: %v", err)
    21  	}
    22  
    23  	if productionId != 0 {
    24  		latestPath := filepath.Join(*basePath, *contentPath, "latest_production")
    25  		if err := CreateSymlink(p, latestPath); err != nil {
    26  			return fmt.Errorf("failed to symlink latest production session folder: %v", err)
    27  		}
    28  	}
    29  
    30  	return nil
    31  }