X-Git-Url: https://git.giacomolli.uk/onechat/blobdiff_plain/80e348724041a694002fc38f57e8868b9b9a2be9..0cb73c3dde36d0078f3c1aa4200f2edcb5ceed38:/tools.go?ds=sidebyside diff --git a/tools.go b/tools.go index 11e208d..191bb25 100644 --- a/tools.go +++ b/tools.go @@ -494,9 +494,11 @@ func (b *Toolbox) shell(ctx context.Context, command string) string { cmd.SysProcAttr = &syscall.SysProcAttr{ Setpgid: true, } + cmd.Cancel = func() error { return syscall.Kill(-cmd.Process.Pid, syscall.SIGKILL) } + cmd.WaitDelay = toolShellOutputTimeout output := &ToolHeadTail{} @@ -542,8 +544,7 @@ func (b *Toolbox) read(path string) (text string, err error) { return output.String(), nil } -// write replaces the file at path with text, and makes its missing -// directories. +// write replaces the file at path with text, and makes its missing directories. func (b *Toolbox) write(path, text string) (string, error) { path = b.path(path) err := os.MkdirAll(filepath.Dir(path), 0o755) @@ -559,8 +560,8 @@ func (b *Toolbox) write(path, text string) (string, error) { return fmt.Sprintf("wrote %d bytes to %s", len(text), path), nil } -// edit replaces the one occurrence of old in the file at path with -// replacement. It keeps the mode of the file. +// edit replaces the one occurrence of old in the file at path with replacement. +// It keeps the mode of the file. func (b *Toolbox) edit(path, old, replacement string) (string, error) { path = b.path(path) data, err := os.ReadFile(path) @@ -590,8 +591,7 @@ func (b *Toolbox) edit(path, old, replacement string) (string, error) { return "edited " + path, nil } -// path returns path, relative to the working directory when it is not -// absolute. +// path returns path, relative to the working directory when it is not absolute. func (b *Toolbox) path(path string) string { if filepath.IsAbs(path) { return path