summaryrefslogtreecommitdiff
path: root/run.go
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2024-12-11 01:14:24 -0600
committerJeff Carr <[email protected]>2024-12-11 01:14:24 -0600
commit875435bc025e3b07d2f4a3fed50e78b9be58390a (patch)
treef355bb362e30f707f33d7534ccf6c714107503e1 /run.go
parentb5a5732ead91ca963ca56341e8993c2c502345f5 (diff)
somewhat is starting to work
Diffstat (limited to 'run.go')
-rw-r--r--run.go70
1 files changed, 70 insertions, 0 deletions
diff --git a/run.go b/run.go
new file mode 100644
index 0000000..2dcb53b
--- /dev/null
+++ b/run.go
@@ -0,0 +1,70 @@
+package main
+
+import (
+ "errors"
+ "fmt"
+ "os"
+ "path/filepath"
+
+ "go.wit.com/lib/gui/shell"
+ "go.wit.com/log"
+)
+
+func purgeGoCaches() {
+ homedir, err := os.UserHomeDir()
+ if err != nil {
+ badExit(err)
+ }
+ pkgdir := filepath.Join(homedir, "go/pkg")
+ var cmd []string
+ cmd = []string{"chmod", "700", "-R", pkgdir}
+ runStrict("", cmd)
+ cmd = []string{"rm", "-rf", pkgdir}
+ runStrict("", cmd)
+ builddir := filepath.Join(homedir, ".cache/go-build")
+ cmd = []string{"rm", "-rf", builddir}
+ runStrict("", cmd)
+
+ // this can't have really happened
+ // echo this still failed in:
+ // echo "Linux hpdev2.grid.wit.com 6.9.8-rt-amd64 #1 SMP PREEMPT_RT Debian 6.9.8-1 (2024-07-07) x86_64 GNU/Linux"
+ // echo and I had to drop the caches after building go install binaries quickly and running them
+ // echo "as an os.Exec() between binaries"
+ // echo sysctl -w vm.drop_caches=3
+}
+
+func runStrict(wd string, cmd []string) {
+ var err error
+ if wd != "" {
+ if err = os.Chdir(wd); err != nil {
+ log.Info("cd", "wd", "failed", err)
+ badExit(err)
+ }
+ }
+ log.Info(wd, "running:", wd, cmd)
+ // result := shell.Run(cmd)
+ result := shell.RunRealtime(cmd)
+ if result.Error != nil {
+ log.Info("cmd failed", wd, cmd, err)
+ for i, line := range result.Stdout {
+ log.Info("STDOUT:", i, line)
+ }
+ for i, line := range result.Stderr {
+ log.Info("STDERR:", i, line)
+ }
+ badExit(err)
+ }
+ if result.Exit != 0 {
+ log.Info("cmd failed", wd, cmd, err)
+ for i, line := range result.Stdout {
+ log.Info("STDOUT:", i, line)
+ }
+ for i, line := range result.Stderr {
+ log.Info("STDERR:", i, line)
+ }
+ badExit(errors.New(fmt.Sprintf("cmd failed with %d", result.Exit)))
+ }
+ for i, line := range result.Stdout {
+ log.Info(i, line)
+ }
+}