-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathpipes_install_dir.go
47 lines (37 loc) · 1.38 KB
/
pipes_install_dir.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package filepaths
import (
"fmt"
"os"
"path/filepath"
"github.com/turbot/pipe-fittings/v2/error_helpers"
)
// PipesInstallDir is the location of config files common between pipelings
// this must be set by the application at startup
var DefaultPipesInstallDir = ""
var PipesInstallDir = ""
func ensurePipesInstallSubDir(dirName string) string {
subDir := pipesInstallSubDir(dirName)
if _, err := os.Stat(subDir); os.IsNotExist(err) {
err = os.MkdirAll(subDir, 0755)
error_helpers.FailOnErrorWithMessage(err, fmt.Sprintf("could not create %s directory", dirName))
}
return subDir
}
func pipesInstallSubDir(dirName string) string {
if PipesInstallDir == "" {
panic(fmt.Errorf("cannot call any pipes directory functions before PipesInstallDir is set"))
}
return filepath.Join(PipesInstallDir, dirName)
}
// PipesInternalDir returns the path to the pipes internal directory (creates if missing)
func PipesInternalDir() string {
return pipesInstallSubDir("internal")
}
// EnsurePipesInternalDir returns the path to the pipes internal directory (creates if missing)
func EnsurePipesInternalDir() string {
return ensurePipesInstallSubDir("internal")
}
// EnsurePipesDuckDbExtensionsDir returns the path to the pipes duckdb extensions directory (creates if missing)
func EnsurePipesDuckDbExtensionsDir() string {
return ensurePipesInstallSubDir(filepath.Join("extensions", "duckdb"))
}