Skip to content

Commit

Permalink
Merge pull request #115 from raghavharness/s3_dir_log
Browse files Browse the repository at this point in the history
Added warn log if only directory is present among the matches of the …
  • Loading branch information
TP Honey committed Dec 16, 2022
2 parents 094a359 + fd17dd9 commit 0dbdc6e
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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
}

0 comments on commit 0dbdc6e

Please sign in to comment.