From ab63985d1de21b98d9c41ed73b8886a16e04b7df Mon Sep 17 00:00:00 2001 From: raghavharness Date: Mon, 12 Dec 2022 14:08:40 +0530 Subject: [PATCH 1/2] Added warn log if only directory is present among the matches of the glob expression --- plugin.go | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/plugin.go b/plugin.go index eca3a7a..5a2cabf 100644 --- a/plugin.go +++ b/plugin.go @@ -148,14 +148,8 @@ func (p *Plugin) Exec() error { } for _, match := range matches { - - stat, err := os.Stat(match) - if err != nil { - continue // should never happen - } - // skip directories - if stat.IsDir() { + if IsDir(match, matches) { continue } @@ -317,3 +311,24 @@ func resolveKey(target, srcPath, stripPrefix string) string { } return key } + +// checks if the source path is a dir +func IsDir(source string, matches []string) bool { + stat, err := os.Stat(source) + if err != nil { + return true // should never happen + } + if (stat.IsDir()) { + count := 0 + for _, match := range matches { + if strings.HasPrefix(match, source) { + count++; + } + } + if count <= 1 { + log.Warnf("Skipping '%s' since it is a directory. Please use correct glob expression if this is unexpected.", source) + } + return true; + } + return false +} From 669d451e6dc124355a70b737dc324c261902df65 Mon Sep 17 00:00:00 2001 From: raghavharness Date: Mon, 12 Dec 2022 17:32:28 +0530 Subject: [PATCH 2/2] small fix --- plugin.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugin.go b/plugin.go index 5a2cabf..b4757e4 100644 --- a/plugin.go +++ b/plugin.go @@ -149,7 +149,7 @@ func (p *Plugin) Exec() error { for _, match := range matches { // skip directories - if IsDir(match, matches) { + if isDir(match, matches) { continue } @@ -313,7 +313,7 @@ func resolveKey(target, srcPath, stripPrefix string) string { } // checks if the source path is a dir -func IsDir(source string, matches []string) bool { +func isDir(source string, matches []string) bool { stat, err := os.Stat(source) if err != nil { return true // should never happen