lib/fs: Fix root path handling for Windows (fixes #8778)
Co-authored-by: Jakob Borg <jakob@kastelo.net>
This commit is contained in:
committed by
Jakob Borg
co-authored by
Jakob Borg
parent
1103a27337
commit
3adfe2f91f
+7
-5
@@ -51,8 +51,10 @@ type BasicFilesystem struct {
|
||||
groupCache *groupCache
|
||||
}
|
||||
|
||||
type userCache = valueCache[string, *user.User]
|
||||
type groupCache = valueCache[string, *user.Group]
|
||||
type (
|
||||
userCache = valueCache[string, *user.User]
|
||||
groupCache = valueCache[string, *user.Group]
|
||||
)
|
||||
|
||||
func newBasicFilesystem(root string, opts ...Option) *BasicFilesystem {
|
||||
if root == "" {
|
||||
@@ -62,11 +64,11 @@ func newBasicFilesystem(root string, opts ...Option) *BasicFilesystem {
|
||||
// The reason it's done like this:
|
||||
// C: -> C:\ -> C:\ (issue that this is trying to fix)
|
||||
// C:\somedir -> C:\somedir\ -> C:\somedir
|
||||
// C:\somedir\ -> C:\somedir\\ -> C:\somedir
|
||||
// C:\somedir\ -> C:\somedir\ -> C:\somedir
|
||||
// This way in the tests, we get away without OS specific separators
|
||||
// in the test configs.
|
||||
sep := string(filepath.Separator)
|
||||
root = filepath.Dir(root + sep)
|
||||
root = filepath.Clean(filepath.Dir(root + sep))
|
||||
|
||||
// Attempt tilde expansion; leave unchanged in case of error
|
||||
if path, err := ExpandTilde(root); err == nil {
|
||||
@@ -215,7 +217,7 @@ func (f *BasicFilesystem) DirNames(name string) ([]string, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
fd, err := os.OpenFile(name, OptReadOnly, 0777)
|
||||
fd, err := os.OpenFile(name, OptReadOnly, 0o777)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user