Fix linter

This commit is contained in:
Fedor Korotkiy 2020-03-28 17:35:01 +03:00
parent d3f089aaf4
commit 8a0fd66a89
6 changed files with 43 additions and 38 deletions

View file

@ -84,10 +84,12 @@ func newEnv(t *testing.T) (e *env, cancel func()) {
workerName := fmt.Sprintf("worker%d", i) workerName := fmt.Sprintf("worker%d", i)
workerDir := filepath.Join(env.RootDir, workerName) workerDir := filepath.Join(env.RootDir, workerName)
fileCache, err := filecache.New(filepath.Join(workerDir, "filecache")) var fileCache *filecache.Cache
fileCache, err = filecache.New(filepath.Join(workerDir, "filecache"))
require.NoError(t, err) require.NoError(t, err)
artifacts, err := artifact.NewCache(filepath.Join(workerDir, "artifacts")) var artifacts *artifact.Cache
artifacts, err = artifact.NewCache(filepath.Join(workerDir, "artifacts"))
require.NoError(t, err) require.NoError(t, err)
w := worker.New( w := worker.New(

View file

@ -66,7 +66,7 @@ func (c *Cache) readLock(id build.ID) error {
return ErrWriteLocked return ErrWriteLocked
} }
c.readLocked[id] += 1 c.readLocked[id]++
return nil return nil
} }
@ -74,7 +74,7 @@ func (c *Cache) readUnlock(id build.ID) {
c.mu.Lock() c.mu.Lock()
defer c.mu.Unlock() defer c.mu.Unlock()
c.readLocked[id] -= 1 c.readLocked[id]--
if c.readLocked[id] == 0 { if c.readLocked[id] == 0 {
delete(c.readLocked, id) delete(c.readLocked, id)
} }

View file

@ -38,12 +38,12 @@ func (c *Coordinator) scheduleJob(job *build.Job) *scheduledJob {
if scheduled, ok := c.scheduledJobs[job.ID]; ok { if scheduled, ok := c.scheduledJobs[job.ID]; ok {
return scheduled return scheduled
} else {
scheduled = newScheduledJob(job)
c.scheduledJobs[job.ID] = scheduled
c.queue = append(c.queue, scheduled)
return scheduled
} }
scheduled := newScheduledJob(job)
c.scheduledJobs[job.ID] = scheduled
c.queue = append(c.queue, scheduled)
return scheduled
} }
func (c *Coordinator) pickJob() (*build.Job, bool) { func (c *Coordinator) pickJob() (*build.Job, bool) {

View file

@ -24,12 +24,14 @@ func Send(dir string, w io.Writer) error {
return nil return nil
} }
if info.IsDir() { switch {
case info.IsDir():
return tw.WriteHeader(&tar.Header{ return tw.WriteHeader(&tar.Header{
Name: rel, Name: rel,
Typeflag: tar.TypeDir, Typeflag: tar.TypeDir,
}) })
} else {
default:
h := &tar.Header{ h := &tar.Header{
Typeflag: tar.TypeReg, Typeflag: tar.TypeReg,
Name: rel, Name: rel,

View file

@ -63,30 +63,30 @@ func executeCmd(ctx context.Context, cmd *build.Cmd) (stdout, stderr []byte, exi
if cmd.CatOutput != "" { if cmd.CatOutput != "" {
err = ioutil.WriteFile(cmd.CatOutput, []byte(cmd.CatTemplate), 0666) err = ioutil.WriteFile(cmd.CatOutput, []byte(cmd.CatTemplate), 0666)
return return
} else {
p := exec.CommandContext(ctx, cmd.Exec[0], cmd.Exec[1:]...)
p.Dir = cmd.WorkingDirectory
p.Env = cmd.Environ
p.Stdout = &stdoutBuf
p.Stderr = &stderrBuf
err = p.Run()
stdout = stdoutBuf.Bytes()
stderr = stderrBuf.Bytes()
if err != nil {
var exitErr *exec.ExitError
if errors.As(err, &exitErr) {
exitCode = exitErr.ExitCode()
err = nil
}
}
return
} }
p := exec.CommandContext(ctx, cmd.Exec[0], cmd.Exec[1:]...)
p.Dir = cmd.WorkingDirectory
p.Env = cmd.Environ
p.Stdout = &stdoutBuf
p.Stderr = &stderrBuf
err = p.Run()
stdout = stdoutBuf.Bytes()
stderr = stderrBuf.Bytes()
if err != nil {
var exitErr *exec.ExitError
if errors.As(err, &exitErr) {
exitCode = exitErr.ExitCode()
err = nil
}
}
return
} }
func (w *Worker) prepareSourceDir(sourceDir string, sourceFiles map[build.ID]string) (unlock func(), err error) { func (w *Worker) prepareSourceDir(sourceDir string, sourceFiles map[build.ID]string) (unlockSources func(), err error) {
var unlocks []func() var unlocks []func()
doUnlock := func() { doUnlock := func() {
for _, u := range unlocks { for _, u := range unlocks {
@ -119,12 +119,12 @@ func (w *Worker) prepareSourceDir(sourceDir string, sourceFiles map[build.ID]str
} }
} }
unlock = doUnlock unlockSources = doUnlock
doUnlock = nil doUnlock = nil
return return
} }
func (w *Worker) lockDeps(deps []build.ID) (paths map[build.ID]string, unlock func(), err error) { func (w *Worker) lockDeps(deps []build.ID) (paths map[build.ID]string, unlockDeps func(), err error) {
var unlocks []func() var unlocks []func()
doUnlock := func() { doUnlock := func() {
for _, u := range unlocks { for _, u := range unlocks {
@ -150,7 +150,7 @@ func (w *Worker) lockDeps(deps []build.ID) (paths map[build.ID]string, unlock fu
paths[id] = filepath.Join(path, outputDirName) paths[id] = filepath.Join(path, outputDirName)
} }
unlock = doUnlock unlockDeps = doUnlock
doUnlock = nil doUnlock = nil
return return
} }
@ -173,18 +173,18 @@ func (w *Worker) runJob(ctx context.Context, spec *proto.JobSpec) (*proto.JobRes
return return
} }
if err := abort(); err != nil { if err = abort(); err != nil {
w.log.Warn("error aborting job", zap.Any("job_id", spec.Job.ID), zap.Error(err)) w.log.Warn("error aborting job", zap.Any("job_id", spec.Job.ID), zap.Error(err))
} }
}() }()
outputDir := filepath.Join(aRoot, outputDirName) outputDir := filepath.Join(aRoot, outputDirName)
if err := os.Mkdir(outputDir, 0777); err != nil { if err = os.Mkdir(outputDir, 0777); err != nil {
return nil, err return nil, err
} }
sourceDir := filepath.Join(aRoot, srcDirName) sourceDir := filepath.Join(aRoot, srcDirName)
if err := os.Mkdir(sourceDir, 0777); err != nil { if err = os.Mkdir(sourceDir, 0777); err != nil {
return nil, err return nil, err
} }

View file

@ -117,6 +117,7 @@ func (w *Worker) Run(ctx context.Context) error {
zap.Int("num_jobs", len(rsp.JobsToRun))) zap.Int("num_jobs", len(rsp.JobsToRun)))
for _, spec := range rsp.JobsToRun { for _, spec := range rsp.JobsToRun {
spec := spec
result, err := w.runJob(ctx, &spec) result, err := w.runJob(ctx, &spec)
if err != nil { if err != nil {
errStr := fmt.Sprintf("job %s failed: %v", spec.Job.ID, err) errStr := fmt.Sprintf("job %s failed: %v", spec.Job.ID, err)