Skip to content

Commit cbe9e11

Browse files
authored
Keep file mode the same as it is cleared (#1097)
## Summary 1. Get the filemode of the directory before everything inside is deleted and use that mode for re-creation 2. Reuse the `ClearDir` in gen-docs ## How was it tested?
1 parent c16bb1d commit cbe9e11

File tree

3 files changed

+13
-10
lines changed

3 files changed

+13
-10
lines changed

internal/boxcli/gen-docs.go

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import (
1010
"github.com/pkg/errors"
1111
"github.com/spf13/cobra"
1212
"github.com/spf13/cobra/doc"
13+
14+
"go.jetpack.io/devbox/internal/fileutil"
1315
)
1416

1517
func genDocsCmd() *cobra.Command {
@@ -30,15 +32,8 @@ func genDocsCmd() *cobra.Command {
3032
// We clear out the existing directory so that the doc-pages for
3133
// commands that have been deleted in the CLI will also be removed
3234
// after we re-generate the docs below
33-
err = os.RemoveAll(docsPath)
34-
if err != nil {
35-
return errors.WithStack(err)
36-
}
37-
38-
// Ensure the directory exists
39-
err = os.MkdirAll(docsPath, 0755)
40-
if err != nil {
41-
return errors.WithStack(err)
35+
if err := fileutil.ClearDir(docsPath); err != nil {
36+
return err
4237
}
4338

4439
rootCmd := cmd

internal/fileutil/dir.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"path/filepath"
99

1010
"github.com/pkg/errors"
11+
1112
"go.jetpack.io/devbox/internal/cmdutil"
1213
)
1314

@@ -26,8 +27,14 @@ func CopyAll(src, dst string) error {
2627
}
2728

2829
func ClearDir(dir string) error {
30+
f, err := os.Stat(dir)
31+
if err != nil {
32+
return errors.WithStack(err)
33+
}
34+
mode := f.Mode()
35+
2936
if err := os.RemoveAll(dir); err != nil {
3037
return errors.WithStack(err)
3138
}
32-
return errors.WithStack(os.MkdirAll(dir, 0755))
39+
return errors.WithStack(os.MkdirAll(dir, mode))
3340
}

internal/pullbox/pullbox.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"path/filepath"
99

1010
"github.com/pkg/errors"
11+
1112
"go.jetpack.io/devbox/internal/boxcli/usererr"
1213
"go.jetpack.io/devbox/internal/pullbox/git"
1314
)

0 commit comments

Comments
 (0)