Skip to content

Commit

Permalink
ignore node_modules/.cache
Browse files Browse the repository at this point in the history
  • Loading branch information
zuzuleinen committed Dec 15, 2022
1 parent be8ddb2 commit 00c64f2
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
4 changes: 4 additions & 0 deletions bobtask/artifact_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"strings"
"time"

target2 "github.com/benchkram/bob/bobtask/target"
"github.com/benchkram/bob/pkg/filehash"
"github.com/benchkram/errz"
"github.com/mholt/archiver/v3"
Expand Down Expand Up @@ -79,6 +80,9 @@ func (t *Task) ArtifactCreate(artifactName hash.In) (err error) {
// targets filesystem
var files []File
for fname := range buildInfo.Filesystem.Files {
if target2.ShouldIgnore(fname) {
continue
}
info, err := os.Lstat(fname)
errz.Fatal(err)

Expand Down
6 changes: 6 additions & 0 deletions bobtask/target/buildinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ func (t *T) buildinfoFiles(paths []string) (bi buildinfo.BuildInfoFiles, _ error

if targetInfo.IsDir() {
if err := filepath.WalkDir(path, func(p string, f fs.DirEntry, err error) error {
if ShouldIgnore(p) {
return nil
}
if err != nil {
return err
}
Expand Down Expand Up @@ -86,6 +89,9 @@ func (t *T) buildinfoFiles(paths []string) (bi buildinfo.BuildInfoFiles, _ error
}
// TODO: what happens on a empty dir?
} else {
if ShouldIgnore(path) {
continue
}
err = h.AddFile(path)
if err != nil {
return buildinfo.BuildInfoFiles{}, fmt.Errorf("failed to hash target %q: %w", path, err)
Expand Down
18 changes: 18 additions & 0 deletions bobtask/target/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/hex"
"fmt"
"os"
"strings"

"github.com/benchkram/bob/pkg/boblog"
"github.com/benchkram/bob/pkg/filehash"
Expand Down Expand Up @@ -106,6 +107,10 @@ func (t *T) verifyFilesystemShallow(v *VerifyResult) bool {
}

for _, path := range *t.filesystemEntries {
if ShouldIgnore(path) {
continue
}

fileInfo, err := os.Lstat(path)
if err != nil {
return false
Expand Down Expand Up @@ -142,6 +147,19 @@ func (t *T) verifyFilesystemShallow(v *VerifyResult) bool {
return len(v.InvalidFiles) == 0
}

var IgnoredTargets = []string{"node_modules/.cache"}

// ShouldIgnore checks if file path should be ignored
// when creating/extracting artifact or creating the buildinfo
func ShouldIgnore(path string) bool {
for _, v := range IgnoredTargets {
if strings.HasPrefix(path, v) {
return true
}
}
return false
}

func (t *T) verifyFilesystem() bool {
if !t.preConditionsFilesystem() {
return false
Expand Down

0 comments on commit 00c64f2

Please sign in to comment.