feat(editor): wait for ready file and rename to doEditor.go
This commit is contained in:
parent
f5b923f180
commit
4f215037a1
|
@ -5,9 +5,37 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"go.wit.com/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
func doEditor() (string, error) {
|
func doEditor() error {
|
||||||
|
for {
|
||||||
|
filename, err := doEditorOnce()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
log.Info("filename:", filename)
|
||||||
|
|
||||||
|
for {
|
||||||
|
_, err := os.Stat("/tmp/regex.ready")
|
||||||
|
if err == nil {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
time.Sleep(100 * time.Millisecond)
|
||||||
|
}
|
||||||
|
// read in regex.ready exists (should be SessionID)
|
||||||
|
// Println session ID
|
||||||
|
content, err := ioutil.ReadFile("/tmp/regex.ready")
|
||||||
|
if err != nil {
|
||||||
|
log.Error(err)
|
||||||
|
}
|
||||||
|
log.Infof("SessionID: %s", string(content))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func doEditorOnce() (string, error) {
|
||||||
// Create a temporary file
|
// Create a temporary file
|
||||||
tmpfile, err := ioutil.TempFile("", "regex-*.txt")
|
tmpfile, err := ioutil.TempFile("", "regex-*.txt")
|
||||||
if err != nil {
|
if err != nil {
|
Loading…
Reference in New Issue