Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: --exclude should exclude recursive files #867

Merged
merged 1 commit into from
Dec 31, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 57 additions & 14 deletions src/croc/croc.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,15 @@ func isChild(parentPath, childPath string) bool {
return !strings.HasPrefix(relPath, "..")
}

func recursiveFiles(path string) (paths []string, err error) {
paths = []string{strings.ToLower(path)}
err = filepath.Walk(path, func(path string, info os.FileInfo, err error) error {
paths = append(paths, strings.ToLower(path))
return nil
})
return
}

// This function retrieves the important file information
// for every file that will be transferred
func GetFilesInfo(fnames []string, zipfolder bool, ignoreGit bool, exclusions []string) (filesInfo []FileInfo, emptyFolders []FileInfo, totalNumberFolders int, err error) {
Expand Down Expand Up @@ -380,18 +389,6 @@ func GetFilesInfo(fnames []string, zipfolder bool, ignoreGit bool, exclusions []
}

absPath, errAbs := filepath.Abs(fpath)
absPathLower := strings.ToLower(absPath)
ignorePath := false
for _, exclusion := range exclusions {
if strings.Contains(absPathLower, exclusion) {
ignorePath = true
break
}
}
if ignorePath {
log.Debugf("Ignoring %s", absPath)
continue
}

if errAbs != nil {
err = errAbs
Expand Down Expand Up @@ -426,6 +423,21 @@ func GetFilesInfo(fnames []string, zipfolder bool, ignoreGit bool, exclusions []
TempFile: true,
IsIgnored: ignoredPaths[absPath],
}
// check if exclusions apply to this file
if len(exclusions) > 0 && !fInfo.IsIgnored {
allFiles, _ := recursiveFiles(absPath)
for _, exclusion := range exclusions {
for _, file := range allFiles {
if strings.Contains(strings.ToLower(file), strings.ToLower(exclusion)) {
fInfo.IsIgnored = true
break
}
}
if fInfo.IsIgnored {
break
}
}
}
if fInfo.IsIgnored {
continue
}
Expand Down Expand Up @@ -458,7 +470,23 @@ func GetFilesInfo(fnames []string, zipfolder bool, ignoreGit bool, exclusions []
TempFile: false,
IsIgnored: ignoredPaths[pathName],
}
if fInfo.IsIgnored && ignoreGit {
// check if exclusions apply to this file
if len(exclusions) > 0 && !fInfo.IsIgnored {
allFiles, _ := recursiveFiles(pathName)
for _, exclusion := range exclusions {
for _, file := range allFiles {
log.Tracef("ignoring test: %s %s %v", strings.ToLower(file), strings.ToLower(exclusion), strings.Contains(strings.ToLower(file), strings.ToLower(exclusion)))
if strings.Contains(strings.ToLower(file), strings.ToLower(exclusion)) {
fInfo.IsIgnored = true
break
}
}
if fInfo.IsIgnored {
break
}
}
}
if fInfo.IsIgnored && (ignoreGit || len(exclusions) > 0) {
return nil
} else {
filesInfo = append(filesInfo, fInfo)
Expand Down Expand Up @@ -494,7 +522,22 @@ func GetFilesInfo(fnames []string, zipfolder bool, ignoreGit bool, exclusions []
TempFile: false,
IsIgnored: ignoredPaths[absPath],
}
if fInfo.IsIgnored && ignoreGit {
if len(exclusions) > 0 && !fInfo.IsIgnored {
allFiles, _ := recursiveFiles(absPath)
for _, exclusion := range exclusions {
for _, file := range allFiles {
log.Tracef("ignoring test: %s %s %v", strings.ToLower(file), strings.ToLower(exclusion), strings.Contains(strings.ToLower(file), strings.ToLower(exclusion)))
if strings.Contains(strings.ToLower(file), strings.ToLower(exclusion)) {
fInfo.IsIgnored = true
break
}
}
if fInfo.IsIgnored {
break
}
}
}
if fInfo.IsIgnored && (ignoreGit || len(exclusions) > 0) {
continue
} else {
filesInfo = append(filesInfo, fInfo)
Expand Down
Loading