Skip to content

Commit 96621b5

Browse files
authored
Replace godirwalk with fs.WalkDir (#23)
1 parent 1564449 commit 96621b5

29 files changed

+20
-1781
lines changed

go.mod

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ require (
2020
github.com/google/go-containerregistry v0.19.1
2121
github.com/google/go-github v17.0.0+incompatible
2222
github.com/google/slowjam v1.1.1
23-
github.com/karrick/godirwalk v1.16.1
2423
github.com/minio/highwayhash v1.0.2
2524
github.com/moby/buildkit v0.13.1
2625
github.com/otiai10/copy v1.14.0

go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -327,8 +327,6 @@ github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfC
327327
github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
328328
github.com/json-iterator/go v1.1.7/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
329329
github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
330-
github.com/karrick/godirwalk v1.16.1 h1:DynhcF+bztK8gooS0+NDJFrdNZjJ3gzVzC545UNA9iw=
331-
github.com/karrick/godirwalk v1.16.1/go.mod h1:j4mkqPuvaLI8mp1DroR3P6ad7cyYd4c1qeJ3RV7ULlk=
332330
github.com/kevinburke/ssh_config v1.2.0 h1:x584FjTGwHzMwvHx18PXxbBVzfnxogHaAReU4gf13a4=
333331
github.com/kevinburke/ssh_config v1.2.0/go.mod h1:CT57kijsi8u/K/BOFA39wgDQJ9CxiF4nAY/ojJ6r6mM=
334332
github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00=

pkg/util/fs_util.go

Lines changed: 20 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ import (
3636
"github.com/GoogleContainerTools/kaniko/pkg/timing"
3737
"github.com/docker/docker/pkg/archive"
3838
v1 "github.com/google/go-containerregistry/pkg/v1"
39-
"github.com/karrick/godirwalk"
4039
"github.com/moby/buildkit/frontend/dockerfile/dockerignore"
4140
"github.com/moby/patternmatcher"
4241
otiai10Cpy "github.com/otiai10/copy"
@@ -1262,7 +1261,7 @@ func gowalkDir(dir string, existingPaths map[string]struct{}, changeFunc func(st
12621261
foundPaths := make([]string, 0)
12631262
deletedFiles := existingPaths // Make a reference.
12641263

1265-
callback := func(path string, ent *godirwalk.Dirent) error {
1264+
callback := func(path string, ent fs.DirEntry, err error) error {
12661265
logrus.Tracef("Analyzing path '%s'", path)
12671266

12681267
if IsInIgnoreList(path) {
@@ -1285,11 +1284,7 @@ func gowalkDir(dir string, existingPaths map[string]struct{}, changeFunc func(st
12851284
return nil
12861285
}
12871286

1288-
godirwalk.Walk(dir,
1289-
&godirwalk.Options{
1290-
Callback: callback,
1291-
Unsorted: true,
1292-
})
1287+
filesystem.WalkDir(dir, callback)
12931288

12941289
return walkFSResult{foundPaths, deletedFiles}
12951290
}
@@ -1299,33 +1294,29 @@ func GetFSInfoMap(dir string, existing map[string]os.FileInfo) (map[string]os.Fi
12991294
fileMap := map[string]os.FileInfo{}
13001295
foundPaths := []string{}
13011296
timer := timing.Start("Walking filesystem with Stat")
1302-
godirwalk.Walk(dir, &godirwalk.Options{
1303-
Callback: func(path string, ent *godirwalk.Dirent) error {
1304-
if CheckCleanedPathAgainstIgnoreList(path) {
1305-
if IsDestDir(path) {
1306-
logrus.Tracef("Skipping paths under %s, as it is a ignored directory", path)
1307-
return filepath.SkipDir
1308-
}
1309-
return nil
1297+
filesystem.WalkDir(dir, func(path string, ent fs.DirEntry, err error) error {
1298+
if CheckCleanedPathAgainstIgnoreList(path) {
1299+
if IsDestDir(path) {
1300+
logrus.Tracef("Skipping paths under %s, as it is a ignored directory", path)
1301+
return filepath.SkipDir
13101302
}
1311-
if fi, err := filesystem.FS.Lstat(path); err == nil {
1312-
if fiPrevious, ok := existing[path]; ok {
1313-
// check if file changed
1314-
if !isSame(fiPrevious, fi) {
1315-
fileMap[path] = fi
1316-
foundPaths = append(foundPaths, path)
1317-
}
1318-
} else {
1319-
// new path
1303+
return nil
1304+
}
1305+
if fi, err := filesystem.FS.Lstat(path); err == nil {
1306+
if fiPrevious, ok := existing[path]; ok {
1307+
// check if file changed
1308+
if !isSame(fiPrevious, fi) {
13201309
fileMap[path] = fi
13211310
foundPaths = append(foundPaths, path)
13221311
}
1312+
} else {
1313+
// new path
1314+
fileMap[path] = fi
1315+
foundPaths = append(foundPaths, path)
13231316
}
1324-
return nil
1325-
},
1326-
Unsorted: true,
1327-
},
1328-
)
1317+
}
1318+
return nil
1319+
})
13291320
timing.DefaultRun.Stop(timer)
13301321
return fileMap, foundPaths
13311322
}

vendor/github.com/karrick/godirwalk/.gitignore

Lines changed: 0 additions & 19 deletions
This file was deleted.

vendor/github.com/karrick/godirwalk/LICENSE

Lines changed: 0 additions & 25 deletions
This file was deleted.

0 commit comments

Comments
 (0)