Skip to content

Commit

Permalink
ignore symlinks
Browse files Browse the repository at this point in the history
  • Loading branch information
Itay Donanhirsh committed Feb 14, 2021
1 parent 770761f commit c11f6fc
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 8 deletions.
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,18 @@ These tags are written as a normal tag to the index, with an added attribute `se
* somewhere:1.1-19 lang=hs search=glob
```

### Pragma Tags

There are only two pragma tags implemented: `%stop` and `%cont`. Example:

```
[# to_be #]
[# %stop #]
[# or_not_to_be #]
[# %cont #]
[# that_is_the_question #]
```

## Index

To generate an index, use:
Expand Down Expand Up @@ -178,6 +190,12 @@ scanner:
right: "#]"
```
## Caveats
- Only textual files are scanned.
- Tags are scanned whether they are in a comment or not.
- Links are ignored.
## Integrations
- [Vim Plugin](https://github.com/cluttercode/vim-clutter)
Expand Down
6 changes: 3 additions & 3 deletions cmd/clutter/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ func readIndex(c *cli.Context) (*index.Index, error) {
continue
}

if path == "" {
path = "stdin"
if path != "" {
path = path + ": "
}

return nil, fmt.Errorf("%s: %w", path, err)
return nil, fmt.Errorf("%s%w", path, err)
}

z.Infow("index read", "n", idx.Size())
Expand Down
21 changes: 18 additions & 3 deletions internal/pkg/scanner/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,29 @@ func NewFilter(z *zap.SugaredLogger, cfg Config) (func(string, os.FileInfo) (boo
exclude := gitignore.NewMatcher(ignores).Match

return func(path string, fi os.FileInfo) (bool, error) {
isDir := fi != nil && fi.IsDir()
var (
isDir, isLink bool
mode os.FileMode
)

if fi != nil {
mode = fi.Mode()
isDir = fi.IsDir()
isLink = mode&os.ModeSymlink != 0
}

split := strings.Split(path, string(filepath.Separator))

z := z.With("path", split, "is_dir", isDir)
z := z.With("path", split, "is_link", isLink, "is_dir", isDir, "mode", mode)

if isLink {
z.Debug("links are excluded")

return false, nil
}

if exclude(split, isDir) {
z.Debug("exclude")
z.Debug("exclude dir")

if isDir {
return false, filepath.SkipDir
Expand Down
2 changes: 0 additions & 2 deletions internal/pkg/scanner/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ func ScanReader(
for i := 0; scanner.Scan(); i++ {
line := scanner.Text()

z.Debugw("read", "line", line)

ms := re.FindAllStringIndex(line, -1)

for _, m := range ms {
Expand Down

0 comments on commit c11f6fc

Please sign in to comment.