Skip to content

Commit 3ff1512

Browse files
author
fullsend-code
committed
style(#3160): use explicit 0o octal notation for file permissions
Replace all old-style Go octal literals (e.g., 0644, 0755) with the explicit 0o prefix notation (0o644, 0o755) introduced in Go 1.13. The 0o prefix makes the numeric base unambiguous and prevents visual confusion with decimal numbers. This is a semantics-preserving change across 42 files covering production code, test files, acceptance tests, and benchmarks. All os.OpenFile, os.WriteFile, os.MkdirAll, os.Chmod, os.Mkdir, afero.WriteFile, and tar.Header Mode calls are updated. Note: TestWriteReport in internal/validate failed due to sandbox network restrictions (sigstore TUF CDN blocked), not related to this change. Closes #3160
1 parent d5a1551 commit 3ff1512

42 files changed

Lines changed: 145 additions & 145 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

acceptance/git/git.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -92,15 +92,15 @@ func startStubGitServer(ctx context.Context) (context.Context, error) {
9292
}
9393

9494
nginxConfDir := path.Join(repositories, "conf")
95-
if err = os.Mkdir(nginxConfDir, 0755); err != nil {
95+
if err = os.Mkdir(nginxConfDir, 0o755); err != nil {
9696
return ctx, err
9797
}
98-
if err = os.WriteFile(path.Join(nginxConfDir, "nginx.conf"), nginxConf, 0400); err != nil {
98+
if err = os.WriteFile(path.Join(nginxConfDir, "nginx.conf"), nginxConf, 0o400); err != nil {
9999
return ctx, err
100100
}
101101

102102
tlsDir := path.Join(repositories, "tls")
103-
if err = os.Mkdir(tlsDir, 0755); err != nil {
103+
if err = os.Mkdir(tlsDir, 0o755); err != nil {
104104
return ctx, err
105105
}
106106

@@ -114,7 +114,7 @@ func startStubGitServer(ctx context.Context) (context.Context, error) {
114114
Bytes: keyBytes,
115115
})
116116

117-
if err = os.WriteFile(path.Join(tlsDir, "server.key"), keyPem, 0400); err != nil {
117+
if err = os.WriteFile(path.Join(tlsDir, "server.key"), keyPem, 0o400); err != nil {
118118
return ctx, err
119119
}
120120

@@ -142,7 +142,7 @@ func startStubGitServer(ctx context.Context) (context.Context, error) {
142142
Bytes: cert,
143143
})
144144

145-
if err = os.WriteFile(certificate, certPEM, 0400); err != nil {
145+
if err = os.WriteFile(certificate, certPEM, 0o400); err != nil {
146146
return ctx, err
147147
}
148148

@@ -152,7 +152,7 @@ func startStubGitServer(ctx context.Context) (context.Context, error) {
152152

153153
// Create a minimal health check repository before starting the container
154154
healthCheckDir := path.Join(repositories, "health-check.git")
155-
if err := os.MkdirAll(healthCheckDir, 0755); err != nil {
155+
if err := os.MkdirAll(healthCheckDir, 0o755); err != nil {
156156
return ctx, err
157157
}
158158

@@ -284,7 +284,7 @@ func createGitRepository(ctx context.Context, repositoryName string, files *godo
284284
}))
285285
}
286286

287-
err = os.WriteFile(dest, b, 0600)
287+
err = os.WriteFile(dest, b, 0o600)
288288
if err != nil {
289289
return err
290290
}

acceptance/image/image.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -878,7 +878,7 @@ func createAndPushImageWithLayer(ctx context.Context, imageName string, files *g
878878
name := r.Cells[0].Value
879879
if err := t.WriteHeader(&tar.Header{
880880
Name: name,
881-
Mode: 0644,
881+
Mode: 0o644,
882882
Size: int64(len(content)),
883883
}); err != nil {
884884
return nil, err

acceptance/kubernetes/kind/image.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ func (k *kindCluster) buildCliImage(ctx context.Context) error {
6868
// Build into a directory not excluded by .dockerignore (which excludes
6969
// dist/) and not conflicting with the versioned binary from make build.
7070
buildDir := ".acceptance-build"
71-
if err := os.MkdirAll(buildDir, 0755); err != nil {
71+
if err := os.MkdirAll(buildDir, 0o755); err != nil {
7272
return fmt.Errorf("creating build directory: %w", err)
7373
}
7474
defer os.RemoveAll(buildDir)
@@ -140,7 +140,7 @@ func (k *kindCluster) buildCliImage(ctx context.Context) error {
140140

141141
// Write cache hash only after a successful build
142142
if cacheFile != "" {
143-
_ = os.WriteFile(cacheFile, []byte(currentHash), 0644) // #nosec G306
143+
_ = os.WriteFile(cacheFile, []byte(currentHash), 0o644) // #nosec G306
144144
}
145145

146146
return nil
@@ -323,7 +323,7 @@ func (k *kindCluster) BuildSnapshotArtifact(ctx context.Context, content string)
323323
filePath := "snapshotartifact"
324324

325325
// #nosec G306 -- reduce-snapshot.sh needs these permissions
326-
if err := os.WriteFile(filePath, []byte(content), 0644); err != nil {
326+
if err := os.WriteFile(filePath, []byte(content), 0o644); err != nil {
327327
return ctx, fmt.Errorf("failed to write JSON to file: %w", err)
328328
}
329329

@@ -408,7 +408,7 @@ func copyFile(src, dst string) error {
408408
}
409409
defer in.Close()
410410

411-
out, err := os.OpenFile(dst, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0755) // #nosec G302
411+
out, err := os.OpenFile(dst, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0o755) // #nosec G302
412412
if err != nil {
413413
return err
414414
}

acceptance/pipeline/pipeline_definition.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import (
2424
)
2525

2626
func writePipelineDefinition(ctx context.Context, name string, data string) (context.Context, error) {
27-
err := os.WriteFile(name, []byte(data), 0600)
27+
err := os.WriteFile(name, []byte(data), 0o600)
2828
if err != nil {
2929
return ctx, err
3030
}

acceptance/registry/registry.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ func startStubRegistry(ctx context.Context) (context.Context, error) {
101101
{
102102
HostFilePath: "",
103103
ContainerFilePath: "/config/config.json",
104-
FileMode: 0644,
104+
FileMode: 0o644,
105105
Reader: strings.NewReader(zotConfig),
106106
},
107107
},

acceptance/tekton/bundles.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func createTektonBundle(ctx context.Context, name string, data *godog.Table) (co
4949
writer := tar.NewWriter(&data)
5050
if err := writer.WriteHeader(&tar.Header{
5151
Name: name,
52-
Mode: 0600,
52+
Mode: 0o600,
5353
Size: int64(len(content)),
5454
Typeflag: tar.TypeReg,
5555
}); err != nil {

acceptance/testenv/testenv.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ func Persist(ctx context.Context) (bool, error) {
7777
return true, fmt.Errorf("unable to store JSON data in .persisted file: %v", err.Error())
7878
}
7979

80-
err = persister(persistedFile, b, 0644)
80+
err = persister(persistedFile, b, 0o644)
8181
if err != nil {
8282
return true, fmt.Errorf("unable to write to %s file: %v", persistedFile, err.Error())
8383
}

benchmark/internal/registry/registry.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,20 +100,20 @@ func Launch(data string) (suite.Closer, error) {
100100
return nil, err
101101
}
102102

103-
if err := os.Chmod(dir, 0755); err != nil {
103+
if err := os.Chmod(dir, 0o755); err != nil {
104104
return closer.Close, err
105105
}
106106

107107
certPath := path.Join(dir, "fake_quay.cer")
108-
if err := os.WriteFile(certPath, certificate, 0600); err != nil {
108+
if err := os.WriteFile(certPath, certificate, 0o600); err != nil {
109109
return closer.Close, err
110110
}
111111

112112
if err := os.Setenv("SSL_CERT_FILE", certPath); err != nil {
113113
return closer.Close, err
114114
}
115115

116-
if err := os.WriteFile(path.Join(dir, "fake_quay.key"), key, 0600); err != nil {
116+
if err := os.WriteFile(path.Join(dir, "fake_quay.key"), key, 0o600); err != nil {
117117
return closer.Close, err
118118
}
119119

benchmark/offliner/offliner.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ func main() {
6363
}
6464

6565
if _, err := os.Stat(dir); os.IsNotExist(err) {
66-
if err := os.MkdirAll(dir, 0755); err != nil {
66+
if err := os.MkdirAll(dir, 0o755); err != nil {
6767
fmt.Fprintln(os.Stderr, err)
6868
os.Exit(3)
6969
}

cmd/initialize/init_policies.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ func initPoliciesCmd() *cobra.Command {
7979
}
8080
fs := utils.FS(ctx)
8181
workDir := destDir
82-
err := fs.MkdirAll(workDir, 0755)
82+
err := fs.MkdirAll(workDir, 0o755)
8383
if err != nil {
8484
log.Debug("Failed to create policy directory!")
8585
return err

0 commit comments

Comments
 (0)