1
0

fix: use the default config dirs provider

This commit is contained in:
dump_stack() 2023-05-21 20:31:47 +00:00
parent ba03d4a049
commit 31b0945a15
Signed by: dump_stack
GPG Key ID: BE44DA8C062D87DC
5 changed files with 16 additions and 62 deletions

View File

@ -10,7 +10,6 @@ import (
"fmt" "fmt"
"os" "os"
"os/exec" "os/exec"
"os/user"
"path" "path"
"path/filepath" "path/filepath"
"regexp" "regexp"
@ -99,22 +98,9 @@ func New(name string, timeout time.Duration) (c Container, err error) {
c.name = name c.name = name
c.timeout = timeout c.timeout = timeout
usr, err := user.Current() c.Volumes.LibModules = config.Dir("volumes", name, "lib", "modules")
if err != nil { c.Volumes.LibModules = config.Dir("volumes", name, "usr", "src")
return c.Volumes.LibModules = config.Dir("volumes", name, "boot")
}
c.Volumes.LibModules = fmt.Sprintf(
"%s/.out-of-tree/volumes/%s/lib/modules", usr.HomeDir, name)
os.MkdirAll(c.Volumes.LibModules, 0777)
c.Volumes.UsrSrc = fmt.Sprintf(
"%s/.out-of-tree/volumes/%s/usr/src", usr.HomeDir, name)
os.MkdirAll(c.Volumes.UsrSrc, 0777)
c.Volumes.Boot = fmt.Sprintf(
"%s/.out-of-tree/volumes/%s/boot", usr.HomeDir, name)
os.MkdirAll(c.Volumes.Boot, 0777)
return return
} }

View File

@ -8,7 +8,7 @@ import (
"errors" "errors"
"fmt" "fmt"
"os" "os"
"os/user" "path/filepath"
"strings" "strings"
"time" "time"
@ -25,12 +25,7 @@ type ImageCmd struct {
type ImageListCmd struct{} type ImageListCmd struct{}
func (cmd *ImageListCmd) Run(g *Globals) (err error) { func (cmd *ImageListCmd) Run(g *Globals) (err error) {
usr, err := user.Current() entries, err := os.ReadDir(config.Dir("images"))
if err != nil {
return
}
entries, err := os.ReadDir(usr.HomeDir + "/.out-of-tree/images/")
if err != nil { if err != nil {
return return
} }
@ -48,12 +43,7 @@ type ImageEditCmd struct {
} }
func (cmd *ImageEditCmd) Run(g *Globals) (err error) { func (cmd *ImageEditCmd) Run(g *Globals) (err error) {
usr, err := user.Current() image := filepath.Join(config.Dir("images"), cmd.Name)
if err != nil {
return
}
image := usr.HomeDir + "/.out-of-tree/images/" + cmd.Name
if !fs.PathExists(image) { if !fs.PathExists(image) {
fmt.Println("image does not exist") fmt.Println("image does not exist")
} }

View File

@ -12,7 +12,7 @@ import (
"os" "os"
"os/exec" "os/exec"
"os/signal" "os/signal"
"os/user" "path/filepath"
"regexp" "regexp"
"runtime" "runtime"
"strings" "strings"
@ -326,16 +326,10 @@ func findInitrdFile(files []os.FileInfo, kname string) (name string, err error)
} }
func GenRootfsImage(d container.Image, download bool) (rootfs string, err error) { func GenRootfsImage(d container.Image, download bool) (rootfs string, err error) {
usr, err := user.Current() imagesPath := config.Dir("images")
if err != nil {
return
}
imageFile := d.Name + ".img" imageFile := d.Name + ".img"
imagesPath := usr.HomeDir + "/.out-of-tree/images/" rootfs = filepath.Join(imagesPath, imageFile)
os.MkdirAll(imagesPath, os.ModePerm)
rootfs = imagesPath + imageFile
if !fs.PathExists(rootfs) { if !fs.PathExists(rootfs) {
if download { if download {
log.Info().Msgf("%v not available, start download", imageFile) log.Info().Msgf("%v not available, start download", imageFile)
@ -395,13 +389,7 @@ func UpdateKernelsCfg(host, download bool) (err error) {
buf = append([]byte("# Autogenerated\n# DO NOT EDIT\n\n"), buf...) buf = append([]byte("# Autogenerated\n# DO NOT EDIT\n\n"), buf...)
usr, err := user.Current() kernelsCfgPath := config.File("kernels.toml")
if err != nil {
return
}
// TODO move all cfg path values to one provider
kernelsCfgPath := usr.HomeDir + "/.out-of-tree/kernels.toml"
err = ioutil.WriteFile(kernelsCfgPath, buf, 0644) err = ioutil.WriteFile(kernelsCfgPath, buf, 0644)
if err != nil { if err != nil {
return return

11
main.go
View File

@ -11,8 +11,6 @@ import (
"net/url" "net/url"
"os" "os"
"os/exec" "os/exec"
"os/user"
"path/filepath"
"runtime/debug" "runtime/debug"
"strconv" "strconv"
"time" "time"
@ -138,11 +136,6 @@ func main() {
loglevel = zerolog.ErrorLevel loglevel = zerolog.ErrorLevel
} }
usr, err := user.Current()
if err != nil {
return
}
consoleWriter = LevelWriter{Writer: zerolog.NewConsoleWriter( consoleWriter = LevelWriter{Writer: zerolog.NewConsoleWriter(
func(w *zerolog.ConsoleWriter) { func(w *zerolog.ConsoleWriter) {
w.Out = os.Stderr w.Out = os.Stderr
@ -152,7 +145,7 @@ func main() {
} }
fileWriter = LevelWriter{Writer: &lumberjack.Logger{ fileWriter = LevelWriter{Writer: &lumberjack.Logger{
Filename: usr.HomeDir + "/.out-of-tree/logs/out-of-tree.log", Filename: config.File("logs/out-of-tree.log"),
}, },
Level: zerolog.TraceLevel, Level: zerolog.TraceLevel,
} }
@ -171,7 +164,7 @@ func main() {
log.Debug().Msgf("%v", buildInfo.Settings) log.Debug().Msgf("%v", buildInfo.Settings)
} }
path := filepath.Join(usr.HomeDir, ".out-of-tree") path := config.Dir()
yes, err := fs.CaseInsensitive(path) yes, err := fs.CaseInsensitive(path)
if err != nil { if err != nil {
log.Fatal().Err(err).Msg(path) log.Fatal().Err(err).Msg(path)

View File

@ -9,7 +9,6 @@ import (
"encoding/hex" "encoding/hex"
"errors" "errors"
"os" "os"
"os/user"
"path/filepath" "path/filepath"
"time" "time"
@ -115,12 +114,10 @@ func buildPreload(workPath, tmp string, ki config.KernelInfo,
return return
} }
func cloneOrPull(repo string, ki config.KernelInfo) (workPath, cache string, err error) { func cloneOrPull(repo string, ki config.KernelInfo) (workPath, cache string,
usr, err := user.Current() err error) {
if err != nil {
return base := config.Dir("preload")
}
base := filepath.Join(usr.HomeDir, "/.out-of-tree/preload/")
workPath = filepath.Join(base, "/repos/", sha1sum(repo)) workPath = filepath.Join(base, "/repos/", sha1sum(repo))
var r *git.Repository var r *git.Repository