Skip to content

Commit

Permalink
feat: Optimized fs walker and util.IsEmptyDir (#9433)
Browse files Browse the repository at this point in the history
  • Loading branch information
idsulik authored Jun 10, 2024
1 parent 1185081 commit 64585c1
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
4 changes: 3 additions & 1 deletion pkg/skaffold/docker/dependencies.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,8 @@ func WalkWorkspace(workspace string, excludes, deps []string) (map[string]bool,
if err != nil {
return err
}
if util.IsEmptyDir(path) || !info.IsDir() {

if !info.IsDir() || util.IsEmptyDir(path) {
files[relPath] = true
}

Expand All @@ -277,5 +278,6 @@ func WalkWorkspace(workspace string, excludes, deps []string) (map[string]bool,
return nil, fmt.Errorf("walking %q: %w", absFrom, err)
}
}

return files, nil
}
9 changes: 4 additions & 5 deletions pkg/skaffold/docker/syncmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,12 @@ func walkWorkspaceWithDestinations(workspace string, excludes []string, fts []Fr
switch mode := fi.Mode(); {
case mode.IsDir():
keepFile := func(path string, info walk.Dirent) (bool, error) {
if info.IsDir() && path == absFrom {
return true, nil
if info.IsDir() {
if path == absFrom || util.IsEmptyDir(path) {
return true, nil
}
}

if util.IsEmptyDir(path) {
return true, nil
}
ignored, err := dockerIgnored(path, info)
if err != nil {
return false, err
Expand Down
2 changes: 1 addition & 1 deletion pkg/skaffold/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ func IsEmptyDir(path string) bool {
return false
}
defer d.Close()
if _, err := d.ReadDir(1); err == io.EOF {
if _, err := d.Readdirnames(1); err == io.EOF {
return true
}
return false
Expand Down

0 comments on commit 64585c1

Please sign in to comment.