Skip to content

Commit ac634da

Browse files
kerstencamilamacedo86
authored andcommitted
🌱 (chore): use octal notation for file and directory modes (kubernetes-sigs#4663)
chore: use octal notation for file and directory modes Replaced legacy octal literals (e.g., 0644, 0755) with Go 1.13+ `0o` syntax (e.g., 0o644, 0o755) across the codebase. This modernizes permission mode expressions, aligns with current Go style and guidelines.
1 parent bd928a0 commit ac634da

File tree

11 files changed

+18
-18
lines changed

11 files changed

+18
-18
lines changed

hack/docs/internal/cronjob-tutorial/generate_cronjob.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -656,7 +656,7 @@ func (sp *Sample) updateExample() {
656656

657657
func (sp *Sample) addControllerTest() {
658658
var fs = afero.NewOsFs()
659-
err := afero.WriteFile(fs, filepath.Join(sp.ctx.Dir, "internal/controller/cronjob_controller_test.go"), []byte(controllerTest), 0600)
659+
err := afero.WriteFile(fs, filepath.Join(sp.ctx.Dir, "internal/controller/cronjob_controller_test.go"), []byte(controllerTest), 0o600)
660660
hackutils.CheckError("adding cronjob_controller_test", err)
661661
}
662662

pkg/cli/alpha/internal/generate.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ func loadProjectConfig(inputDir string) (store.Store, error) {
133133

134134
// Helper function to create the output directory.
135135
func createDirectory(outputDir string) error {
136-
if err := os.MkdirAll(outputDir, 0755); err != nil {
136+
if err := os.MkdirAll(outputDir, 0o755); err != nil {
137137
return fmt.Errorf("failed to create output directory %s: %w", outputDir, err)
138138
}
139139
return nil
@@ -414,7 +414,7 @@ func copyFile(src, des string) error {
414414
if err != nil {
415415
return fmt.Errorf("source file path %s does not exist: %w", src, err)
416416
}
417-
return os.WriteFile(des, bytesRead, 0755)
417+
return os.WriteFile(des, bytesRead, 0o755)
418418
}
419419

420420
// Migrates Grafana configuration files.

pkg/cli/cmd_helpers.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ func updateProjectFileForAlphaGenerate() error {
366366

367367
// Only update the file if changes were made
368368
if updated {
369-
err = os.WriteFile(projectFilePath, []byte(projectStr), 0644)
369+
err = os.WriteFile(projectFilePath, []byte(projectStr), 0o644)
370370
if err != nil {
371371
return fmt.Errorf("failed to update PROJECT file: %w", err)
372372
}

pkg/cli/options.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -329,5 +329,5 @@ func DiscoverExternalPlugins(fs afero.Fs) (ps []plugin.Plugin, err error) {
329329

330330
// isPluginExectuable checks if a plugin is an executable based on the bitmask and returns true or false.
331331
func isPluginExectuable(mode fs.FileMode) bool {
332-
return mode&0111 != 0
332+
return mode&0o111 != 0
333333
}

pkg/cli/options_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ var _ = Describe("Discover external plugins", func() {
126126

127127
When("using the custom path", func() {
128128
BeforeEach(func() {
129-
err := os.MkdirAll(customPath, 0750)
129+
err := os.MkdirAll(customPath, 0o750)
130130
Expect(err).ToNot(HaveOccurred())
131131

132132
// store and set the EXTERNAL_PLUGINS_PATH

pkg/config/store/yaml/store.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ func (s yamlStore) SaveTo(path string) error {
144144
content = append([]byte(commentStr), content...)
145145

146146
// Write the marshalled configuration
147-
err = afero.WriteFile(s.fs, path, content, 0600)
147+
err = afero.WriteFile(s.fs, path, content, 0o600)
148148
if err != nil {
149149
return store.SaveError{Err: fmt.Errorf("failed to save configuration to %q: %w", path, err)}
150150
}

pkg/machinery/scaffold.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ import (
3535
const (
3636
createOrUpdate = os.O_WRONLY | os.O_CREATE | os.O_TRUNC
3737

38-
defaultDirectoryPermission os.FileMode = 0700
39-
defaultFilePermission os.FileMode = 0600
38+
defaultDirectoryPermission os.FileMode = 0o700
39+
defaultFilePermission os.FileMode = 0o600
4040
)
4141

4242
var options = imports.Options{

pkg/plugin/util/util.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ func InsertCode(filename, target, code string) error {
7575
}
7676
out := string(contents[:idx+len(target)]) + code + string(contents[idx+len(target):])
7777
//nolint:gosec // false positive
78-
return os.WriteFile(filename, []byte(out), 0644)
78+
return os.WriteFile(filename, []byte(out), 0o644)
7979
}
8080

8181
// InsertCodeIfNotExist insert code if it does not already exists
@@ -110,7 +110,7 @@ func AppendCodeIfNotExist(filename, code string) error {
110110

111111
// AppendCodeAtTheEnd appends the given code at the end of the file.
112112
func AppendCodeAtTheEnd(filename, code string) error {
113-
f, err := os.OpenFile(filename, os.O_APPEND|os.O_WRONLY, 0644)
113+
f, err := os.OpenFile(filename, os.O_APPEND|os.O_WRONLY, 0o644)
114114
if err != nil {
115115
return err
116116
}
@@ -168,7 +168,7 @@ func UncommentCode(filename, target, prefix string) error {
168168
return err
169169
}
170170
//nolint:gosec // false positive
171-
return os.WriteFile(filename, out.Bytes(), 0644)
171+
return os.WriteFile(filename, out.Bytes(), 0o644)
172172
}
173173

174174
// CommentCode searches for target in the file and adds the comment prefix
@@ -210,7 +210,7 @@ func CommentCode(filename, target, prefix string) error {
210210
}
211211

212212
// Write the modified content back to the file
213-
return os.WriteFile(filename, out.Bytes(), 0644)
213+
return os.WriteFile(filename, out.Bytes(), 0o644)
214214
}
215215

216216
// EnsureExistAndReplace check if the content exists and then do the replace

pkg/plugin/util/util_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ var _ = Describe("Cover plugin util helpers", func() {
3030
var content []byte
3131

3232
BeforeAll(func() {
33-
err := os.MkdirAll("testdata", 0755)
33+
err := os.MkdirAll("testdata", 0o755)
3434
Expect(err).NotTo(HaveOccurred())
3535

3636
if _, err := os.Stat(path); os.IsNotExist(err) {
37-
err = os.WriteFile(path, []byte("exampleTarget"), 0644)
37+
err = os.WriteFile(path, []byte("exampleTarget"), 0o644)
3838
Expect(err).NotTo(HaveOccurred())
3939
}
4040

@@ -43,7 +43,7 @@ var _ = Describe("Cover plugin util helpers", func() {
4343
})
4444

4545
AfterAll(func() {
46-
err := os.WriteFile(path, content, 0644)
46+
err := os.WriteFile(path, content, 0o644)
4747
Expect(err).NotTo(HaveOccurred())
4848

4949
err = os.RemoveAll("testdata")

pkg/plugins/golang/v4/scaffolds/edit.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ func (s *editScaffolder) Scaffold() error {
6666
// because there is nothing to replace.
6767
if str != "" {
6868
// TODO: instead of writing it directly, we should use the scaffolding machinery for consistency
69-
return afero.WriteFile(s.fs.FS, filename, []byte(str), 0644)
69+
return afero.WriteFile(s.fs.FS, filename, []byte(str), 0o644)
7070
}
7171

7272
return nil

test/e2e/utils/webhooks.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,5 +74,5 @@ func ImplementWebhooks(filename, lowerKind string) error {
7474
return err
7575
}
7676
//nolint:gosec // false positive
77-
return os.WriteFile(filename, []byte(str), 0644)
77+
return os.WriteFile(filename, []byte(str), 0o644)
7878
}

0 commit comments

Comments
 (0)