Skip to content

Commit fb8f64d

Browse files
refactor: change created files permission
1 parent 93219d2 commit fb8f64d

File tree

5 files changed

+19
-18
lines changed

5 files changed

+19
-18
lines changed

cmd/init.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -351,13 +351,13 @@ func extractPMDConfiguration(toolConfigurations []CodacyToolConfiguration) *Coda
351351
func createPMDConfigFile(config CodacyToolConfiguration, toolsConfigDir string) error {
352352
pmdDomainConfiguration := convertAPIToolConfigurationToDomain(config)
353353
pmdConfigurationString := tools.CreatePmdConfig(pmdDomainConfiguration)
354-
return os.WriteFile(filepath.Join(toolsConfigDir, "pmd-ruleset.xml"), []byte(pmdConfigurationString), utils.DefaultRW)
354+
return os.WriteFile(filepath.Join(toolsConfigDir, "pmd-ruleset.xml"), []byte(pmdConfigurationString), utils.DefaultFilePerms)
355355
}
356356

357357
func createDefaultPMDConfigFile(toolsConfigDir string) error {
358358
emptyConfig := tools.ToolConfiguration{}
359359
content := tools.CreatePmdConfig(emptyConfig)
360-
return os.WriteFile(filepath.Join(toolsConfigDir, "pmd-ruleset.xml"), []byte(content), utils.DefaultRW)
360+
return os.WriteFile(filepath.Join(toolsConfigDir, "pmd-ruleset.xml"), []byte(content), utils.DefaultFilePerms)
361361
}
362362

363363
type CodacyToolConfiguration struct {
@@ -385,7 +385,7 @@ func createTrivyConfigFile(config CodacyToolConfiguration, toolsConfigDir string
385385
trivyConfigurationString := tools.CreateTrivyConfig(trivyDomainConfiguration)
386386

387387
// Write to file
388-
return os.WriteFile(filepath.Join(toolsConfigDir, "trivy.yaml"), []byte(trivyConfigurationString), utils.DefaultRW)
388+
return os.WriteFile(filepath.Join(toolsConfigDir, "trivy.yaml"), []byte(trivyConfigurationString), utils.DefaultFilePerms)
389389
}
390390

391391
// convertAPIToolConfigurationForTrivy converts API tool configuration to domain model for Trivy
@@ -435,7 +435,7 @@ func createDefaultTrivyConfigFile(toolsConfigDir string) error {
435435
content := tools.CreateTrivyConfig(emptyConfig)
436436

437437
// Write to file
438-
return os.WriteFile(filepath.Join(toolsConfigDir, "trivy.yaml"), []byte(content), utils.DefaultRW)
438+
return os.WriteFile(filepath.Join(toolsConfigDir, "trivy.yaml"), []byte(content), utils.DefaultFilePerms)
439439
}
440440

441441
// createDefaultEslintConfigFile creates a default eslint.config.mjs configuration file
@@ -445,5 +445,5 @@ func createDefaultEslintConfigFile(toolsConfigDir string) error {
445445
content := tools.CreateEslintConfig(emptyConfig)
446446

447447
// Write to file
448-
return os.WriteFile(filepath.Join(toolsConfigDir, "eslint.config.mjs"), []byte(content), utils.DefaultRW)
448+
return os.WriteFile(filepath.Join(toolsConfigDir, "eslint.config.mjs"), []byte(content), utils.DefaultFilePerms)
449449
}

config/config.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"path/filepath"
88

99
"codacy/cli-v2/plugins"
10+
"codacy/cli-v2/utils"
1011
)
1112

