chore: migrate to gitea
This commit is contained in:
21
vendor/github.com/sagikazarmark/locafero/.editorconfig
generated
vendored
Normal file
21
vendor/github.com/sagikazarmark/locafero/.editorconfig
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
root = true
|
||||
|
||||
[*]
|
||||
charset = utf-8
|
||||
end_of_line = lf
|
||||
indent_size = 4
|
||||
indent_style = space
|
||||
insert_final_newline = true
|
||||
trim_trailing_whitespace = true
|
||||
|
||||
[{Makefile,*.mk}]
|
||||
indent_style = tab
|
||||
|
||||
[*.nix]
|
||||
indent_size = 2
|
||||
|
||||
[*.go]
|
||||
indent_style = tab
|
||||
|
||||
[{*.yml,*.yaml}]
|
||||
indent_size = 2
|
||||
4
vendor/github.com/sagikazarmark/locafero/.envrc
generated
vendored
Normal file
4
vendor/github.com/sagikazarmark/locafero/.envrc
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
export DIRENV_WARN_TIMEOUT=20s
|
||||
|
||||
eval "$(devenv direnvrc)"
|
||||
use devenv
|
||||
5
vendor/github.com/sagikazarmark/locafero/.gitignore
generated
vendored
Normal file
5
vendor/github.com/sagikazarmark/locafero/.gitignore
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
# Devenv
|
||||
/.devenv*
|
||||
/.direnv/
|
||||
devenv.local.nix
|
||||
.pre-commit-config.yaml
|
||||
37
vendor/github.com/sagikazarmark/locafero/.golangci.yaml
generated
vendored
Normal file
37
vendor/github.com/sagikazarmark/locafero/.golangci.yaml
generated
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
version: "2"
|
||||
|
||||
run:
|
||||
timeout: 10m
|
||||
|
||||
linters:
|
||||
enable:
|
||||
- errcheck
|
||||
- govet
|
||||
- ineffassign
|
||||
- misspell
|
||||
- nolintlint
|
||||
- revive
|
||||
- staticcheck
|
||||
- unused
|
||||
|
||||
settings:
|
||||
misspell:
|
||||
locale: US
|
||||
nolintlint:
|
||||
allow-unused: false # report any unused nolint directives
|
||||
require-specific: false # don't require nolint directives to be specific about which linter is being skipped
|
||||
|
||||
formatters:
|
||||
enable:
|
||||
- gci
|
||||
- gofmt
|
||||
- gofumpt
|
||||
- goimports
|
||||
- golines
|
||||
|
||||
settings:
|
||||
gci:
|
||||
sections:
|
||||
- standard
|
||||
- default
|
||||
- localmodule
|
||||
19
vendor/github.com/sagikazarmark/locafero/LICENSE
generated
vendored
Normal file
19
vendor/github.com/sagikazarmark/locafero/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
Copyright (c) 2023 Márk Sági-Kazár <mark.sagikazar@gmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is furnished
|
||||
to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
37
vendor/github.com/sagikazarmark/locafero/README.md
generated
vendored
Normal file
37
vendor/github.com/sagikazarmark/locafero/README.md
generated
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
# Finder library for [Afero](https://github.com/spf13/afero)
|
||||
|
||||
[](https://github.com/sagikazarmark/locafero/actions/workflows/ci.yaml)
|
||||
[](https://pkg.go.dev/mod/github.com/sagikazarmark/locafero)
|
||||

|
||||
[](https://deps.dev/go/github.com%252Fsagikazarmark%252Flocafero)
|
||||
|
||||
**Finder library for [Afero](https://github.com/spf13/afero) ported from [go-finder](https://github.com/sagikazarmark/go-finder).**
|
||||
|
||||
> [!WARNING]
|
||||
> This is an experimental library under development.
|
||||
>
|
||||
> **Backwards compatibility is not guaranteed, expect breaking changes.**
|
||||
|
||||
## Installation
|
||||
|
||||
```shell
|
||||
go get github.com/sagikazarmark/locafero
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
Check out the [package example](https://pkg.go.dev/github.com/sagikazarmark/locafero#example-package) on go.dev.
|
||||
|
||||
## Development
|
||||
|
||||
**For an optimal developer experience, it is recommended to install [Nix](https://nixos.org/download.html) and [direnv](https://direnv.net/docs/installation.html).**
|
||||
|
||||
Run the test suite:
|
||||
|
||||
```shell
|
||||
just test
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
The project is licensed under the [MIT License](LICENSE).
|
||||
103
vendor/github.com/sagikazarmark/locafero/devenv.lock
generated
vendored
Normal file
103
vendor/github.com/sagikazarmark/locafero/devenv.lock
generated
vendored
Normal file
@@ -0,0 +1,103 @@
|
||||
{
|
||||
"nodes": {
|
||||
"devenv": {
|
||||
"locked": {
|
||||
"dir": "src/modules",
|
||||
"lastModified": 1758285954,
|
||||
"owner": "cachix",
|
||||
"repo": "devenv",
|
||||
"rev": "0f0e4c6921995ae9334b546eac71a5800621baa8",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"dir": "src/modules",
|
||||
"owner": "cachix",
|
||||
"repo": "devenv",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"flake-compat": {
|
||||
"flake": false,
|
||||
"locked": {
|
||||
"lastModified": 1747046372,
|
||||
"owner": "edolstra",
|
||||
"repo": "flake-compat",
|
||||
"rev": "9100a0f413b0c601e0533d1d94ffd501ce2e7885",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "edolstra",
|
||||
"repo": "flake-compat",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"git-hooks": {
|
||||
"inputs": {
|
||||
"flake-compat": "flake-compat",
|
||||
"gitignore": "gitignore",
|
||||
"nixpkgs": [
|
||||
"nixpkgs"
|
||||
]
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1758108966,
|
||||
"owner": "cachix",
|
||||
"repo": "git-hooks.nix",
|
||||
"rev": "54df955a695a84cd47d4a43e08e1feaf90b1fd9b",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "cachix",
|
||||
"repo": "git-hooks.nix",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"gitignore": {
|
||||
"inputs": {
|
||||
"nixpkgs": [
|
||||
"git-hooks",
|
||||
"nixpkgs"
|
||||
]
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1709087332,
|
||||
"owner": "hercules-ci",
|
||||
"repo": "gitignore.nix",
|
||||
"rev": "637db329424fd7e46cf4185293b9cc8c88c95394",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "hercules-ci",
|
||||
"repo": "gitignore.nix",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1755783167,
|
||||
"owner": "cachix",
|
||||
"repo": "devenv-nixpkgs",
|
||||
"rev": "4a880fb247d24fbca57269af672e8f78935b0328",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "cachix",
|
||||
"ref": "rolling",
|
||||
"repo": "devenv-nixpkgs",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"root": {
|
||||
"inputs": {
|
||||
"devenv": "devenv",
|
||||
"git-hooks": "git-hooks",
|
||||
"nixpkgs": "nixpkgs",
|
||||
"pre-commit-hooks": [
|
||||
"git-hooks"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"root": "root",
|
||||
"version": 7
|
||||
}
|
||||
17
vendor/github.com/sagikazarmark/locafero/devenv.nix
generated
vendored
Normal file
17
vendor/github.com/sagikazarmark/locafero/devenv.nix
generated
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
{ pkgs, ... }:
|
||||
|
||||
{
|
||||
cachix.pull = [ "sagikazarmark-dev" ];
|
||||
|
||||
languages = {
|
||||
go = {
|
||||
enable = true;
|
||||
package = pkgs.go_1_25;
|
||||
};
|
||||
};
|
||||
|
||||
packages = with pkgs; [
|
||||
just
|
||||
golangci-lint
|
||||
];
|
||||
}
|
||||
4
vendor/github.com/sagikazarmark/locafero/devenv.yaml
generated
vendored
Normal file
4
vendor/github.com/sagikazarmark/locafero/devenv.yaml
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
# yaml-language-server: $schema=https://devenv.sh/devenv.schema.json
|
||||
inputs:
|
||||
nixpkgs:
|
||||
url: github:cachix/devenv-nixpkgs/rolling
|
||||
32
vendor/github.com/sagikazarmark/locafero/file_type.go
generated
vendored
Normal file
32
vendor/github.com/sagikazarmark/locafero/file_type.go
generated
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
package locafero
|
||||
|
||||
import "io/fs"
|
||||
|
||||
// FileType represents the kind of entries [Finder] can return.
|
||||
type FileType int
|
||||
|
||||
// FileType represents the kind of entries [Finder] can return.
|
||||
const (
|
||||
FileTypeAny FileType = iota
|
||||
FileTypeFile
|
||||
FileTypeDir
|
||||
|
||||
// Deprecated: Use [FileTypeAny] instead.
|
||||
FileTypeAll = FileTypeAny
|
||||
)
|
||||
|
||||
func (ft FileType) match(info fs.FileInfo) bool {
|
||||
switch ft {
|
||||
case FileTypeAny:
|
||||
return true
|
||||
|
||||
case FileTypeFile:
|
||||
return info.Mode().IsRegular()
|
||||
|
||||
case FileTypeDir:
|
||||
return info.IsDir()
|
||||
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
171
vendor/github.com/sagikazarmark/locafero/finder.go
generated
vendored
Normal file
171
vendor/github.com/sagikazarmark/locafero/finder.go
generated
vendored
Normal file
@@ -0,0 +1,171 @@
|
||||
// Package locafero looks for files and directories in an {fs.Fs} filesystem.
|
||||
package locafero
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"io/fs"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/spf13/afero"
|
||||
|
||||
"github.com/sagikazarmark/locafero/internal/queue"
|
||||
)
|
||||
|
||||
// Finder looks for files and directories in an [afero.Fs] filesystem.
|
||||
type Finder struct {
|
||||
// Paths represents a list of locations that the [Finder] will search in.
|
||||
//
|
||||
// They are essentially the root directories or starting points for the search.
|
||||
//
|
||||
// Examples:
|
||||
// - home/user
|
||||
// - etc
|
||||
Paths []string
|
||||
|
||||
// Names are specific entries that the [Finder] will look for within the given Paths.
|
||||
//
|
||||
// It provides the capability to search for entries with depth,
|
||||
// meaning it can target deeper locations within the directory structure.
|
||||
//
|
||||
// It also supports glob syntax (as defined by [filepath.Match]), offering greater flexibility in search patterns.
|
||||
//
|
||||
// Examples:
|
||||
// - config.yaml
|
||||
// - home/*/config.yaml
|
||||
// - home/*/config.*
|
||||
Names []string
|
||||
|
||||
// Type restricts the kind of entries returned by the [Finder].
|
||||
//
|
||||
// This parameter helps in differentiating and filtering out files from directories or vice versa.
|
||||
Type FileType
|
||||
}
|
||||
|
||||
// Find looks for files and directories in an [afero.Fs] filesystem.
|
||||
func (f Finder) Find(fsys afero.Fs) ([]string, error) {
|
||||
q := queue.NewEager[[]searchResult]()
|
||||
|
||||
for _, searchPath := range f.Paths {
|
||||
for _, searchName := range f.Names {
|
||||
q.Add(func() ([]searchResult, error) {
|
||||
// If the name contains any glob character, perform a glob match
|
||||
if strings.ContainsAny(searchName, globMatch) {
|
||||
return globWalkSearch(fsys, searchPath, searchName, f.Type)
|
||||
}
|
||||
|
||||
return statSearch(fsys, searchPath, searchName, f.Type)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
searchResults, err := flatten(q.Wait())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Return early if no results were found
|
||||
if len(searchResults) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
results := make([]string, 0, len(searchResults))
|
||||
|
||||
for _, searchResult := range searchResults {
|
||||
results = append(results, searchResult.path)
|
||||
}
|
||||
|
||||
return results, nil
|
||||
}
|
||||
|
||||
type searchResult struct {
|
||||
path string
|
||||
info fs.FileInfo
|
||||
}
|
||||
|
||||
func flatten[T any](results [][]T, err error) ([]T, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var flattened []T
|
||||
|
||||
for _, r := range results {
|
||||
flattened = append(flattened, r...)
|
||||
}
|
||||
|
||||
return flattened, nil
|
||||
}
|
||||
|
||||
func globWalkSearch(
|
||||
fsys afero.Fs,
|
||||
searchPath string,
|
||||
searchName string,
|
||||
searchType FileType,
|
||||
) ([]searchResult, error) {
|
||||
var results []searchResult
|
||||
|
||||
err := afero.Walk(fsys, searchPath, func(p string, fileInfo fs.FileInfo, err error) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Skip the root path
|
||||
if p == searchPath {
|
||||
return nil
|
||||
}
|
||||
|
||||
var result error
|
||||
|
||||
// Stop reading subdirectories
|
||||
// TODO: add depth detection here
|
||||
if fileInfo.IsDir() && filepath.Dir(p) == searchPath {
|
||||
result = fs.SkipDir
|
||||
}
|
||||
|
||||
// Skip unmatching type
|
||||
if !searchType.match(fileInfo) {
|
||||
return result
|
||||
}
|
||||
|
||||
match, err := filepath.Match(searchName, fileInfo.Name())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if match {
|
||||
results = append(results, searchResult{p, fileInfo})
|
||||
}
|
||||
|
||||
return result
|
||||
})
|
||||
if err != nil {
|
||||
return results, err
|
||||
}
|
||||
|
||||
return results, nil
|
||||
}
|
||||
|
||||
func statSearch(
|
||||
fsys afero.Fs,
|
||||
searchPath string,
|
||||
searchName string,
|
||||
searchType FileType,
|
||||
) ([]searchResult, error) {
|
||||
filePath := filepath.Join(searchPath, searchName)
|
||||
|
||||
fileInfo, err := fsys.Stat(filePath)
|
||||
if errors.Is(err, fs.ErrNotExist) {
|
||||
return nil, nil
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Skip unmatching type
|
||||
if !searchType.match(fileInfo) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
return []searchResult{{filePath, fileInfo}}, nil
|
||||
}
|
||||
5
vendor/github.com/sagikazarmark/locafero/glob.go
generated
vendored
Normal file
5
vendor/github.com/sagikazarmark/locafero/glob.go
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
//go:build !windows
|
||||
|
||||
package locafero
|
||||
|
||||
const globMatch = "*?[]\\^"
|
||||
8
vendor/github.com/sagikazarmark/locafero/glob_windows.go
generated
vendored
Normal file
8
vendor/github.com/sagikazarmark/locafero/glob_windows.go
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
//go:build windows
|
||||
|
||||
package locafero
|
||||
|
||||
// See [filepath.Match]:
|
||||
//
|
||||
// On Windows, escaping is disabled. Instead, '\\' is treated as path separator.
|
||||
const globMatch = "*?[]^"
|
||||
41
vendor/github.com/sagikazarmark/locafero/helpers.go
generated
vendored
Normal file
41
vendor/github.com/sagikazarmark/locafero/helpers.go
generated
vendored
Normal file
@@ -0,0 +1,41 @@
|
||||
package locafero
|
||||
|
||||
import "fmt"
|
||||
|
||||
// NameWithExtensions creates a list of names from a base name and a list of extensions.
|
||||
//
|
||||
// TODO: find a better name for this function.
|
||||
func NameWithExtensions(baseName string, extensions ...string) []string {
|
||||
var names []string
|
||||
|
||||
if baseName == "" {
|
||||
return names
|
||||
}
|
||||
|
||||
for _, ext := range extensions {
|
||||
if ext == "" {
|
||||
continue
|
||||
}
|
||||
|
||||
names = append(names, fmt.Sprintf("%s.%s", baseName, ext))
|
||||
}
|
||||
|
||||
return names
|
||||
}
|
||||
|
||||
// NameWithOptionalExtensions creates a list of names from a base name and a list of extensions,
|
||||
// plus it adds the base name (without any extensions) to the end of the list.
|
||||
//
|
||||
// TODO: find a better name for this function.
|
||||
func NameWithOptionalExtensions(baseName string, extensions ...string) []string {
|
||||
var names []string
|
||||
|
||||
if baseName == "" {
|
||||
return names
|
||||
}
|
||||
|
||||
names = NameWithExtensions(baseName, extensions...)
|
||||
names = append(names, baseName)
|
||||
|
||||
return names
|
||||
}
|
||||
53
vendor/github.com/sagikazarmark/locafero/internal/queue/eager.go
generated
vendored
Normal file
53
vendor/github.com/sagikazarmark/locafero/internal/queue/eager.go
generated
vendored
Normal file
@@ -0,0 +1,53 @@
|
||||
package queue
|
||||
|
||||
import "sync"
|
||||
|
||||
// NewEager creates a new eager queue.
|
||||
func NewEager[T any]() Queue[T] {
|
||||
return &Eager[T]{}
|
||||
}
|
||||
|
||||
// Eager is a queue that processes items eagerly.
|
||||
type Eager[T any] struct {
|
||||
results []T
|
||||
error error
|
||||
|
||||
mu sync.Mutex
|
||||
}
|
||||
|
||||
// Add implements the [Queue] interface.
|
||||
func (p *Eager[T]) Add(fn func() (T, error)) {
|
||||
p.mu.Lock()
|
||||
defer p.mu.Unlock()
|
||||
|
||||
// Return early if there's an error
|
||||
if p.error != nil {
|
||||
return
|
||||
}
|
||||
|
||||
result, err := fn()
|
||||
if err != nil {
|
||||
p.error = err
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
p.results = append(p.results, result)
|
||||
}
|
||||
|
||||
// Wait implements the [Queue] interface.
|
||||
func (p *Eager[T]) Wait() ([]T, error) {
|
||||
p.mu.Lock()
|
||||
defer p.mu.Unlock()
|
||||
|
||||
if p.error != nil {
|
||||
return nil, p.error
|
||||
}
|
||||
|
||||
results := p.results
|
||||
|
||||
// Reset results for reuse
|
||||
p.results = nil
|
||||
|
||||
return results, nil
|
||||
}
|
||||
8
vendor/github.com/sagikazarmark/locafero/internal/queue/queue.go
generated
vendored
Normal file
8
vendor/github.com/sagikazarmark/locafero/internal/queue/queue.go
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
// Package queue provides a generic queue implementation.
|
||||
package queue
|
||||
|
||||
// Queue represents a generic queue.
|
||||
type Queue[T any] interface {
|
||||
Add(func() (T, error))
|
||||
Wait() ([]T, error)
|
||||
}
|
||||
14
vendor/github.com/sagikazarmark/locafero/justfile
generated
vendored
Normal file
14
vendor/github.com/sagikazarmark/locafero/justfile
generated
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
default:
|
||||
just --list
|
||||
|
||||
test:
|
||||
go test -count 10 -shuffle on -race -v ./...
|
||||
|
||||
fuzz:
|
||||
go test -race -v -fuzz=Fuzz -fuzztime=60s ./...
|
||||
|
||||
lint:
|
||||
golangci-lint run
|
||||
|
||||
fmt:
|
||||
golangci-lint fmt
|
||||
Reference in New Issue
Block a user