Skip to content

Commit 5f4346a

Browse files
fix(fs): use new OsFS instead of os.DirFS during execution (#1416)
DirFS("/") roots the filesystem. Relative paths are resolved relative to this root. Paths with a leading `/` are invalid. Introduced OsFS to use during normal CLI execution, which forwards to corresponding os package functions. While still allowing other FS implementations during testing.
1 parent 16e34c5 commit 5f4346a

2 files changed

Lines changed: 20 additions & 1 deletion

File tree

internal/pkg/utils/os_fs.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package utils
2+
3+
import (
4+
"io/fs"
5+
"os"
6+
)
7+
8+
var _ fs.ReadFileFS = OsFS{}
9+
10+
type OsFS struct{}
11+
12+
func (o OsFS) Open(name string) (fs.File, error) {
13+
return os.Open(name)
14+
}
15+
16+
func (o OsFS) ReadFile(name string) ([]byte, error) {
17+
return os.ReadFile(name)
18+
}

main.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"github.com/stackitcloud/stackit-cli/internal/pkg/config"
88
"github.com/stackitcloud/stackit-cli/internal/pkg/print"
99
"github.com/stackitcloud/stackit-cli/internal/pkg/types"
10+
"github.com/stackitcloud/stackit-cli/internal/pkg/utils"
1011
)
1112

1213
// These values are overwritten by GoReleaser at build time
@@ -28,7 +29,7 @@ func main() {
2829
Printer: printer,
2930
CliVersion: version,
3031
Date: date,
31-
Fs: os.DirFS("/"),
32+
Fs: utils.OsFS{},
3233
Args: os.Args[1:],
3334
}
3435
if !cmd.Execute(&params) {

0 commit comments

Comments
 (0)