Skip to content

Commit 0949d0a

Browse files
committed
Change all file permissions to octal format
This better represent permissions as Linux handles such information in octal format, meaning that the left-most 0 has an important meaning and is not to be ignored as normally integers would. See #603 Signed-off-by: Peter Gundel <mail@petergundel.de>
1 parent fe17137 commit 0949d0a

File tree

11 files changed

+37
-37
lines changed

11 files changed

+37
-37
lines changed

controllers/helmchart_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,7 @@ func (r *HelmChartReconciler) buildFromTarballArtifact(ctx context.Context, obj
580580

581581
// Create directory to untar source into
582582
sourceDir := filepath.Join(tmpDir, "source")
583-
if err := os.Mkdir(sourceDir, 0700); err != nil {
583+
if err := os.Mkdir(sourceDir, 0o700); err != nil {
584584
e := &serror.Event{
585585
Err: fmt.Errorf("failed to create directory to untar source into: %w", err),
586586
Reason: sourcev1.DirCreationFailedReason,

controllers/storage.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ func (s Storage) SetHostname(URL string) string {
112112
// MkdirAll calls os.MkdirAll for the given v1beta1.Artifact base dir.
113113
func (s *Storage) MkdirAll(artifact sourcev1.Artifact) error {
114114
dir := filepath.Dir(s.LocalPath(artifact))
115-
return os.MkdirAll(dir, 0777)
115+
return os.MkdirAll(dir, 0o777)
116116
}
117117

118118
// RemoveAll calls os.RemoveAll for the given v1beta1.Artifact base dir.
@@ -432,7 +432,7 @@ func (s *Storage) Archive(artifact *sourcev1.Artifact, dir string, filter Archiv
432432
return err
433433
}
434434

435-
if err := os.Chmod(tmpName, 0644); err != nil {
435+
if err := os.Chmod(tmpName, 0o644); err != nil {
436436
return err
437437
}
438438

controllers/storage_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ func TestStorage_Archive(t *testing.T) {
136136
}
137137
for name, b := range files {
138138
absPath := filepath.Join(dir, name)
139-
if err = os.MkdirAll(filepath.Dir(absPath), 0755); err != nil {
139+
if err = os.MkdirAll(filepath.Dir(absPath), 0o755); err != nil {
140140
return
141141
}
142142
f, err := os.Create(absPath)
@@ -316,7 +316,7 @@ func TestStorageRemoveAllButCurrent(t *testing.T) {
316316

317317
// Create artifact dir and artifacts.
318318
artifactDir := path.Join(dir, "foo", "bar")
319-
g.Expect(os.MkdirAll(artifactDir, 0755)).NotTo(HaveOccurred())
319+
g.Expect(os.MkdirAll(artifactDir, 0o755)).NotTo(HaveOccurred())
320320
current := []string{
321321
path.Join(artifactDir, "artifact1.tar.gz"),
322322
}
@@ -378,7 +378,7 @@ func TestStorageRemoveAll(t *testing.T) {
378378
}
379379

380380
if tt.createArtifactPath {
381-
g.Expect(os.MkdirAll(path.Join(dir, tt.artifactPath), 0755)).ToNot(HaveOccurred())
381+
g.Expect(os.MkdirAll(path.Join(dir, tt.artifactPath), 0o755)).ToNot(HaveOccurred())
382382
}
383383

384384
deleted, err := s.RemoveAll(artifact)
@@ -412,7 +412,7 @@ func TestStorageCopyFromPath(t *testing.T) {
412412
}
413413
t.Cleanup(cleanupStoragePath(dir))
414414
absPath = filepath.Join(dir, file.Name)
415-
if err = os.MkdirAll(filepath.Dir(absPath), 0755); err != nil {
415+
if err = os.MkdirAll(filepath.Dir(absPath), 0o755); err != nil {
416416
return
417417
}
418418
f, err := os.Create(absPath)

internal/fs/fs_test.go

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@ func TestRenameWithFallback(t *testing.T) {
4242
}
4343

4444
srcpath = filepath.Join(dir, "a")
45-
if err = os.MkdirAll(srcpath, 0777); err != nil {
45+
if err = os.MkdirAll(srcpath, 0o777); err != nil {
4646
t.Fatal(err)
4747
}
4848

4949
dstpath := filepath.Join(dir, "b")
50-
if err = os.MkdirAll(dstpath, 0777); err != nil {
50+
if err = os.MkdirAll(dstpath, 0o777); err != nil {
5151
t.Fatal(err)
5252
}
5353

@@ -64,7 +64,7 @@ func TestCopyDir(t *testing.T) {
6464
defer os.RemoveAll(dir)
6565

6666
srcdir := filepath.Join(dir, "src")
67-
if err := os.MkdirAll(srcdir, 0755); err != nil {
67+
if err := os.MkdirAll(srcdir, 0o755); err != nil {
6868
t.Fatal(err)
6969
}
7070

@@ -81,7 +81,7 @@ func TestCopyDir(t *testing.T) {
8181
for i, file := range files {
8282
fn := filepath.Join(srcdir, file.path)
8383
dn := filepath.Dir(fn)
84-
if err = os.MkdirAll(dn, 0755); err != nil {
84+
if err = os.MkdirAll(dn, 0o755); err != nil {
8585
t.Fatal(err)
8686
}
8787

@@ -151,7 +151,7 @@ func TestCopyDirFail_SrcInaccessible(t *testing.T) {
151151

152152
cleanup := setupInaccessibleDir(t, func(dir string) error {
153153
srcdir = filepath.Join(dir, "src")
154-
return os.MkdirAll(srcdir, 0755)
154+
return os.MkdirAll(srcdir, 0o755)
155155
})
156156
defer cleanup()
157157

@@ -184,7 +184,7 @@ func TestCopyDirFail_DstInaccessible(t *testing.T) {
184184
defer os.RemoveAll(dir)
185185

186186
srcdir = filepath.Join(dir, "src")
187-
if err = os.MkdirAll(srcdir, 0755); err != nil {
187+
if err = os.MkdirAll(srcdir, 0o755); err != nil {
188188
t.Fatal(err)
189189
}
190190

@@ -235,12 +235,12 @@ func TestCopyDirFail_DstExists(t *testing.T) {
235235
defer os.RemoveAll(dir)
236236

237237
srcdir = filepath.Join(dir, "src")
238-
if err = os.MkdirAll(srcdir, 0755); err != nil {
238+
if err = os.MkdirAll(srcdir, 0o755); err != nil {
239239
t.Fatal(err)
240240
}
241241

242242
dstdir = filepath.Join(dir, "dst")
243-
if err = os.MkdirAll(dstdir, 0755); err != nil {
243+
if err = os.MkdirAll(dstdir, 0o755); err != nil {
244244
t.Fatal(err)
245245
}
246246

@@ -256,7 +256,7 @@ func TestCopyDirFail_DstExists(t *testing.T) {
256256
func TestCopyDirFailOpen(t *testing.T) {
257257
if runtime.GOOS == "windows" {
258258
// XXX: setting permissions works differently in
259-
// Microsoft Windows. os.Chmod(..., 0222) below is not
259+
// Microsoft Windows. os.Chmod(..., 0o222) below is not
260260
// enough for the file to be readonly, and os.Chmod(...,
261261
// 0000) returns an invalid argument error. Skipping
262262
// this this until a compatible implementation is
@@ -273,7 +273,7 @@ func TestCopyDirFailOpen(t *testing.T) {
273273
defer os.RemoveAll(dir)
274274

275275
srcdir = filepath.Join(dir, "src")
276-
if err = os.MkdirAll(srcdir, 0755); err != nil {
276+
if err = os.MkdirAll(srcdir, 0o755); err != nil {
277277
t.Fatal(err)
278278
}
279279

@@ -285,7 +285,7 @@ func TestCopyDirFailOpen(t *testing.T) {
285285
srcf.Close()
286286

287287
// setup source file so that it cannot be read
288-
if err = os.Chmod(srcfn, 0222); err != nil {
288+
if err = os.Chmod(srcfn, 0o222); err != nil {
289289
t.Fatal(err)
290290
}
291291

@@ -419,11 +419,11 @@ func TestCopyFileLongFilePath(t *testing.T) {
419419
}
420420

421421
fullPath := filepath.Join(dir, dirName, string(os.PathSeparator))
422-
if err := os.MkdirAll(fullPath, 0755); err != nil && !os.IsExist(err) {
422+
if err := os.MkdirAll(fullPath, 0o755); err != nil && !os.IsExist(err) {
423423
t.Fatalf("%+v", fmt.Errorf("unable to create temp directory: %s", fullPath))
424424
}
425425

426-
err = os.WriteFile(fullPath+"src", []byte(nil), 0644)
426+
err = os.WriteFile(fullPath+"src", []byte(nil), 0o644)
427427
if err != nil {
428428
t.Fatalf("%+v", err)
429429
}
@@ -460,7 +460,7 @@ func TestCopyFileFail(t *testing.T) {
460460

461461
cleanup := setupInaccessibleDir(t, func(dir string) error {
462462
dstdir = filepath.Join(dir, "dir")
463-
return os.Mkdir(dstdir, 0777)
463+
return os.Mkdir(dstdir, 0o777)
464464
})
465465
defer cleanup()
466466

@@ -493,15 +493,15 @@ func setupInaccessibleDir(t *testing.T, op func(dir string) error) func() {
493493
subdir := filepath.Join(dir, "dir")
494494

495495
cleanup := func() {
496-
if err := os.Chmod(subdir, 0777); err != nil {
496+
if err := os.Chmod(subdir, 0o777); err != nil {
497497
t.Error(err)
498498
}
499499
if err := os.RemoveAll(dir); err != nil {
500500
t.Error(err)
501501
}
502502
}
503503

504-
if err := os.Mkdir(subdir, 0777); err != nil {
504+
if err := os.Mkdir(subdir, 0o777); err != nil {
505505
cleanup()
506506
t.Fatal(err)
507507
return nil
@@ -513,7 +513,7 @@ func setupInaccessibleDir(t *testing.T, op func(dir string) error) func() {
513513
return nil
514514
}
515515

516-
if err := os.Chmod(subdir, 0666); err != nil {
516+
if err := os.Chmod(subdir, 0o666); err != nil {
517517
cleanup()
518518
t.Fatal(err)
519519
return nil
@@ -532,7 +532,7 @@ func TestIsDir(t *testing.T) {
532532

533533
cleanup := setupInaccessibleDir(t, func(dir string) error {
534534
dn = filepath.Join(dir, "dir")
535-
return os.Mkdir(dn, 0777)
535+
return os.Mkdir(dn, 0o777)
536536
})
537537
defer cleanup()
538538

@@ -575,7 +575,7 @@ func TestIsSymlink(t *testing.T) {
575575
defer os.RemoveAll(dir)
576576

577577
dirPath := filepath.Join(dir, "directory")
578-
if err = os.MkdirAll(dirPath, 0777); err != nil {
578+
if err = os.MkdirAll(dirPath, 0o777); err != nil {
579579
t.Fatal(err)
580580
}
581581

internal/helm/chart/builder_local_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ fullnameOverride: "full-foo-name-override"`),
201201
// Write value file in the base dir.
202202
for _, f := range tt.valuesFiles {
203203
vPath := filepath.Join(localRef.WorkDir, f.Name)
204-
g.Expect(os.WriteFile(vPath, f.Data, 0644)).ToNot(HaveOccurred())
204+
g.Expect(os.WriteFile(vPath, f.Data, 0o644)).ToNot(HaveOccurred())
205205
}
206206

207207
// Write chart dependencies in the base dir.
@@ -336,7 +336,7 @@ func Test_mergeFileValues(t *testing.T) {
336336
defer os.RemoveAll(baseDir)
337337

338338
for _, f := range tt.files {
339-
g.Expect(os.WriteFile(filepath.Join(baseDir, f.Name), f.Data, 0644)).To(Succeed())
339+
g.Expect(os.WriteFile(filepath.Join(baseDir, f.Name), f.Data, 0o644)).To(Succeed())
340340
}
341341

342342
got, err := mergeFileValues(baseDir, tt.paths)

internal/helm/chart/metadata_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ func TestLoadChartMetadataFromDir(t *testing.T) {
140140
copy.Copy("../testdata/charts/helmchart", tmpDir)
141141
bigRequirementsFile := filepath.Join(tmpDir, "requirements.yaml")
142142
data := make([]byte, helm.MaxChartFileSize+10)
143-
g.Expect(os.WriteFile(bigRequirementsFile, data, 0644)).ToNot(HaveOccurred())
143+
g.Expect(os.WriteFile(bigRequirementsFile, data, 0o644)).ToNot(HaveOccurred())
144144

145145
tests := []struct {
146146
name string
@@ -205,7 +205,7 @@ func TestLoadChartMetadataFromArchive(t *testing.T) {
205205
defer os.RemoveAll(tmpDir)
206206
bigArchiveFile := filepath.Join(tmpDir, "chart.tgz")
207207
data := make([]byte, helm.MaxChartSize+10)
208-
g.Expect(os.WriteFile(bigArchiveFile, data, 0644)).ToNot(HaveOccurred())
208+
g.Expect(os.WriteFile(bigArchiveFile, data, 0o644)).ToNot(HaveOccurred())
209209

210210
tests := []struct {
211211
name string

internal/helm/repository/chart_repository_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ func TestChartRepository_LoadIndexFromFile(t *testing.T) {
363363
defer os.RemoveAll(tmpDir)
364364
bigIndexFile := filepath.Join(tmpDir, "index.yaml")
365365
data := make([]byte, helm.MaxIndexSize+10)
366-
g.Expect(os.WriteFile(bigIndexFile, data, 0644)).ToNot(HaveOccurred())
366+
g.Expect(os.WriteFile(bigIndexFile, data, 0o644)).ToNot(HaveOccurred())
367367

368368
tests := []struct {
369369
name string

main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ func mustInitStorage(path string, storageAdvAddr string, artifactRetentionTTL ti
299299
if path == "" {
300300
p, _ := os.Getwd()
301301
path = filepath.Join(p, "bin")
302-
os.MkdirAll(path, 0777)
302+
os.MkdirAll(path, 0o777)
303303
}
304304

305305
storage, err := controllers.NewStorage(path, storageAdvAddr, artifactRetentionTTL, artifactRetentionRecords)

pkg/gcp/gcp.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ func (c *GCSClient) FGetObject(ctx context.Context, bucketName, objectName, loca
118118
objectDir, _ := filepath.Split(localPath)
119119
if objectDir != "" {
120120
// Create any missing top level directories.
121-
if err := os.MkdirAll(objectDir, 0700); err != nil {
121+
if err := os.MkdirAll(objectDir, 0o700); err != nil {
122122
return "", err
123123
}
124124
}
@@ -130,7 +130,7 @@ func (c *GCSClient) FGetObject(ctx context.Context, bucketName, objectName, loca
130130
}
131131

132132
// Prepare target file.
133-
objectFile, err := os.OpenFile(localPath, os.O_CREATE|os.O_WRONLY, 0600)
133+
objectFile, err := os.OpenFile(localPath, os.O_CREATE|os.O_WRONLY, 0o600)
134134
if err != nil {
135135
return "", err
136136
}

pkg/sourceignore/sourceignore_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,10 +209,10 @@ func TestLoadExcludePatterns(t *testing.T) {
209209
"a/b/.sourceignore": "subdir.txt",
210210
}
211211
for n, c := range files {
212-
if err = os.MkdirAll(filepath.Join(tmpDir, filepath.Dir(n)), 0755); err != nil {
212+
if err = os.MkdirAll(filepath.Join(tmpDir, filepath.Dir(n)), 0o755); err != nil {
213213
t.Fatal(err)
214214
}
215-
if err = os.WriteFile(filepath.Join(tmpDir, n), []byte(c), 0644); err != nil {
215+
if err = os.WriteFile(filepath.Join(tmpDir, n), []byte(c), 0o644); err != nil {
216216
t.Fatal(err)
217217
}
218218
}

0 commit comments

Comments
 (0)