-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
merge #37 into cyphar/filepath-securejoin:main
Aleksa Sarai (6): gha: use stable/oldstable go versions gha: compile-test for all supported Go versions gha: test older Go versions in CI deps: downgrade golang.org/x/sys requirement go: lower Go requirement to Go 1.18 tests: don't call testing.Testing() in mocks LGTMs: cyphar
- Loading branch information
Showing
15 changed files
with
362 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,27 @@ and this project adheres to [Semantic Versioning](http://semver.org/). | |
|
||
## [Unreleased] ## | ||
|
||
### Compatibility ### | ||
- The minimum Go version requirement for `filepath-securejoin` is now Go 1.18 | ||
(we use generics internally). | ||
|
||
For reference, `[email protected]` somewhat-arbitrarily bumped the | ||
Go version requirement to 1.21. | ||
|
||
While we did make some use of Go 1.21 stdlib features (and in principle Go | ||
versions <= 1.21 are no longer even supported by upstream anymore), some | ||
downstreams have complained that the version bump has meant that they have to | ||
do workarounds when backporting fixes that use the new `filepath-securejoin` | ||
API onto old branches. This is not an ideal situation, but since using this | ||
library is probably better for most downstreams than a hand-rolled | ||
workaround, we now have compatibility shims that allow us to build on older | ||
Go versions. | ||
- Lower minimum version requirement for `golang.org/x/sys` to `v0.18.0` (we | ||
need the wrappers for `fsconfig(2)`), which should also make backporting | ||
patches to older branches easier. | ||
|
||
## [0.3.5] - 2024-12-06 ## | ||
|
||
### Fixed ### | ||
- `MkdirAll` will now no longer return an `EEXIST` error if two racing | ||
processes are creating the same directory. We will still verify that the path | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
//go:build linux && go1.20 | ||
|
||
// Copyright (C) 2024 SUSE LLC. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package securejoin | ||
|
||
import ( | ||
"fmt" | ||
) | ||
|
||
// wrapBaseError is a helper that is equivalent to fmt.Errorf("%w: %w"), except | ||
// that on pre-1.20 Go versions only errors.Is() works properly (errors.Unwrap) | ||
// is only guaranteed to give you baseErr. | ||
func wrapBaseError(baseErr, extraErr error) error { | ||
return fmt.Errorf("%w: %w", extraErr, baseErr) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
//go:build linux | ||
|
||
// Copyright (C) 2024 SUSE LLC. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package securejoin | ||
|
||
import ( | ||
"errors" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestGoCompatErrorWrap(t *testing.T) { | ||
baseErr := errors.New("base error") | ||
extraErr := errors.New("extra error") | ||
|
||
err := wrapBaseError(baseErr, extraErr) | ||
|
||
require.Error(t, err) | ||
assert.ErrorIs(t, err, baseErr, "wrapped error should contain base error") | ||
assert.ErrorIs(t, err, extraErr, "wrapped error should contain extra error") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
//go:build linux && !go1.20 | ||
|
||
// Copyright (C) 2024 SUSE LLC. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package securejoin | ||
|
||
import ( | ||
"fmt" | ||
) | ||
|
||
type wrappedError struct { | ||
inner error | ||
isError error | ||
} | ||
|
||
func (err wrappedError) Is(target error) bool { | ||
return err.isError == target | ||
} | ||
|
||
func (err wrappedError) Unwrap() error { | ||
return err.inner | ||
} | ||
|
||
func (err wrappedError) Error() string { | ||
return fmt.Sprintf("%v: %v", err.isError, err.inner) | ||
} | ||
|
||
// wrapBaseError is a helper that is equivalent to fmt.Errorf("%w: %w"), except | ||
// that on pre-1.20 Go versions only errors.Is() works properly (errors.Unwrap) | ||
// is only guaranteed to give you baseErr. | ||
func wrapBaseError(baseErr, extraErr error) error { | ||
return wrappedError{ | ||
inner: baseErr, | ||
isError: extraErr, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
//go:build linux && go1.21 | ||
|
||
// Copyright (C) 2024 SUSE LLC. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package securejoin | ||
|
||
import ( | ||
"slices" | ||
"sync" | ||
) | ||
|
||
func slices_DeleteFunc[S ~[]E, E any](slice S, delFn func(E) bool) S { | ||
return slices.DeleteFunc(slice, delFn) | ||
} | ||
|
||
func slices_Contains[S ~[]E, E comparable](slice S, val E) bool { | ||
return slices.Contains(slice, val) | ||
} | ||
|
||
func slices_Clone[S ~[]E, E any](slice S) S { | ||
return slices.Clone(slice) | ||
} | ||
|
||
func sync_OnceValue[T any](f func() T) func() T { | ||
return sync.OnceValue(f) | ||
} | ||
|
||
func sync_OnceValues[T1, T2 any](f func() (T1, T2)) func() (T1, T2) { | ||
return sync.OnceValues(f) | ||
} |
Oops, something went wrong.