Skip to content

Commit 6958c6e

Browse files
refactor: Use constants for file and directory permissions in tool runners
- Updated file and directory permission settings in tools (Dart Analyzer, Pylint, Lizard) to utilize constants from the new constants package. - Ensured consistent permission handling across various tool runners, enhancing maintainability and readability of the codebase.
1 parent a43fa24 commit 6958c6e

File tree

4 files changed

+10
-6
lines changed

4 files changed

+10
-6
lines changed

config/tools-installer.go

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

33
import (
44
"bytes"
5+
"codacy/cli-v2/constants"
56
"codacy/cli-v2/plugins"
67
"codacy/cli-v2/utils"
78
"codacy/cli-v2/utils/logger"
@@ -102,7 +103,7 @@ func InstallTool(name string, toolInfo *plugins.ToolInfo, registry string) error
102103
}
103104

104105
// Make sure the installation directory exists
105-
err := os.MkdirAll(toolInfo.InstallDir, 0755)
106+
err := os.MkdirAll(toolInfo.InstallDir, constants.DefaultDirPerms)
106107
if err != nil {
107108
return fmt.Errorf("failed to create installation directory: %w", err)
108109
}
@@ -291,7 +292,7 @@ func installDownloadBasedTool(toolInfo *plugins.ToolInfo) error {
291292
defer file.Close()
292293

293294
// Create the installation directory
294-
err = os.MkdirAll(toolInfo.InstallDir, 0755)
295+
err = os.MkdirAll(toolInfo.InstallDir, constants.DefaultDirPerms)
295296
if err != nil {
296297
return fmt.Errorf("failed to create installation directory: %w", err)
297298
}
@@ -316,7 +317,7 @@ func installDownloadBasedTool(toolInfo *plugins.ToolInfo) error {
316317

317318
// Make sure all binaries are executable
318319
for _, binaryPath := range toolInfo.Binaries {
319-
err = os.Chmod(filepath.Join(toolInfo.InstallDir, filepath.Base(binaryPath)), 0755)
320+
err = os.Chmod(filepath.Join(toolInfo.InstallDir, filepath.Base(binaryPath)), constants.DefaultDirPerms)
320321
if err != nil && !os.IsNotExist(err) {
321322
return fmt.Errorf("failed to make binary executable: %w", err)
322323
}

tools/dartanalyzerRunner.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package tools
33
import (
44
"bufio"
55
"bytes"
6+
"codacy/cli-v2/constants"
67
"encoding/json"
78
"fmt"
89
"log"
@@ -121,7 +122,7 @@ func RunDartAnalyzer(workDirectory string, installationDirectory string, binary
121122
// Write SARIF output to file if specified
122123
if outputFile != "" {
123124
sarifJson, _ := json.MarshalIndent(sarif, "", " ")
124-
err := os.WriteFile(outputFile, sarifJson, 0644)
125+
err := os.WriteFile(outputFile, sarifJson, constants.DefaultFilePerms)
125126
if err != nil {
126127
fmt.Fprintf(os.Stderr, "Error writing SARIF output: %v\n", err)
127128
}

tools/lizard/lizardRunner.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package lizard
33
import (
44
"bytes"
55
"codacy/cli-v2/config"
6+
"codacy/cli-v2/constants"
67
"codacy/cli-v2/domain"
78
"codacy/cli-v2/tools"
89
"encoding/json"
@@ -84,7 +85,7 @@ func RunLizard(workDirectory string, binary string, files []string, outputFile s
8485

8586
// Write SARIF output to file if specified, else stdout
8687
if outputFile != "" {
87-
err = os.WriteFile(outputFile, sarifData, 0644)
88+
err = os.WriteFile(outputFile, sarifData, constants.DefaultFilePerms)
8889
if err != nil {
8990
return fmt.Errorf("failed to write SARIF output: %w", err)
9091
}

tools/pylintRunner.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package tools
22

33
import (
44
"codacy/cli-v2/config"
5+
"codacy/cli-v2/constants"
56
"codacy/cli-v2/utils"
67
"fmt"
78
"os"
@@ -69,7 +70,7 @@ func RunPylint(workDirectory string, binary string, files []string, outputFile s
6970
sarifOutput := utils.ConvertPylintToSarif(jsonOutput)
7071

7172
if outputFile != "" {
72-
err = os.WriteFile(outputFile, sarifOutput, 0644)
73+
err = os.WriteFile(outputFile, sarifOutput, constants.DefaultFilePerms)
7374
if err != nil {
7475
return fmt.Errorf("failed to write SARIF output: %w", err)
7576
}

0 commit comments

Comments
 (0)