Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,12 +313,12 @@ func createToolFileConfigurations(tool tools.Tool, patternConfiguration []domain

func createPMDConfigFile(config []domain.PatternConfiguration, toolsConfigDir string) error {
pmdConfigurationString := tools.CreatePmdConfig(config)
return os.WriteFile(filepath.Join(toolsConfigDir, "pmd-ruleset.xml"), []byte(pmdConfigurationString), utils.DefaultRW)
return os.WriteFile(filepath.Join(toolsConfigDir, "pmd-ruleset.xml"), []byte(pmdConfigurationString), utils.DefaultFilePerms)
}

func createDefaultPMDConfigFile(toolsConfigDir string) error {
content := tools.CreatePmdConfig([]domain.PatternConfiguration{})
return os.WriteFile(filepath.Join(toolsConfigDir, "pmd-ruleset.xml"), []byte(content), utils.DefaultRW)
return os.WriteFile(filepath.Join(toolsConfigDir, "pmd-ruleset.xml"), []byte(content), utils.DefaultFilePerms)
}

// createTrivyConfigFile creates a trivy.yaml configuration file based on the API configuration
Expand All @@ -327,7 +327,7 @@ func createTrivyConfigFile(config []domain.PatternConfiguration, toolsConfigDir
trivyConfigurationString := tools.CreateTrivyConfig(config)

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

// createDefaultTrivyConfigFile creates a default trivy.yaml configuration file
Expand All @@ -337,7 +337,7 @@ func createDefaultTrivyConfigFile(toolsConfigDir string) error {
content := tools.CreateTrivyConfig(emptyConfig)

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

// createDefaultEslintConfigFile creates a default eslint.config.mjs configuration file
Expand All @@ -347,7 +347,7 @@ func createDefaultEslintConfigFile(toolsConfigDir string) error {
content := tools.CreateEslintConfig(emptyConfig)

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

const (
Expand Down
9 changes: 5 additions & 4 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"path/filepath"

"codacy/cli-v2/plugins"
"codacy/cli-v2/utils"
)

type ConfigType struct {
Expand Down Expand Up @@ -109,22 +110,22 @@ func (c *ConfigType) setupCodacyPaths() {
}

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

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

if err := os.MkdirAll(c.toolsDirectory, 0777); err != nil {
if err := os.MkdirAll(c.toolsDirectory, utils.DefaultDirPerms); err != nil {
return fmt.Errorf("failed to create tools directory: %w", err)
}
return nil
}

func (c *ConfigType) CreateLocalCodacyDir() error {
if err := os.MkdirAll(c.localCodacyDirectory, 0777); err != nil {
if err := os.MkdirAll(c.localCodacyDirectory, utils.DefaultDirPerms); err != nil {
return fmt.Errorf("failed to create local codacy directory: %w", err)
}
return nil
Expand Down
5 changes: 3 additions & 2 deletions config/runtimes-installer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package config

import (
"codacy/cli-v2/plugins"
"codacy/cli-v2/utils"
"os"
"path/filepath"
"testing"
Expand All @@ -26,7 +27,7 @@ func TestIsRuntimeInstalled(t *testing.T) {
assert.False(t, isRuntimeInstalled(runtimeInfoNoBinaries))

// Create the install directory
err = os.MkdirAll(runtimeInfoNoBinaries.InstallDir, 0755)
err = os.MkdirAll(runtimeInfoNoBinaries.InstallDir, utils.DefaultDirPerms)
assert.NoError(t, err)

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

// Test when the binary exists
assert.True(t, isRuntimeInstalled(runtimeInfoWithBinaries))
}
}
11 changes: 5 additions & 6 deletions utils/extract.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func ExtractTarGz(archive *os.File, targetDir string) error {
switch f.IsDir() {
case true:
// create a directory
err := os.MkdirAll(path, 0777)
err := os.MkdirAll(path, DefaultDirPerms)
if err != nil {
return err
}
Expand All @@ -37,9 +37,8 @@ func ExtractTarGz(archive *os.File, targetDir string) error {
return nil
}


// Ensure parent directory exists
err := os.MkdirAll(filepath.Dir(path), 0777)
err := os.MkdirAll(filepath.Dir(path), DefaultDirPerms)
if err != nil {
return err
}
Expand Down Expand Up @@ -74,7 +73,7 @@ func ExtractTarGz(archive *os.File, targetDir string) error {
os.Remove(path)

// Ensure parent directory exists
err := os.MkdirAll(filepath.Dir(path), 0777)
err := os.MkdirAll(filepath.Dir(path), DefaultDirPerms)
if err != nil {
return err
}
Expand All @@ -99,7 +98,7 @@ func ExtractZip(zipPath string, targetDir string) error {
switch f.IsDir() {
case true:
// create a directory
err := os.MkdirAll(path, 0777)
err := os.MkdirAll(path, DefaultDirPerms)
if err != nil {
return err
}
Expand All @@ -116,7 +115,7 @@ func ExtractZip(zipPath string, targetDir string) error {
}

// ensure parent directory exists
err := os.MkdirAll(filepath.Dir(path), 0777)
err := os.MkdirAll(filepath.Dir(path), DefaultDirPerms)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion utils/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const (
// - read/write (rw-) permissions to the owner
// - read-only (r--) permissions to the group
// - read-only (r--) permissions to others
DefaultRW = 0644
DefaultFilePerms = 0644

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