mirror of
https://github.com/schollz/croc.git
synced 2025-10-10 21:01:02 +02:00
Merge pull request #865 from schollz:schollz/issue864
croc: add --ignore to ignore folders with strings
This commit is contained in:
commit
14e805c53c
2 changed files with 24 additions and 2 deletions
|
@ -78,6 +78,7 @@ func Run() (err error) {
|
|||
&cli.IntFlag{Name: "port", Value: 9009, Usage: "base port for the relay"},
|
||||
&cli.IntFlag{Name: "transfers", Value: 4, Usage: "number of ports to use for transfers"},
|
||||
&cli.BoolFlag{Name: "qrcode", Aliases: []string{"qr"}, Usage: "show receive code as a qrcode"},
|
||||
&cli.StringFlag{Name: "exclude", Value: "", Usage: "exclude files if they contain any of the comma separated strings"},
|
||||
},
|
||||
HelpName: "croc send",
|
||||
Action: send,
|
||||
|
@ -274,6 +275,13 @@ func send(c *cli.Context) (err error) {
|
|||
if transfersParam == 0 {
|
||||
transfersParam = 4
|
||||
}
|
||||
excludeStrings := []string{}
|
||||
for _, v := range strings.Split(c.String("exclude"), ",") {
|
||||
v = strings.ToLower(strings.TrimSpace(v))
|
||||
if v != "" {
|
||||
excludeStrings = append(excludeStrings, v)
|
||||
}
|
||||
}
|
||||
|
||||
ports := make([]string, transfersParam+1)
|
||||
for i := 0; i <= transfersParam; i++ {
|
||||
|
@ -305,6 +313,7 @@ func send(c *cli.Context) (err error) {
|
|||
GitIgnore: c.Bool("git"),
|
||||
ShowQrCode: c.Bool("qrcode"),
|
||||
MulticastAddress: c.String("multicast"),
|
||||
Exclude: excludeStrings,
|
||||
}
|
||||
if crocOptions.RelayAddress != models.DEFAULT_RELAY {
|
||||
crocOptions.RelayAddress6 = ""
|
||||
|
@ -418,7 +427,7 @@ Or you can go back to the classic croc behavior by enabling classic mode:
|
|||
// generate code phrase
|
||||
crocOptions.SharedSecret = utils.GetRandomName()
|
||||
}
|
||||
minimalFileInfos, emptyFoldersToTransfer, totalNumberFolders, err := croc.GetFilesInfo(fnames, crocOptions.ZipFolder, crocOptions.GitIgnore)
|
||||
minimalFileInfos, emptyFoldersToTransfer, totalNumberFolders, err := croc.GetFilesInfo(fnames, crocOptions.ZipFolder, crocOptions.GitIgnore, crocOptions.Exclude)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
|
|
@ -87,6 +87,7 @@ type Options struct {
|
|||
GitIgnore bool
|
||||
MulticastAddress string
|
||||
ShowQrCode bool
|
||||
Exclude []string
|
||||
}
|
||||
|
||||
type SimpleMessage struct {
|
||||
|
@ -314,7 +315,7 @@ func isChild(parentPath, childPath string) bool {
|
|||
|
||||
// This function retrieves the important file information
|
||||
// for every file that will be transferred
|
||||
func GetFilesInfo(fnames []string, zipfolder bool, ignoreGit bool) (filesInfo []FileInfo, emptyFolders []FileInfo, totalNumberFolders int, err error) {
|
||||
func GetFilesInfo(fnames []string, zipfolder bool, ignoreGit bool, exclusions []string) (filesInfo []FileInfo, emptyFolders []FileInfo, totalNumberFolders int, err error) {
|
||||
// fnames: the relative/absolute paths of files/folders that will be transferred
|
||||
totalNumberFolders = 0
|
||||
var paths []string
|
||||
|
@ -379,6 +380,18 @@ func GetFilesInfo(fnames []string, zipfolder bool, ignoreGit bool) (filesInfo []
|
|||
}
|
||||
|
||||
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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue