summaryrefslogtreecommitdiff
path: root/pkg/bindings/images
diff options
context:
space:
mode:
authorDaniel J Walsh <dwalsh@redhat.com>2022-03-26 06:39:11 -0400
committerDaniel J Walsh <dwalsh@redhat.com>2022-03-27 07:18:25 -0400
commitd106b294b428fbb10f59d4cafe72c3dcaa4e73bb (patch)
tree3c81aa0b8452565c704629258643eb6c51b82b3e /pkg/bindings/images
parent56b2937f87bd67b46aa93109aefc08ce0edb5cf1 (diff)
downloadpodman-d106b294b428fbb10f59d4cafe72c3dcaa4e73bb.tar.gz
podman-d106b294b428fbb10f59d4cafe72c3dcaa4e73bb.tar.bz2
podman-d106b294b428fbb10f59d4cafe72c3dcaa4e73bb.zip
Switch all calls to filepath.Walk to filepath.WalkDir
WalkDir should be faster the Walk, since we often do not need to stat files. [NO NEW TESTS NEEDED] Existing tests should find errors. Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
Diffstat (limited to 'pkg/bindings/images')
-rw-r--r--pkg/bindings/images/build.go23
1 files changed, 18 insertions, 5 deletions
diff --git a/pkg/bindings/images/build.go b/pkg/bindings/images/build.go
index e1b427742..f6739b7ca 100644
--- a/pkg/bindings/images/build.go
+++ b/pkg/bindings/images/build.go
@@ -7,6 +7,7 @@ import (
"encoding/json"
"fmt"
"io"
+ "io/fs"
"io/ioutil"
"net/http"
"net/url"
@@ -557,14 +558,14 @@ func nTar(excludes []string, sources ...string) (io.ReadCloser, error) {
merr = multierror.Append(merr, err)
return
}
- err = filepath.Walk(s, func(path string, info os.FileInfo, err error) error {
+ err = filepath.WalkDir(s, func(path string, d fs.DirEntry, err error) error {
if err != nil {
return err
}
// check if what we are given is an empty dir, if so then continue w/ it. Else return.
// if we are given a file or a symlink, we do not want to exclude it.
- if info.IsDir() && s == path {
+ if d.IsDir() && s == path {
var p *os.File
p, err = os.Open(path)
if err != nil {
@@ -588,7 +589,11 @@ func nTar(excludes []string, sources ...string) (io.ReadCloser, error) {
return nil
}
- if info.Mode().IsRegular() { // add file item
+ if d.Type().IsRegular() { // add file item
+ info, err := d.Info()
+ if err != nil {
+ return err
+ }
di, isHardLink := checkHardLink(info)
if err != nil {
return err
@@ -624,7 +629,11 @@ func nTar(excludes []string, sources ...string) (io.ReadCloser, error) {
seen[di] = name
}
return err
- } else if info.Mode().IsDir() { // add folders
+ } else if d.IsDir() { // add folders
+ info, err := d.Info()
+ if err != nil {
+ return err
+ }
hdr, lerr := tar.FileInfoHeader(info, name)
if lerr != nil {
return lerr
@@ -634,11 +643,15 @@ func nTar(excludes []string, sources ...string) (io.ReadCloser, error) {
if lerr := tw.WriteHeader(hdr); lerr != nil {
return lerr
}
- } else if info.Mode()&os.ModeSymlink != 0 { // add symlinks as it, not content
+ } else if d.Type()&os.ModeSymlink != 0 { // add symlinks as it, not content
link, err := os.Readlink(path)
if err != nil {
return err
}
+ info, err := d.Info()
+ if err != nil {
+ return err
+ }
hdr, lerr := tar.FileInfoHeader(info, link)
if lerr != nil {
return lerr