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"
"os"
"os/exec"
"os/user"
"path"
"path/filepath"
"regexp"
@ -99,22 +98,9 @@ func New(name string, timeout time.Duration) (c Container, err error) {
c.name = name
c.timeout = timeout
usr, err := user.Current()
if err != nil {
return
}
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)
c.Volumes.LibModules = config.Dir("volumes", name, "lib", "modules")
c.Volumes.LibModules = config.Dir("volumes", name, "usr", "src")
c.Volumes.LibModules = config.Dir("volumes", name, "boot")
return
}

View File

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

View File

@ -12,7 +12,7 @@ import (
"os"
"os/exec"
"os/signal"
"os/user"
"path/filepath"
"regexp"
"runtime"
"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) {
usr, err := user.Current()
if err != nil {
return
}
imagesPath := config.Dir("images")
imageFile := d.Name + ".img"
imagesPath := usr.HomeDir + "/.out-of-tree/images/"
os.MkdirAll(imagesPath, os.ModePerm)
rootfs = imagesPath + imageFile
rootfs = filepath.Join(imagesPath, imageFile)
if !fs.PathExists(rootfs) {
if download {
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...)
usr, err := user.Current()
if err != nil {
return
}
// TODO move all cfg path values to one provider
kernelsCfgPath := usr.HomeDir + "/.out-of-tree/kernels.toml"
kernelsCfgPath := config.File("kernels.toml")
err = ioutil.WriteFile(kernelsCfgPath, buf, 0644)
if err != nil {
return

11
main.go
View File

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

View File

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