pkgsrc-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[pkgsrc/trunk]: pkgsrc/pkgtools/pkglint/files pkgtools/pkglint: increase perf...



details:   https://anonhg.NetBSD.org/pkgsrc/rev/90d366dcba69
branches:  trunk
changeset: 425047:90d366dcba69
user:      rillig <rillig%pkgsrc.org@localhost>
date:      Wed Mar 18 08:42:48 2020 +0000

description:
pkgtools/pkglint: increase performance

diffstat:

 pkgtools/pkglint/files/pkgsrc.go      |  12 +++++++-----
 pkgtools/pkglint/files/pkgsrc_test.go |   2 +-
 2 files changed, 8 insertions(+), 6 deletions(-)

diffs (50 lines):

diff -r e5f76b697422 -r 90d366dcba69 pkgtools/pkglint/files/pkgsrc.go
--- a/pkgtools/pkglint/files/pkgsrc.go  Wed Mar 18 08:25:06 2020 +0000
+++ b/pkgtools/pkglint/files/pkgsrc.go  Wed Mar 18 08:42:48 2020 +0000
@@ -885,9 +885,10 @@
        }
 
        var names []string
+       dir := src.File(category)
        for _, fileInfo := range src.ReadDir(category) {
                name := fileInfo.Name()
-               if matches(name, re) {
+               if matches(name, re) && !isEmptyDir(dir.JoinNoClean(NewRelPathString(name))) {
                        names = append(names, name)
                }
        }
@@ -1075,8 +1076,10 @@
 }
 
 // ReadDir lists the files and subdirectories from the given directory
-// (relative to the pkgsrc root), filtering out any ignored files (CVS/*)
-// and empty directories.
+// (relative to the pkgsrc root).
+//
+// The result may contain empty directories that are left over from CVS.
+// For performance reasons, the caller needs to filter these out; see isEmptyDir.
 func (src *Pkgsrc) ReadDir(dirName PkgsrcPath) []os.FileInfo {
        dir := src.File(dirName)
        files, err := dir.ReadDir()
@@ -1087,8 +1090,7 @@
        var relevantFiles []os.FileInfo
        for _, dirent := range files {
                name := dirent.Name()
-               // TODO: defer isEmptyDir, for performance reasons; run ktrace or strace to see why.
-               if !dirent.IsDir() || !isIgnoredFilename(name) && !isEmptyDir(dir.JoinNoClean(NewRelPathString(name))) {
+               if !dirent.IsDir() || !isIgnoredFilename(name) {
                        relevantFiles = append(relevantFiles, dirent)
                }
        }
diff -r e5f76b697422 -r 90d366dcba69 pkgtools/pkglint/files/pkgsrc_test.go
--- a/pkgtools/pkglint/files/pkgsrc_test.go     Wed Mar 18 08:25:06 2020 +0000
+++ b/pkgtools/pkglint/files/pkgsrc_test.go     Wed Mar 18 08:42:48 2020 +0000
@@ -1272,7 +1272,7 @@
                names = append(names, info.Name())
        }
 
-       t.CheckDeepEquals(names, []string{"aaa-subdir", "file", "subdir"})
+       t.CheckDeepEquals(names, []string{"aaa-subdir", "empty", "file", "subdir"})
 }
 
 func (s *Suite) Test_Pkgsrc_Relpath(c *check.C) {



Home | Main Index | Thread Index | Old Index