Skip to content

Commit 008efc8

Browse files
authored
[runner] Check if repo dir exists before chown (#3589)
The check is added to avoid the following log message when no repo specified or the repo is empty: > Error while walking repo dir path=/workflow err=lstat /workflow: > no such file or directory In addition, walk/chown errors log level is changed to warning to highlight possible issues.
1 parent 5fd6545 commit 008efc8

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

runner/internal/executor/repo.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -236,16 +236,25 @@ func (ex *RunExecutor) restoreRepoDir(ctx context.Context, tmpDir string) error
236236

237237
func (ex *RunExecutor) chownRepoDir(ctx context.Context) error {
238238
log.Trace(ctx, "Chowning repo dir")
239+
exists, err := common.PathExists(ex.repoDir)
240+
// We consider all errors here non-fatal
241+
if err != nil {
242+
log.Warning(ctx, "Failed to check if repo dir exists", "err", err)
243+
return nil
244+
}
245+
if !exists {
246+
log.Trace(ctx, "Repo dir does not exist")
247+
return nil
248+
}
239249
return filepath.WalkDir(
240250
ex.repoDir,
241251
func(p string, d fs.DirEntry, err error) error {
242-
// We consider walk/chown errors non-fatal
243252
if err != nil {
244-
log.Debug(ctx, "Error while walking repo dir", "path", p, "err", err)
253+
log.Warning(ctx, "Error while walking repo dir", "path", p, "err", err)
245254
return nil
246255
}
247256
if err := os.Chown(p, ex.jobUser.Uid, ex.jobUser.Gid); err != nil {
248-
log.Debug(ctx, "Error while chowning repo dir", "path", p, "err", err)
257+
log.Warning(ctx, "Error while chowning repo dir", "path", p, "err", err)
249258
}
250259
return nil
251260
},

0 commit comments

Comments
 (0)