"Fossies" - the Fresh Open Source Software Archive

Member "cli-1.1280.1/cliv2/internal/utils/directories.go" (20 Feb 2024, 1136 Bytes) of package /linux/misc/snyk-cli-1.1280.1.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Go source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 package utils
    2 
    3 import (
    4     "os"
    5     "path"
    6 
    7     "github.com/pkg/errors"
    8 )
    9 
   10 const CACHEDIR_PERMISSION = 0755
   11 
   12 // The directory structure used to cache things into
   13 // - Base cache directory (user definable, default depends on OS, exmple:  /Users/username/Library/Caches/snyk/)
   14 // |- Version cache directory (example: /Users/username/Library/Caches/snyk/snyk-cli/1.1075.0/)
   15 // |- Temp directory (example: /Users/username/Library/Caches/snyk/snyk-cli/1.1075.0/tmp/)
   16 
   17 func GetTemporaryDirectory(baseCacheDirectory string, versionNumber string) string {
   18     return path.Join(GetVersionCacheDirectory(baseCacheDirectory, versionNumber), "tmp")
   19 }
   20 
   21 func GetVersionCacheDirectory(baseCacheDirectory string, versionNumber string) string {
   22     return path.Join(baseCacheDirectory, versionNumber)
   23 }
   24 
   25 func CreateAllDirectories(baseCacheDirectory string, versionNumber string) error {
   26     directoryList := []string{
   27         GetTemporaryDirectory(baseCacheDirectory, versionNumber),
   28     }
   29 
   30     for _, dir := range directoryList {
   31         err := os.MkdirAll(dir, CACHEDIR_PERMISSION)
   32         if err != nil {
   33             return errors.Wrap(err, "failed to create all directories.")
   34         }
   35     }
   36 
   37     return nil
   38 }