diff --git a/main.go b/main.go index 070f097..83daf0e 100644 --- a/main.go +++ b/main.go @@ -4,19 +4,16 @@ package main import ( "log" "os" - "os/exec" "path/filepath" "sort" "strings" "sync" - "sync/atomic" "time" "9fans.net/go/acme" ) var ollie string -var exiting atomic.Bool func init() { ollie = os.Getenv("OLLIE") @@ -25,40 +22,6 @@ func init() { } } -func remount() { - if exiting.Load() { - return - } - exec.Command("ollie-remount").Run() //nolint:errcheck -} - -func readFileRetry(path string) ([]byte, error) { - data, err := os.ReadFile(path) - if err != nil { - remount() - data, err = os.ReadFile(path) - } - return data, err -} - -func writeFileRetry(path string, data []byte) error { - err := os.WriteFile(path, data, 0644) - if err != nil { - remount() - err = os.WriteFile(path, data, 0644) - } - return err -} - -func statRetry(path string) (os.FileInfo, error) { - fi, err := os.Stat(path) - if err != nil { - remount() - fi, err = os.Stat(path) - } - return fi, err -} - func main() { acme.AutoExit(true) if err := newSessionList(); err != nil { @@ -70,9 +33,9 @@ func main() { // --- session list window --- type sessionList struct { - win *acme.Win - allSIDs []string - mu sync.Mutex + win *acme.Win + allSIDs []string + mu sync.Mutex } func newSessionList() error { @@ -90,7 +53,7 @@ func newSessionList() error { } func (sl *sessionList) refresh() { - data, err := readFileRetry(filepath.Join(ollie, "s", "idx")) + data, err := os.ReadFile(filepath.Join(ollie, "s", "idx")) if err != nil { sl.win.Errf("read idx: %v", err) return @@ -150,7 +113,7 @@ func (sl *sessionList) eventLoop() { arg := strings.TrimSpace(string(e.Arg)) sid := sl.resolveFullSID(arg) if sid != "" { - writeFileRetry(filepath.Join(ollie, "s", sid, "ctl"), []byte("kill")) + os.WriteFile(filepath.Join(ollie, "s", sid, "ctl"), []byte("kill"), 0644) //nolint:errcheck sl.refresh() } continue @@ -169,12 +132,11 @@ func (sl *sessionList) eventLoop() { sl.win.WriteEvent(e) } } - exiting.Store(true) os.Exit(0) } func sessionExists(sid string) bool { - _, err := statRetry(filepath.Join(ollie, "s", sid)) + _, err := os.Stat(filepath.Join(ollie, "s", sid)) return err == nil } @@ -201,7 +163,7 @@ func openChat(sid string) { return } winName := "ollie/sessions/" + sid - if data, err := readFileRetry(filepath.Join(ollie, "s", "idx")); err == nil { + if data, err := os.ReadFile(filepath.Join(ollie, "s", "idx")); err == nil { for _, line := range strings.Split(string(data), "\n") { fields := strings.Split(line, "\t") if len(fields) >= 3 && fields[0] == sid { @@ -219,7 +181,7 @@ func openChat(sid string) { // Load existing chat. chatPath := filepath.Join(ollie, "s", sid, "chat") - if data, err := readFileRetry(chatPath); err == nil && len(data) > 0 { + if data, err := os.ReadFile(chatPath); err == nil && len(data) > 0 { w.Write("body", data) cw.offset = len(data) } @@ -239,7 +201,7 @@ func (cw *chatWin) eventLoop() { case "Prompt": openFile(filepath.Join(ollie, "s", cw.sid, "prompt")) case "Stop": - writeFileRetry(filepath.Join(ollie, "s", cw.sid, "ctl"), []byte("stop")) + os.WriteFile(filepath.Join(ollie, "s", cw.sid, "ctl"), []byte("stop"), 0644) //nolint:errcheck case "Ctl": openFile(filepath.Join(ollie, "s", cw.sid, "ctl")) default: @@ -256,7 +218,7 @@ func (cw *chatWin) tail() { chatPath := filepath.Join(ollie, "s", cw.sid, "chat") for { - fi, err := statRetry(chatPath) + fi, err := os.Stat(chatPath) if err != nil { if os.IsNotExist(err) { return