-
Notifications
You must be signed in to change notification settings - Fork 410
/
Copy pathpath_windows.go
48 lines (43 loc) · 954 Bytes
/
path_windows.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
48
/* SPDX-License-Identifier: MIT
*
* Copyright (C) 2019 WireGuard LLC. All Rights Reserved.
*/
package conf
import (
"os"
"path/filepath"
"golang.org/x/sys/windows"
)
func tunnelConfigurationsDirectory() (string, error) {
if cachedConfigFileDir != "" {
return cachedConfigFileDir, nil
}
root, err := RootDirectory()
if err != nil {
return "", err
}
c := filepath.Join(root, "Configurations")
maybeMigrate(c)
err = os.MkdirAll(c, os.ModeDir|0700)
if err != nil {
return "", err
}
cachedConfigFileDir = c
return cachedConfigFileDir, nil
}
func RootDirectory() (string, error) {
if cachedRootDir != "" {
return cachedRootDir, nil
}
root, err := windows.KnownFolderPath(windows.FOLDERID_LocalAppData, windows.KF_FLAG_CREATE)
if err != nil {
return "", err
}
c := filepath.Join(root, "WireGuard")
err = os.MkdirAll(c, os.ModeDir|0700)
if err != nil {
return "", err
}
cachedRootDir = c
return cachedRootDir, nil
}