1
0

Use single temp directory base

This commit is contained in:
dump_stack() 2023-04-07 16:43:56 +00:00
parent 32b692f752
commit 056e38698e
Signed by: dump_stack
GPG Key ID: BE44DA8C062D87DC
6 changed files with 18 additions and 21 deletions

View File

@ -144,7 +144,7 @@ func (cmd *DebugCmd) Run(g *Globals) (err error) {
}
defer q.Stop()
tmp, err := ioutil.TempDir("/tmp/", "out-of-tree_")
tmp, err := ioutil.TempDir(tempDirBase, "out-of-tree_")
if err != nil {
return
}

View File

@ -159,7 +159,7 @@ func unpackTar(archive, destination string) (err error) {
}
func downloadImage(path, file string) (err error) {
tmp, err := ioutil.TempDir("/tmp/", "out-of-tree_")
tmp, err := ioutil.TempDir(tempDirBase, "out-of-tree_")
if err != nil {
return
}

View File

@ -172,7 +172,7 @@ func matchDebImagePkg(container, mask string) (pkgs []string, err error) {
return
}
output, err := c.Run("/tmp", cmd)
output, err := c.Run(tempDirBase, cmd)
if err != nil {
return
}
@ -203,7 +203,7 @@ func matchCentOSDevelPkg(container, mask string, generic bool) (
return
}
output, err := c.Run("/tmp", cmd)
output, err := c.Run(tempDirBase, cmd)
if err != nil {
return
}
@ -389,7 +389,7 @@ func generateBaseDockerImage(registry string, commands []config.DockerCommand,
}
func installKernel(sk config.KernelMask, pkgname string, force, headers bool) (err error) {
tmpdir, err := os.MkdirTemp("", "out-of-tree-"+pkgname+"-")
tmpdir, err := os.MkdirTemp(tempDirBase, "out-of-tree-"+pkgname+"-")
if err != nil {
log.Fatal().Err(err).Msg("make tmp directory")
}
@ -445,7 +445,7 @@ func installKernel(sk config.KernelMask, pkgname string, force, headers bool) (e
cmd := fmt.Sprintf("apt-get install -y %s %s", pkgname, headerspkg)
_, err = c.Run("/tmp", cmd)
_, err = c.Run(tempDirBase, cmd)
if err != nil {
return
}
@ -459,14 +459,14 @@ func installKernel(sk config.KernelMask, pkgname string, force, headers bool) (e
}
cmd := fmt.Sprintf("yum -y install %s %s\n", imagepkg,
pkgname)
_, err = c.Run("/tmp", cmd)
_, err = c.Run(tempDirBase, cmd)
if err != nil {
return
}
cmd = fmt.Sprintf("dracut --add-drivers 'e1000 ext4' -f "+
"/boot/initramfs-%s.img %s\n", version, version)
_, err = c.Run("/tmp", cmd)
_, err = c.Run(tempDirBase, cmd)
if err != nil {
return
}
@ -505,7 +505,7 @@ func installKernel(sk config.KernelMask, pkgname string, force, headers bool) (e
cmd += " && cp -r /usr/src/* /target/usr/src/"
}
_, err = c.Run("/tmp", cmd)
_, err = c.Run(tempDirBase, cmd)
if err != nil {
return
}
@ -676,7 +676,7 @@ func listContainersKernels(dii containerImageInfo, newkcfg *config.KernelConfig,
for _, cmd := range []string{
"find /boot -type f -exec chmod a+r {} \\;",
} {
_, err = c.Run("/tmp", cmd)
_, err = c.Run(tempDirBase, cmd)
if err != nil {
return
}

View File

@ -89,6 +89,8 @@ func (lw *LevelWriter) WriteLevel(l zerolog.Level, p []byte) (n int, err error)
return len(p), nil
}
var tempDirBase string
func main() {
rand.Seed(time.Now().UnixNano())
@ -101,7 +103,7 @@ func main() {
Compact: true,
}),
kong.Vars{
"version": "2.0.5",
"version": "2.0.6",
},
)
@ -124,6 +126,9 @@ func main() {
return
}
tempDirBase = usr.HomeDir + "/.out-of-tree/tmp/"
os.MkdirAll(tempDirBase, os.ModePerm)
log.Logger = log.Output(zerolog.MultiLevelWriter(
&LevelWriter{Writer: zerolog.NewConsoleWriter(
func(w *zerolog.ConsoleWriter) {

10
pew.go
View File

@ -14,7 +14,6 @@ import (
"math/rand"
"os"
"os/exec"
"os/user"
"strings"
"time"
@ -599,14 +598,7 @@ func (cmd PewCmd) testArtifact(swg *sizedwaitgroup.SizedWaitGroup,
}
}()
usr, err := user.Current()
if err != nil {
return
}
tmpdir := usr.HomeDir + "/.out-of-tree/tmp"
os.MkdirAll(tmpdir, os.ModePerm)
tmp, err := ioutil.TempDir(tmpdir, "out-of-tree_")
tmp, err := ioutil.TempDir(tempDirBase, "out-of-tree_")
if err != nil {
slog.Error().Err(err).Msg("making tmp directory")
return

View File

@ -61,7 +61,7 @@ func preload(q *qemu.System, ki config.KernelInfo, pm config.PreloadModule,
func buildAndInsmod(workPath string, q *qemu.System, ki config.KernelInfo,
dockerTimeout time.Duration, cache string) (err error) {
tmp, err := ioutil.TempDir("", "out-of-tree_")
tmp, err := ioutil.TempDir(tempDirBase, "out-of-tree_")
if err != nil {
return
}