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

Question - Supporting negation cases #49

Open
ansrivas opened this issue Nov 10, 2020 · 6 comments
Open

Question - Supporting negation cases #49

ansrivas opened this issue Nov 10, 2020 · 6 comments
Assignees

Comments

@ansrivas
Copy link

Hello,
Thank you for your work on this library.

I have a use case where I'd exclude files and include others. I skimmed through the test-cases as well but I couldn't find, hence the query.

Reproducing steps:

$ mkdir -p level1/level2/

$ touch level1/level2/{a.stderr.0,a.stdout.0,ignore.stderr.0,ignore.stdout.0,b.stderr.0,b.stdout.0}

$ ls level1/level2/!(ignore*).std* 
level1/level2/a.stderr.0  level1/level2/a.stdout.0  level1/level2/b.stderr.0  level1/level2/b.stdout.0

Corresponding go-snippet:

$ cat main.go
package main

import (
	"fmt"

	"github.com/bmatcuk/doublestar/v2"
)

func main() {
	matched, err := doublestar.Glob("level1/level2/!(ignore*).std* ")
	if err != nil {
		panic(err)
	}

        // So here we find no matched files
	if len(matched) == 0 {
		panic(fmt.Errorf("No matched files found"))
	}
	for _, match := range matched {
		fmt.Println(match)
	}
}

Is this by design or it could be a feature worth supporting in the library?

@bmatcuk bmatcuk self-assigned this Nov 10, 2020
@bmatcuk
Copy link
Owner

bmatcuk commented Nov 10, 2020

Hi @ansrivas - doublestar doesn't support negation, but that could be an interesting feature. For the time being, you could accomplish it by using a very inclusive pattern with Glob() (such as level1/level2/*) and then use Match() to filter out results matching your negative pattern (level1/level2/ignore*.std*).

@ansrivas
Copy link
Author

ansrivas commented Nov 10, 2020

Thank you for your response @bmatcuk . I also figured we could use that.
Just for the background, promtail from grafana uses doublestar to support file-glob/match.

Seems I should open this as an issue upstream:
https://github.com/grafana/loki/blob/b9534c65b357b04049b57350da68be12b950521d/pkg/promtail/targets/file/filetarget.go#L180

@rgl
Copy link

rgl commented Jun 5, 2021

@ansrivas, did you open an issue in upstream about using another Match to exclude results?

PS in the mean time, I've created an issue in upstream at grafana/loki#3804

@ansrivas
Copy link
Author

ansrivas commented Jun 5, 2021

Hi @rgl no, unfortunately, we maintained a local fork to work on it. Thanks for opening this upstream.

@michaelkebe
Copy link

@ansrivas Could you publish your local fork? Could you create a PR at grafana/loki?

@fordneild
Copy link

Hello! This package is used by the otel-collector, and Im running into an issue where negation is not supported. Is there any workaround or plan to fix? Thanks!

jamietanna pushed a commit to elastic/monorepo-diff-buildkite-plugin that referenced this issue Oct 8, 2024
As part of adikari#20, we want to be able to negate specific paths in a given
`watch` path by using `skip_path`.

This PR adds support for specifying a `skip_path` option that support
either a path or a list of paths that shouldn't result in adding the
`trigger` step as part of the dynamically generated pipeline.

Note even in cases where a line in the `diff` is skipped due to
`skip_path` and there are other paths in the `diff` that match `path`
but doesn't match `skip_path`, the step will still be added to the
dynamically generated pipeline. i.e. for the step to be effectively
ignored, the paths in `skip_path` should match all of those in the given
`diff`.

This is required due to the lack of support for negation cases in
`doublestar`, which we use for glob pattern matching[0].

Closes adikari#20.

[0]: bmatcuk/doublestar#49
jamietanna pushed a commit to elastic/monorepo-diff-buildkite-plugin that referenced this issue Oct 24, 2024
As part of adikari#20, we want to be able to negate specific paths in a given
`watch` path by using `skip_path`.

This PR adds support for specifying a `skip_path` option that support
either a path or a list of paths that shouldn't result in adding the
`trigger` step as part of the dynamically generated pipeline.

Note even in cases where a line in the `diff` is skipped due to
`skip_path` and there are other paths in the `diff` that match `path`
but doesn't match `skip_path`, the step will still be added to the
dynamically generated pipeline. i.e. for the step to be effectively
ignored, the paths in `skip_path` should match all of those in the given
`diff`.

This is required due to the lack of support for negation cases in
`doublestar`, which we use for glob pattern matching[0].

Closes adikari#20.

[0]: bmatcuk/doublestar#49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants