github.com/NVIDIA/aistore@v1.3.23-0.20240517131212-7df6609be51d/cmn/cos/homedir.go (about)

     1  // Package cos provides common low-level types and utilities for all aistore projects.
     2  /*
     3   * Copyright (c) 2018-2022, NVIDIA CORPORATION. All rights reserved.
     4   */
     5  package cos
     6  
     7  import (
     8  	"os"
     9  	"os/user"
    10  	"path/filepath"
    11  
    12  	"github.com/NVIDIA/aistore/cmn/debug"
    13  	"github.com/NVIDIA/aistore/cmn/fname"
    14  )
    15  
    16  func HomeDir() (string, error) {
    17  	currentUser, err := user.Current()
    18  	if err != nil {
    19  		Errorf("%v", err)
    20  		return os.UserHomeDir()
    21  	}
    22  	return currentUser.HomeDir, nil
    23  }
    24  
    25  func HomeConfigDir(subdir string) (configDir string) {
    26  	home, err := HomeDir()
    27  	if err != nil {
    28  		debug.AssertNoErr(err)
    29  		Errorf("%v", err)
    30  	}
    31  	// $HOME/.config/ais/<subdir>
    32  	return filepath.Join(home, fname.HomeConfigsDir, fname.HomeAIS, subdir)
    33  }