1213
type ConfigType struct {
@@ -109,22 +110,22 @@ func (c *ConfigType) setupCodacyPaths() {
109110
}
110111

111112
func (c *ConfigType) CreateCodacyDirs() error {
112-
if err := os.MkdirAll(c.globalCacheDirectory, 0777); err != nil {
113+
if err := os.MkdirAll(c.globalCacheDirectory, utils.DefaultDirPerms); err != nil {
113114
return fmt.Errorf("failed to create codacy directory: %w", err)
114115
}
115116

116-
if err := os.MkdirAll(c.runtimesDirectory, 0777); err != nil {
117+
if err := os.MkdirAll(c.runtimesDirectory, utils.DefaultDirPerms); err != nil {
117118
return fmt.Errorf("failed to create runtimes directory: %w", err)
118119
}
119120

120-
if err := os.MkdirAll(c.toolsDirectory, 0777); err != nil {
121+
if err := os.MkdirAll(c.toolsDirectory, utils.DefaultDirPerms); err != nil {
121122
return fmt.Errorf("failed to create tools directory: %w", err)
122123
}
123124
return nil
124125
}
125126

126127
func (c *ConfigType) CreateLocalCodacyDir() error {
127-
if err := os.MkdirAll(c.localCodacyDirectory, 0777); err != nil {
128+
if err := os.MkdirAll(c.localCodacyDirectory, utils.DefaultDirPerms); err != nil {
128129
return fmt.Errorf("failed to create local codacy directory: %w", err)
129130
}
130131
return nil

config/runtimes-installer_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package config
22

33
import (
44
"codacy/cli-v2/plugins"
5+
"codacy/cli-v2/utils"
56
"os"
67
"path/filepath"
78
"testing"
@@ -26,7 +27,7 @@ func TestIsRuntimeInstalled(t *testing.T) {
2627
assert.False(t, isRuntimeInstalled(runtimeInfoNoBinaries))
2728

2829
// Create the install directory
29-
err = os.MkdirAll(runtimeInfoNoBinaries.InstallDir, 0755)
30+
err = os.MkdirAll(runtimeInfoNoBinaries.InstallDir, utils.DefaultDirPerms)
3031
assert.NoError(t, err)
3132

3233
// Test when the install directory exists
@@ -52,4 +53,4 @@ func TestIsRuntimeInstalled(t *testing.T) {
5253

5354
// Test when the binary exists
5455
assert.True(t, isRuntimeInstalled(runtimeInfoWithBinaries))
55-
}
56+
}

utils/extract.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func ExtractTarGz(archive *os.File, targetDir string) error {
2525
switch f.IsDir() {
2626
case true:
2727
// create a directory
28-
err := os.MkdirAll(path, 0777)
28+
err := os.MkdirAll(path, DefaultDirPerms)
2929
if err != nil {
3030
return err
3131
}
@@ -37,9 +37,8 @@ func ExtractTarGz(archive *os.File, targetDir string) error {
3737
return nil
3838
}
3939

40-
4140
// Ensure parent directory exists
42-
err := os.MkdirAll(filepath.Dir(path), 0777)
41+
err := os.MkdirAll(filepath.Dir(path), DefaultDirPerms)
4342
if err != nil {
4443
return err
4544
}
@@ -74,7 +73,7 @@ func ExtractTarGz(archive *os.File, targetDir string) error {
7473
os.Remove(path)
7574

7675
// Ensure parent directory exists
77-
err := os.MkdirAll(filepath.Dir(path), 0777)
76+
err := os.MkdirAll(filepath.Dir(path), DefaultDirPerms)
7877
if err != nil {
7978
return err
8079
}
@@ -99,7 +98,7 @@ func ExtractZip(zipPath string, targetDir string) error {
9998
switch f.IsDir() {
10099
case true:
101100
// create a directory
102-
err := os.MkdirAll(path, 0777)
101+
err := os.MkdirAll(path, DefaultDirPerms)
103102
if err != nil {
104103
return err
105104
}
@@ -116,7 +115,7 @@ func ExtractZip(zipPath string, targetDir string) error {
116115
}
117116

118117
// ensure parent directory exists
119-
err := os.MkdirAll(filepath.Dir(path), 0777)
118+
err := os.MkdirAll(filepath.Dir(path), DefaultDirPerms)
120119
if err != nil {
121120
return err
122121
}

utils/files.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const (
77
// - read/write (rw-) permissions to the owner
88
// - read-only (r--) permissions to the group
99
// - read-only (r--) permissions to others
10-
DefaultRW = 0644
10+
DefaultFilePerms = 0644
1111

1212
// DefaultDirPerms represents the default directory permission (rwxr-xr-x)
1313
// This permission gives:

0 commit comments

Comments
 (0)