| 1 |
/* |
| 2 |
Copyright 2020 Docker Compose CLI authors |
| 3 |
|
| 4 |
Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 |
you may not use this file except in compliance with the License. |
| 6 |
You may obtain a copy of the License at |
| 7 |
|
| 8 |
http://www.apache.org/licenses/LICENSE-2.0 |
| 9 |
|
| 10 |
Unless required by applicable law or agreed to in writing, software |
| 11 |
distributed under the License is distributed on an "AS IS" BASIS, |
| 12 |
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 |
See the License for the specific language governing permissions and |
| 14 |
limitations under the License. |
| 15 |
*/ |
| 16 |
|
| 17 |
package remote |
| 18 |
|
| 19 |
import ( |
| 20 |
"os" |
| 21 |
"path/filepath" |
| 22 |
|
| 23 |
"golang.org/x/sys/windows" |
| 24 |
) |
| 25 |
|
| 26 |
// Based on https://github.com/adrg/xdg |
| 27 |
// Licensed under MIT License (MIT) |
| 28 |
// Copyright (c) 2014 Adrian-George Bostan <[email protected]> |
| 29 |
|
| 30 |
func osDependentCacheDir() (string, error) { |
| 31 |
flags := []uint32{windows.KF_FLAG_DEFAULT, windows.KF_FLAG_DEFAULT_PATH} |
| 32 |
for _, flag := range flags { |
| 33 |
p, _ := windows.KnownFolderPath(windows.FOLDERID_LocalAppData, flag|windows.KF_FLAG_DONT_VERIFY) |
| 34 |
if p != "" { |
| 35 |
return filepath.Join(p, "cache", "docker-compose"), nil |
| 36 |
} |
| 37 |
} |
| 38 |
|
| 39 |
appData, ok := os.LookupEnv("LOCALAPPDATA") |
| 40 |
if ok { |
| 41 |
return filepath.Join(appData, "cache", "docker-compose"), nil |
| 42 |
} |
| 43 |
|
| 44 |
home, err := os.UserHomeDir() |
| 45 |
if err != nil { |
| 46 |
return "", err |
| 47 |
} |
| 48 |
return filepath.Join(home, "AppData", "Local", "cache", "docker-compose"), nil |
| 49 |
} |