Skip to content

Commit

Permalink
fix input path prefx when subdir is used
Browse files Browse the repository at this point in the history
  • Loading branch information
easeway committed Jan 5, 2022
1 parent 8a5d38c commit 207a13c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
9 changes: 5 additions & 4 deletions pkg/repos/filescache.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,15 @@ func NewFilesCache(xctx *ToolExecContext) *FilesCache {
// AddInput implements Cache.
func (s *FilesCache) AddInput(relPath string, recursive bool) error {
if recursive {
return filepath.Walk(filepath.Join(s.xctx.ProjectDir(), relPath), func(path string, info os.FileInfo, err error) error {
return filepath.Walk(filepath.Join(s.xctx.SourceDir(), relPath), func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}
s.addInputEntry(path, &fileEntry{Dir: info.IsDir(), MTime: info.ModTime()})
return nil
})
}
fn := filepath.Join(s.xctx.ProjectDir(), relPath)
fn := filepath.Join(s.xctx.SourceDir(), relPath)
fi, err := os.Stat(fn)
if err != nil {
return err
Expand All @@ -83,8 +83,9 @@ func (s *FilesCache) AddSource(relPath string, recursive bool) error {
}

func (s *FilesCache) addInputEntry(fn string, entry *fileEntry) {
s.current.Inputs[fn] = entry
s.xctx.Logger.Printf("Input %q %s", fn[len(s.xctx.ProjectDir())+1:], entry.String())
key := filepath.Clean(fn)
s.current.Inputs[key] = entry
s.xctx.Logger.Printf("Input %q %s", key, entry.String())
}

// AddOutput implements Cache.
Expand Down
3 changes: 2 additions & 1 deletion pkg/tools/go/tool.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ func (x *Executor) validateCache(ctx context.Context, xctx *repos.ToolExecContex
return false
}

prefix := xctx.ProjectDir() + string(filepath.Separator)
prefix := strings.TrimRight(filepath.Clean(xctx.SourceDir()), string(filepath.Separator)) + string(filepath.Separator)
decoder := json.NewDecoder(&out)
for {
var pkg listPackage
Expand All @@ -164,6 +164,7 @@ func (x *Executor) validateCache(ctx context.Context, xctx *repos.ToolExecContex
xctx.Logger.Printf("parse output of go list error: %v", err)
return false
}
xctx.Logger.Printf("Package dir=%q prefix=%q", pkg.Dir, prefix)
if !strings.HasPrefix(pkg.Dir, prefix) {
continue
}
Expand Down

0 comments on commit 207a13c

Please sign in to comment.