Bladeren bron

builder: use filepath.WalkDir instead of filepath.Walk

WalkDir is more performant as it doesn't perform an os.Lstat on every visited
file or directory.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Sebastiaan van Stijn 2 jaren geleden
bovenliggende
commit
1870d5f4aa
3 gewijzigde bestanden met toevoegingen van 4 en 4 verwijderingen
  1. 2 2
      builder/dockerfile/copy.go
  2. 1 1
      builder/dockerfile/copy_unix.go
  3. 1 1
      builder/remotecontext/tarsum.go

+ 2 - 2
builder/dockerfile/copy.go

@@ -258,7 +258,7 @@ func (o *copier) storeInPathCache(im *imageMount, path string, hash string) {
 func (o *copier) copyWithWildcards(origPath string) ([]copyInfo, error) {
 	root := o.source.Root()
 	var copyInfos []copyInfo
-	if err := filepath.Walk(root, func(path string, info os.FileInfo, err error) error {
+	if err := filepath.WalkDir(root, func(path string, _ os.DirEntry, err error) error {
 		if err != nil {
 			return err
 		}
@@ -316,7 +316,7 @@ func walkSource(source builder.Source, origPath string) ([]string, error) {
 	}
 	// Must be a dir
 	var subfiles []string
-	err = filepath.Walk(fp, func(path string, info os.FileInfo, err error) error {
+	err = filepath.WalkDir(fp, func(path string, _ os.DirEntry, err error) error {
 		if err != nil {
 			return err
 		}

+ 1 - 1
builder/dockerfile/copy_unix.go

@@ -26,7 +26,7 @@ func fixPermissions(source, destination string, identity idtools.Identity, overr
 
 	// We Walk on the source rather than on the destination because we don't
 	// want to change permissions on things we haven't created or modified.
-	return filepath.Walk(source, func(fullpath string, _ os.FileInfo, _ error) error {
+	return filepath.WalkDir(source, func(fullpath string, _ os.DirEntry, _ error) error {
 		// Do not alter the walk root iff. it existed before, as it doesn't fall under
 		// the domain of "things we should chown".
 		if skipChownRoot && source == fullpath {

+ 1 - 1
builder/remotecontext/tarsum.go

@@ -66,7 +66,7 @@ func (cs *CachableSource) Scan() error {
 		return err
 	}
 	txn := iradix.New().Txn()
-	err = filepath.Walk(cs.root, func(path string, info os.FileInfo, err error) error {
+	err = filepath.WalkDir(cs.root, func(path string, _ os.DirEntry, err error) error {
 		if err != nil {
 			return errors.Wrapf(err, "failed to walk %s", path)
 		}