Skip to content

Commit 47331e6

Browse files
committed
extract osfsWithChmod to its own package
Signed-off-by: Cian Johnston <[email protected]>
1 parent 2270f59 commit 47331e6

File tree

2 files changed

+23
-10
lines changed

2 files changed

+23
-10
lines changed

envbuilder.go

+2-10
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626

2727
"github.com/coder/envbuilder/constants"
2828
"github.com/coder/envbuilder/git"
29+
"github.com/coder/envbuilder/internal/chmodfs"
2930
"github.com/coder/envbuilder/options"
3031

3132
"github.com/GoogleContainerTools/kaniko/pkg/config"
@@ -41,7 +42,6 @@ import (
4142
_ "github.com/distribution/distribution/v3/registry/storage/driver/filesystem"
4243
"github.com/docker/cli/cli/config/configfile"
4344
"github.com/fatih/color"
44-
"github.com/go-git/go-billy/v5"
4545
"github.com/go-git/go-billy/v5/osfs"
4646
"github.com/go-git/go-git/v5/plumbing/transport"
4747
v1 "github.com/google/go-containerregistry/pkg/v1"
@@ -91,7 +91,7 @@ func Run(ctx context.Context, opts options.Options) error {
9191
}
9292
}
9393
if opts.Filesystem == nil {
94-
opts.Filesystem = &osfsWithChmod{osfs.New("/")}
94+
opts.Filesystem = chmodfs.New(osfs.New("/"))
9595
}
9696
if opts.WorkspaceFolder == "" {
9797
opts.WorkspaceFolder = options.DefaultWorkspaceFolder(opts.GitURL)
@@ -1053,14 +1053,6 @@ func newColor(value ...color.Attribute) *color.Color {
10531053
return c
10541054
}
10551055

1056-
type osfsWithChmod struct {
1057-
billy.Filesystem
1058-
}
1059-
1060-
func (fs *osfsWithChmod) Chmod(name string, mode os.FileMode) error {
1061-
return os.Chmod(name, mode)
1062-
}
1063-
10641056
func findDevcontainerJSON(options options.Options) (string, string, error) {
10651057
// 0. Check if custom devcontainer directory or path is provided.
10661058
if options.DevcontainerDir != "" || options.DevcontainerJSONPath != "" {

internal/chmodfs/chmodfs.go

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package chmodfs
2+
3+
import (
4+
"os"
5+
6+
"github.com/go-git/go-billy/v5"
7+
)
8+
9+
func New(fs billy.Filesystem) billy.Filesystem {
10+
return &osfsWithChmod{
11+
Filesystem: fs,
12+
}
13+
}
14+
15+
type osfsWithChmod struct {
16+
billy.Filesystem
17+
}
18+
19+
func (fs *osfsWithChmod) Chmod(name string, mode os.FileMode) error {
20+
return os.Chmod(name, mode)
21+
}

0 commit comments

Comments
 (0)