Skip to content

Commit 14e805c

Browse files
authored
Merge pull request #865 from schollz:schollz/issue864
croc: add --ignore to ignore folders with strings
2 parents bc5063e + 537d514 commit 14e805c

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

src/cli/cli.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ func Run() (err error) {
7878
&cli.IntFlag{Name: "port", Value: 9009, Usage: "base port for the relay"},
7979
&cli.IntFlag{Name: "transfers", Value: 4, Usage: "number of ports to use for transfers"},
8080
&cli.BoolFlag{Name: "qrcode", Aliases: []string{"qr"}, Usage: "show receive code as a qrcode"},
81+
&cli.StringFlag{Name: "exclude", Value: "", Usage: "exclude files if they contain any of the comma separated strings"},
8182
},
8283
HelpName: "croc send",
8384
Action: send,
@@ -274,6 +275,13 @@ func send(c *cli.Context) (err error) {
274275
if transfersParam == 0 {
275276
transfersParam = 4
276277
}
278+
excludeStrings := []string{}
279+
for _, v := range strings.Split(c.String("exclude"), ",") {
280+
v = strings.ToLower(strings.TrimSpace(v))
281+
if v != "" {
282+
excludeStrings = append(excludeStrings, v)
283+
}
284+
}
277285

278286
ports := make([]string, transfersParam+1)
279287
for i := 0; i <= transfersParam; i++ {
@@ -305,6 +313,7 @@ func send(c *cli.Context) (err error) {
305313
GitIgnore: c.Bool("git"),
306314
ShowQrCode: c.Bool("qrcode"),
307315
MulticastAddress: c.String("multicast"),
316+
Exclude: excludeStrings,
308317
}
309318
if crocOptions.RelayAddress != models.DEFAULT_RELAY {
310319
crocOptions.RelayAddress6 = ""
@@ -418,7 +427,7 @@ Or you can go back to the classic croc behavior by enabling classic mode:
418427
// generate code phrase
419428
crocOptions.SharedSecret = utils.GetRandomName()
420429
}
421-
minimalFileInfos, emptyFoldersToTransfer, totalNumberFolders, err := croc.GetFilesInfo(fnames, crocOptions.ZipFolder, crocOptions.GitIgnore)
430+
minimalFileInfos, emptyFoldersToTransfer, totalNumberFolders, err := croc.GetFilesInfo(fnames, crocOptions.ZipFolder, crocOptions.GitIgnore, crocOptions.Exclude)
422431
if err != nil {
423432
return
424433
}

src/croc/croc.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ type Options struct {
8787
GitIgnore bool
8888
MulticastAddress string
8989
ShowQrCode bool
90+
Exclude []string
9091
}
9192

9293
type SimpleMessage struct {
@@ -314,7 +315,7 @@ func isChild(parentPath, childPath string) bool {
314315

315316
// This function retrieves the important file information
316317
// for every file that will be transferred
317-
func GetFilesInfo(fnames []string, zipfolder bool, ignoreGit bool) (filesInfo []FileInfo, emptyFolders []FileInfo, totalNumberFolders int, err error) {
318+
func GetFilesInfo(fnames []string, zipfolder bool, ignoreGit bool, exclusions []string) (filesInfo []FileInfo, emptyFolders []FileInfo, totalNumberFolders int, err error) {
318319
// fnames: the relative/absolute paths of files/folders that will be transferred
319320
totalNumberFolders = 0
320321
var paths []string
@@ -379,6 +380,18 @@ func GetFilesInfo(fnames []string, zipfolder bool, ignoreGit bool) (filesInfo []
379380
}
380381

381382
absPath, errAbs := filepath.Abs(fpath)
383+
absPathLower := strings.ToLower(absPath)
384+
ignorePath := false
385+
for _, exclusion := range exclusions {
386+
if strings.Contains(absPathLower, exclusion) {
387+
ignorePath = true
388+
break
389+
}
390+
}
391+
if ignorePath {
392+
log.Debugf("Ignoring %s", absPath)
393+
continue
394+
}
382395

383396
if errAbs != nil {
384397
err = errAbs

0 commit comments

Comments
 (0)