mirror of
https://github.com/navidrome/navidrome.git
synced 2026-10-30 15:07:56 +01:00
The whole pglite data dir was mounted as the guest's /tmp, which also exposed the cluster twice. The guest only needs its password file and the shared-memory stand-ins there, so <DataFolder>/pglite/tmp is mounted instead. The cluster and /dev mounts are unchanged.
33 lines
1.1 KiB
Go
33 lines
1.1 KiB
Go
package pglite
|
|
|
|
import (
|
|
"crypto/rand"
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
)
|
|
|
|
// setupDataDir prepares the host directories the guest mounts (cluster, /dev/urandom stand-in,
|
|
// initdb password file) and reports whether initdb still has to run.
|
|
func setupDataDir(dataDir string) (fresh bool, err error) {
|
|
for _, dir := range []string{"pgdata", "dev", filepath.Join("tmp", "pglite")} {
|
|
if err := os.MkdirAll(filepath.Join(dataDir, dir), 0o700); err != nil {
|
|
return false, fmt.Errorf("creating %s: %w", dir, err)
|
|
}
|
|
}
|
|
urandom := filepath.Join(dataDir, "dev", "urandom")
|
|
if !fileExists(urandom) {
|
|
seed := make([]byte, 256)
|
|
if _, err := rand.Read(seed); err != nil {
|
|
return false, fmt.Errorf("generating random bytes: %w", err)
|
|
}
|
|
if err := os.WriteFile(urandom, seed, 0o600); err != nil {
|
|
return false, fmt.Errorf("writing urandom: %w", err)
|
|
}
|
|
}
|
|
// initdb's --pwfile; the bridge never checks it.
|
|
if err := os.WriteFile(filepath.Join(dataDir, "tmp", "pglite", "password"), []byte("password\n"), 0o600); err != nil {
|
|
return false, fmt.Errorf("writing password file: %w", err)
|
|
}
|
|
return !fileExists(filepath.Join(dataDir, "pgdata", "PG_VERSION")), nil
|
|
}
|