From 08f9d393e213c6c68984e0aa68b98dfe285db45e Mon Sep 17 00:00:00 2001 From: Zackary Scholl Date: Tue, 31 Dec 2024 08:57:34 -0800 Subject: [PATCH] fix: correctly apply exclusion filter --- src/cli/cli.go | 72 ++++++++++++++++++++++++-------------------------- 1 file changed, 34 insertions(+), 38 deletions(-) diff --git a/src/cli/cli.go b/src/cli/cli.go index a4c0495f4..b29077f5b 100644 --- a/src/cli/cli.go +++ b/src/cli/cli.go @@ -431,50 +431,46 @@ Or you can go back to the classic croc behavior by enabling classic mode: if err != nil { return } - minimalFileInfosInclude := []croc.FileInfo{} - exclusions := []string{} - for _, exclude := range crocOptions.Exclude { - exclusions = append(exclusions, strings.ToLower(exclude)) - } - for _, f := range minimalFileInfos { - exclude := false - for _, exclusion := range exclusions { - if strings.Contains(path.Join(strings.ToLower(f.FolderRemote), strings.ToLower(f.Name)), exclusion) { - exclude = true - break + if len(crocOptions.Exclude) > 0 { + minimalFileInfosInclude := []croc.FileInfo{} + emptyFoldersToTransferInclude := []croc.FileInfo{} + for _, f := range minimalFileInfos { + exclude := false + for _, exclusion := range crocOptions.Exclude { + if strings.Contains(path.Join(strings.ToLower(f.FolderRemote), strings.ToLower(f.Name)), exclusion) { + exclude = true + break + } + } + if !exclude { + minimalFileInfosInclude = append(minimalFileInfosInclude, f) } } - if !exclude { - minimalFileInfosInclude = append(minimalFileInfosInclude, f) - } - } - emptyFoldersToTransferInclude := []croc.FileInfo{} - for _, f := range emptyFoldersToTransfer { - exclude := false - for _, exclusion := range exclusions { - if strings.Contains(path.Join(strings.ToLower(f.FolderRemote), strings.ToLower(f.Name)), exclusion) { - exclude = true - break + for _, f := range emptyFoldersToTransfer { + exclude := false + for _, exclusion := range crocOptions.Exclude { + if strings.Contains(path.Join(strings.ToLower(f.FolderRemote), strings.ToLower(f.Name)), exclusion) { + exclude = true + break + } + } + if !exclude { + emptyFoldersToTransferInclude = append(emptyFoldersToTransferInclude, f) } } - if !exclude { - emptyFoldersToTransferInclude = append(emptyFoldersToTransferInclude, f) + totalNumberFolders = 0 + folderMap := make(map[string]bool) + for _, f := range minimalFileInfosInclude { + folderMap[f.FolderRemote] = true } + for _, f := range emptyFoldersToTransferInclude { + folderMap[f.FolderRemote] = true + } + totalNumberFolders = len(folderMap) + minimalFileInfos = minimalFileInfosInclude + emptyFoldersToTransfer = emptyFoldersToTransferInclude } - totalNumberFolders = 0 - folderMap := make(map[string]bool) - for _, f := range minimalFileInfosInclude { - folderMap[f.FolderRemote] = true - log.Tracef("zxvc file: %+v", f) - // is folder - } - for _, f := range emptyFoldersToTransferInclude { - log.Tracef("zxvc folder: %+v", f) - } - totalNumberFolders = len(folderMap) - log.Debugf("zxvc total number of folders: %d", totalNumberFolders) - cr, err := croc.New(crocOptions) if err != nil { return @@ -483,7 +479,7 @@ Or you can go back to the classic croc behavior by enabling classic mode: // save the config saveConfig(c, crocOptions) - err = cr.Send(minimalFileInfosInclude, emptyFoldersToTransferInclude, totalNumberFolders) + err = cr.Send(minimalFileInfos, emptyFoldersToTransfer, totalNumberFolders) return }