Flamenco/internal/appinfo/xdg_paths.go
Sybren A. Stüvel 2f76df437b T99415: Worker: change default location for writing local files
Change the location where the Worker writes its local files so that it
follows the XDG specification (instead of writing to the current working
directory).

- Linux:   `$HOME/.local/share/flamenco`
- Windows: `C:\Users\UserName\AppData\Local\Flamenco`
- macOS:   `$HOME/Library/Application Support/Flamenco`

NOTE: The old files will not be loaded any more. This means that if
nothing is done and the new worker is run as-is, it will reregister as a
brand new worker. Move `flamenco-worker-credentials.yaml` and
`flamenco-worker.sqlite` to the new location to avoid this.
2022-07-19 12:08:41 +02:00

25 lines
566 B
Go

package appinfo
// SPDX-License-Identifier: GPL-3.0-or-later
import (
"os"
"path"
"path/filepath"
"github.com/adrg/xdg"
)
// InFlamencoHome returns the filename in the 'flamenco home' dir, and ensures
// that the directory exists.
func InFlamencoHome(filename string) (string, error) {
flamencoHome := os.Getenv("FLAMENCO_HOME")
if flamencoHome == "" {
return xdg.DataFile(path.Join(xdgApplicationName, filename))
}
if err := os.MkdirAll(flamencoHome, os.ModePerm); err != nil {
return "", err
}
return filepath.Join(flamencoHome, filename), nil
}