Files
s41r4j 0f03d49514
CI / contracts (push) Canceled after 0s
Website / deploy (push) Canceled after 0s
CI / test (macos-latest) (push) Canceled after 0s
CI / test (ubuntu-24.04) (push) Canceled after 0s
CI / test (ubuntu-24.04-arm) (push) Canceled after 0s
CI / test (windows-latest) (push) Canceled after 0s
CI / Compact real-tool fixtures (ubuntu-24.04) (push) Canceled after 0s
CI / Compact real-tool fixtures (ubuntu-24.04-arm) (push) Canceled after 0s
CI / Code analysis fixtures (ubuntu-24.04) (push) Canceled after 0s
CI / Code analysis fixtures (ubuntu-24.04-arm) (push) Canceled after 0s
CI / Web engine fixtures (ubuntu-24.04) (push) Canceled after 0s
CI / Web engine fixtures (ubuntu-24.04-arm) (push) Canceled after 0s
CI / Chromium operation fixtures (ubuntu-24.04) (push) Canceled after 0s
CI / Chromium operation fixtures (ubuntu-24.04-arm) (push) Canceled after 0s
CI / operation-readiness (push) Canceled after 0s
CI / Supply chain fixtures (ubuntu-24.04) (push) Canceled after 0s
CI / Supply chain fixtures (ubuntu-24.04-arm) (push) Canceled after 0s
Initial commit
2026-11-01 09:14:18 +05:30

50 lines
1.2 KiB
Go

package execution
import (
"context"
"os"
"os/exec"
"path/filepath"
"strings"
"time"
)
// Continue accepting writes after cancellation so a noisy child cannot block a
// pipe reader. The caller reports truncation as an error, never a valid result.
type limitedOutput struct {
data []byte
limit int
exceeded bool
cancel context.CancelFunc
}
func (b *limitedOutput) Write(p []byte) (int, error) {
n := len(p)
remaining := b.limit - len(b.data)
if len(p) > remaining {
b.data = append(b.data, p[:remaining]...)
b.exceeded = true
b.cancel()
} else {
b.data = append(b.data, p...)
}
return n, nil
}
// A killed docker client does not stop its container. Only remove the exact ID
// created by this invocation; a name conflict must never stop another run.
func removeOwnedContainer(dir string) {
defer os.RemoveAll(dir)
id, err := os.ReadFile(filepath.Join(dir, "id"))
if err != nil {
return
}
value := strings.TrimSpace(string(id))
if len(value) != 64 || strings.Trim(value, "0123456789abcdef") != "" {
return
}
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
_ = exec.CommandContext(ctx, "docker", "rm", "-f", value).Run()
}