pathspec-ruby
pathspec-ruby copied to clipboard
How to implement a deny list?
Hi! I'm struggling to implement something and I hope you could help me out. I've some ruby code that parses a file with .gitignore style filters and afterward creates a tar archive:
https://github.com/puppetlabs/puppet-modulebuilder/blob/main/lib/puppet/modulebuilder/builder.rb#L251-L268 (ignore_file is set to .pmtigore) -> https://github.com/puppetlabs/puppet-modulebuilder/blob/main/lib/puppet/modulebuilder/builder.rb#L149-L153 -> https://github.com/puppetlabs/puppet-modulebuilder/blob/main/lib/puppet/modulebuilder/builder.rb#L76-L92
Current .pmtignore is something like this:
/docs/
/pkg/
/Gemfile
/Gemfile.lock
/Gemfile.local
/vendor/
/.vendor/
/spec/
/Rakefile
/.vagrant/
/.bundle/
/.ruby-version
/coverage/
/log/
/.idea/
/.dependencies/
/.github/
/.librarian/
/Puppetfile.lock
*.iml
/.editorconfig
/.fixtures.yml
/.gitignore
/.msync.yml
/.overcommit.yml
/.pmtignore
/.rspec
/.rspec_parallel
/.rubocop.yml
/.sync.yml
.*.sw?
/.yardoc/
/.yardopts
/Dockerfile
/HISTORY.md
And I need to switch from an denylist to an allowlist, roughly:
*
!/manifests
!/README*
!/metadata.json
!/LICENSE
!/hiera.yaml
!/data
!/templates
!/files
!/CHANGELOG*
!/docs
!/REFERENCE.md
!/locales
!/scripts
!/tasks
!/plans
!/types
!/bolt_plugin.json
So I want to exclude everything except for the directories/files prefixed with a !. When I use this new filter I always end up with some empty directories that aren't supposed to be there:
- the whole spec dir should have been excluded
- there are files missing in the
manifests/directory
.
├── CHANGELOG.md
├── examples
├── files
├── lib
│ ├── facter
│ ├── puppet
│ │ ├── functions
│ │ │ └── archive
│ │ ├── provider
│ │ │ └── archive
│ │ └── type
│ └── puppet_x
│ └── bodeco
├── LICENSE
├── manifests
├── metadata.json
├── README.md
├── REFERENCE.md
└── spec
├── acceptance
├── classes
├── defines
├── fixtures
│ ├── checksum
│ └── manifests
├── functions
├── hosts
├── support
└── unit
├── facter
├── puppet
│ ├── provider
│ │ └── archive
│ └── type
└── puppet_x
└── bodeco