|
| 1 | +// Copyright 2023 Arduino SA |
| 2 | +// |
| 3 | +// This program is free software: you can redistribute it and/or modify |
| 4 | +// it under the terms of the GNU Affero General Public License as published |
| 5 | +// by the Free Software Foundation, either version 3 of the License, or |
| 6 | +// (at your option) any later version. |
| 7 | +// |
| 8 | +// This program is distributed in the hope that it will be useful, |
| 9 | +// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | +// GNU Affero General Public License for more details. |
| 12 | +// |
| 13 | +// You should have received a copy of the GNU Affero General Public License |
| 14 | +// along with this program. If not, see <https://www.gnu.org/licenses/>. |
| 15 | + |
| 16 | +package main |
| 17 | + |
| 18 | +import ( |
| 19 | + "fmt" |
| 20 | + "os" |
| 21 | + |
| 22 | + "github.com/arduino/go-paths-helper" |
| 23 | +) |
| 24 | + |
| 25 | +// getDefaultArduinoCreateConfigDir returns the full path to the default arduino create agent data directory |
| 26 | +func getDefaultArduinoCreateConfigDir() (*paths.Path, error) { |
| 27 | + // UserConfigDir returns the default root directory to use |
| 28 | + // for user-specific configuration data. Users should create |
| 29 | + // their own application-specific subdirectory within this |
| 30 | + // one and use that. |
| 31 | + // |
| 32 | + // On Unix systems, it returns $XDG_CONFIG_HOME as specified by |
| 33 | + // https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html |
| 34 | + // if non-empty, else $HOME/.config. |
| 35 | + // |
| 36 | + // On Darwin, it returns $HOME/Library/Application Support. |
| 37 | + // On Windows, it returns %AppData%. |
| 38 | + // On Plan 9, it returns $home/lib. |
| 39 | + // |
| 40 | + // If the location cannot be determined (for example, $HOME |
| 41 | + // is not defined), then it will return an error. |
| 42 | + configDir, err := os.UserConfigDir() |
| 43 | + if err != nil { |
| 44 | + return nil, err |
| 45 | + } |
| 46 | + |
| 47 | + agentConfigDir := paths.New(configDir, "ArduinoCreateAgent") |
| 48 | + if err := agentConfigDir.MkdirAll(); err != nil { |
| 49 | + return nil, fmt.Errorf("cannot create config dir: %s", err) |
| 50 | + } |
| 51 | + return agentConfigDir, nil |
| 52 | +} |
0 commit comments