Skip to content

Commit 00ba90a

Browse files
committed
♻️ refactor: add lint suppression comments for file operations in multiple packages
1 parent 34738c8 commit 00ba90a

9 files changed

Lines changed: 15 additions & 24 deletions

File tree

internal/adapters/secondary/filesystem/fs.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func NewOSFileSystem() *OSFileSystem {
2929
//
3030
//nolint:gosec,nolintlint // Filesystem adapter - file access controlled by caller
3131
func (fs *OSFileSystem) ReadFile(name string) ([]byte, error) {
32-
return os.ReadFile(name)
32+
return os.ReadFile(name) // #nosec G304 -- Filesystem adapter, paths controlled by caller
3333
}
3434

3535
// WriteFile writes data to a file with the given permissions.
@@ -66,14 +66,14 @@ func (fs *OSFileSystem) Rename(oldpath, newpath string) error {
6666
//
6767
//nolint:gosec,nolintlint // Filesystem adapter - file access controlled by caller
6868
func (fs *OSFileSystem) Open(name string) (io.ReadCloser, error) {
69-
return os.Open(name)
69+
return os.Open(name) // #nosec G304 -- Filesystem adapter, paths controlled by caller
7070
}
7171

7272
// Create creates or truncates the named file.
7373
//
7474
//nolint:gosec,nolintlint // Filesystem adapter - file access controlled by caller
7575
func (fs *OSFileSystem) Create(name string) (io.WriteCloser, error) {
76-
return os.Create(name)
76+
return os.Create(name) // #nosec G304 -- Filesystem adapter, paths controlled by caller
7777
}
7878

7979
// Exists returns true if the file exists.

internal/core/services/compiler/executor.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,7 @@ func compile(dprojPath string, dep *domain.Dependency, rootLock domain.PackageLo
9595
abs, _ := filepath.Abs(filepath.Dir(dprojPath))
9696
buildLog := filepath.Join(abs, fileRes+".log")
9797
buildBat := filepath.Join(abs, fileRes+".bat")
98-
//nolint:gosec,nolintlint // Reading Delphi environment variables file from known location
99-
readFile, err := os.ReadFile(rsvars)
98+
readFile, err := os.ReadFile(rsvars) // #nosec G304 -- Reading Delphi environment variables file from known location
10099
if err != nil {
101100
msg.Err(" ❌ Error on read rsvars.bat")
102101
}

internal/core/services/paths/paths.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ func EnsureCleanModulesDir(dependencies []domain.Dependency, lock domain.Package
2020
cacheDir := env.GetModulesDir()
2121
cacheDirInfo, err := os.Stat(cacheDir)
2222
if os.IsNotExist(err) {
23-
err = os.MkdirAll(cacheDir, 0755)
23+
err = os.MkdirAll(cacheDir, 0755) // #nosec G301 -- Standard permissions for cache directory
2424
if err != nil {
2525
msg.Die("❌ Failed to create modules directory: %v", err)
2626
}
@@ -71,7 +71,7 @@ func EnsureCacheDir(config env.ConfigProvider, dep domain.Dependency) {
7171
fi, err := os.Stat(cacheDir)
7272
if err != nil {
7373
msg.Debug("Creating %s", cacheDir)
74-
err = os.MkdirAll(cacheDir, 0755)
74+
err = os.MkdirAll(cacheDir, 0755) // #nosec G301 -- Standard permissions for cache directory
7575
if err != nil {
7676
msg.Die("❌ Could not create %s: %s", cacheDir, err)
7777
}

pkg/env/configuration.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -143,15 +143,13 @@ func (c *Configuration) SaveConfiguration() {
143143
msg.Die("❌ Failed to parse config file", err.Error())
144144
}
145145

146-
//nolint:gosec,nolintlint // Standard permissions for Boss cache directory
147-
err = os.MkdirAll(c.path, 0755)
146+
err = os.MkdirAll(c.path, 0755) // #nosec G301 -- Standard permissions for Boss cache directory
148147
if err != nil {
149148
msg.Die("❌ Failed to create path", c.path, err.Error())
150149
}
151150

152151
configPath := filepath.Join(c.path, consts.BossConfigFile)
153-
//nolint:gosec,nolintlint // Creating Boss configuration file in known location
154-
f, err := os.Create(configPath)
152+
f, err := os.Create(configPath) // #nosec G304 -- Creating Boss configuration file in known location
155153
if err != nil {
156154
msg.Die("❌ Failed to create file ", configPath, err.Error())
157155
return
@@ -186,8 +184,7 @@ func LoadConfiguration(cachePath string) (*Configuration, error) {
186184
}
187185

188186
configFileName := filepath.Join(cachePath, consts.BossConfigFile)
189-
//nolint:gosec,nolintlint // Reading Boss configuration file from cache directory
190-
buffer, err := os.ReadFile(configFileName)
187+
buffer, err := os.ReadFile(configFileName) // #nosec G304 -- Reading Boss configuration file from cache directory
191188
if err != nil {
192189
return makeDefault(cachePath), err
193190
}

setup/migrations.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,7 @@ func seven() {
5454
if _, err := os.Stat(bossCfg); os.IsNotExist(err) {
5555
return
5656
}
57-
//nolint:gosec,nolintlint // Reading Boss configuration file from known location
58-
file, err := os.Open(bossCfg)
57+
file, err := os.Open(bossCfg) // #nosec G304 -- Reading Boss configuration file from known location
5958
if err != nil {
6059
msg.Warn("⚠️ Migration 7: could not open config file: %v", err)
6160
return

setup/setup.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ func initializeInfrastructure() {
7070
func CreatePaths() {
7171
_, err := os.Stat(env.GetGlobalEnvBpl())
7272
if os.IsNotExist(err) {
73-
_ = os.MkdirAll(env.GetGlobalEnvBpl(), 0755)
73+
_ = os.MkdirAll(env.GetGlobalEnvBpl(), 0755) // #nosec G301 -- Standard permissions for shared directory
7474
}
7575
}
7676

utils/dcp/dcp.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,7 @@ func InjectDpcsFile(fileName string, pkg *domain.Package, lock domain.PackageLoc
5252

5353
// readFile reads a file with Windows1252 encoding.
5454
func readFile(filename string) string {
55-
//nolint:gosec,nolintlint // Reading DCP files from controlled package directories
56-
f, err := os.Open(filename)
55+
f, err := os.Open(filename) // #nosec G304 -- Reading DCP files from controlled package directories
5756
if err != nil {
5857
msg.Die(err.Error())
5958
}
@@ -69,8 +68,7 @@ func readFile(filename string) string {
6968

7069
// writeFile writes a file with Windows1252 encoding.
7170
func writeFile(filename string, content string) {
72-
//nolint:gosec,nolintlint // Writing DCP files to controlled package directories
73-
f, err := os.Create(filename)
71+
f, err := os.Create(filename) // #nosec G304 -- Writing DCP files to controlled package directories
7472
if err != nil {
7573
msg.Die(err.Error())
7674
}

utils/hash.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ func HashDir(dir string) string {
3434
return nil
3535
}
3636

37-
//nolint:gosec,nolintlint // Reading files from controlled directory structure for hashing
38-
fileBytes, _ := os.ReadFile(path)
37+
fileBytes, _ := os.ReadFile(path) // #nosec G304 -- Reading files from controlled directory structure for hashing
3938
fileHash := hashByte(&fileBytes)
4039
finalHash += fileHash
4140
return nil

utils/librarypath/librarypath.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,7 @@ func setReadOnlyProperty(dir string) {
9696
msg.Warn(" ⚠️ Error on create build file")
9797
}
9898

99-
//nolint:gosec,nolintlint // Executing controlled batch file with readonly attributes
100-
cmd := exec.Command(readonlybat)
99+
cmd := exec.Command(readonlybat) // #nosec G204 -- Executing controlled batch file with readonly attributes
101100

102101
_, err = cmd.Output()
103102
if err != nil {

0 commit comments

Comments
 (0)