fixup zip creating

This commit is contained in:
Edgaru089 2023-08-15 22:06:44 +08:00
parent 35092fc7c1
commit 4054ca3b2e

View File

@ -15,15 +15,24 @@ type logsWriter struct {
outfd int // 0(manual message) 1(stdout) or 2(stderr) outfd int // 0(manual message) 1(stdout) or 2(stderr)
} }
func (l *logsWriter) Write(data []byte) (len int, err error) { func (l *logsWriter) Write(data []byte) (written int, err error) {
datalen := len(data)
written = datalen
l.lock.Lock() l.lock.Lock()
defer l.lock.Unlock() defer l.lock.Unlock()
for data[datalen-1] == byte('\n') {
datalen--
}
data = data[:datalen]
*l.logs = append(*l.logs, LogEntry{ *l.logs = append(*l.logs, LogEntry{
Time: time.Now(), Time: time.Now(),
Text: string(data), Text: string(data),
OutFd: l.outfd, OutFd: l.outfd,
}) })
return return
} }
@ -53,13 +62,15 @@ func (p *Profile) Run(dir string, outfile string) (logs Logs, exitcode int, err
var systime, usrtime time.Duration var systime, usrtime time.Duration
fmt.Fprintf(logman, "building %s", p.Name)
// Run commands // Run commands
runcmds: runcmds:
for i, str := range p.Commands { for i, str := range p.Commands {
fmt.Fprintf(logman, "[%d/%d] running \"%s\"", i, len(p.Commands), str) fmt.Fprintf(logman, "[%d/%d] running \"%s\"", i, len(p.Commands), str)
cmd := exec.Command("sh", "-c", str) cmd := exec.Command("sh", "-c", "exec "+str)
cmd.Env = append(cmd.Env, env...) cmd.Env = append(cmd.Env, env...)
cmd.Stdout = logout cmd.Stdout = logout
cmd.Stderr = logerr cmd.Stderr = logerr
@ -91,7 +102,7 @@ runcmds:
packstr := "zip -r - " + strings.Join(p.Output, " ") packstr := "zip -r - " + strings.Join(p.Output, " ")
fmt.Fprintf(logman, "[fin] packing output: \"%s\"", packstr) fmt.Fprintf(logman, "[fin] packing output: \"%s\"", packstr)
packcmd := exec.Command("sh", "-c", packstr) packcmd := exec.Command("sh", "-c", "exec "+packstr)
packcmd.Dir = p.OutputDir packcmd.Dir = p.OutputDir
packcmd.Stdout = writer packcmd.Stdout = writer
packcmd.Stderr = logerr packcmd.Stderr = logerr
@ -101,5 +112,7 @@ runcmds:
return return
} }
fmt.Fprintf(logman, "output is at %s", outfile)
return return
} }