Skip to content

Commit 8139545

Browse files
committed
fix: replace deprecated io/ioutil with os package functions and remaining 401 magic number
- Remove deprecated io/ioutil imports (SA1019 warning) - Replace ioutil.ReadFile with os.ReadFile - Replace ioutil.WriteFile with os.WriteFile - Replace ioutil.ReadDir with os.ReadDir - Replace remaining 401 magic number with http.StatusUnauthorized Fixes staticcheck SA1019 and usestdlibvars linting issues in IDE setup code.
1 parent 6273725 commit 8139545

File tree

2 files changed

+14
-16
lines changed

2 files changed

+14
-16
lines changed

general/ide/jetbrains/jetbrains.go

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package jetbrains
33
import (
44
"bufio"
55
"fmt"
6-
"io/ioutil"
76
"net/http"
87
"os"
98
"path/filepath"
@@ -149,7 +148,7 @@ func (jc *JetbrainsCommand) validateRepository(repoURL string) error {
149148
if resp.StatusCode == http.StatusNotFound {
150149
return fmt.Errorf("repository not found (404). Please verify the repository key '%s' exists", jc.repoKey)
151150
}
152-
if resp.StatusCode >= 400 && resp.StatusCode != 401 {
151+
if resp.StatusCode >= 400 && resp.StatusCode != http.StatusUnauthorized {
153152
return fmt.Errorf("repository returned status %d. Please verify the repository is accessible", resp.StatusCode)
154153
}
155154

@@ -184,7 +183,7 @@ func (jc *JetbrainsCommand) detectJetBrainsIDEs() error {
184183
}
185184

186185
// Scan for IDE configurations
187-
entries, err := ioutil.ReadDir(configBasePath)
186+
entries, err := os.ReadDir(configBasePath)
188187
if err != nil {
189188
return fmt.Errorf("failed to read JetBrains configuration directory: %w", err)
190189
}
@@ -250,21 +249,21 @@ func (jc *JetbrainsCommand) createBackup(ide IDEInstallation) error {
250249
// If properties file doesn't exist, create an empty backup
251250
if _, err := os.Stat(ide.PropertiesPath); os.IsNotExist(err) {
252251
// Create empty file for backup record
253-
if err := ioutil.WriteFile(backupPath, []byte("# Empty properties file backup\n"), 0644); err != nil {
252+
if err := os.WriteFile(backupPath, []byte("# Empty properties file backup\n"), 0644); err != nil {
254253
return fmt.Errorf("failed to create backup marker: %w", err)
255254
}
256255
jc.backupPaths[ide.PropertiesPath] = backupPath
257256
return nil
258257
}
259258

260259
// Read existing properties file
261-
data, err := ioutil.ReadFile(ide.PropertiesPath)
260+
data, err := os.ReadFile(ide.PropertiesPath)
262261
if err != nil {
263262
return fmt.Errorf("failed to read properties file: %w", err)
264263
}
265264

266265
// Write backup
267-
if err := ioutil.WriteFile(backupPath, data, 0644); err != nil {
266+
if err := os.WriteFile(backupPath, data, 0644); err != nil {
268267
return fmt.Errorf("failed to create backup: %w", err)
269268
}
270269

@@ -280,7 +279,7 @@ func (jc *JetbrainsCommand) restoreBackup(ide IDEInstallation) error {
280279
return fmt.Errorf("no backup path available for %s", ide.PropertiesPath)
281280
}
282281

283-
data, err := ioutil.ReadFile(backupPath)
282+
data, err := os.ReadFile(backupPath)
284283
if err != nil {
285284
return fmt.Errorf("failed to read backup: %w", err)
286285
}
@@ -294,7 +293,7 @@ func (jc *JetbrainsCommand) restoreBackup(ide IDEInstallation) error {
294293
return nil
295294
}
296295

297-
if err := ioutil.WriteFile(ide.PropertiesPath, data, 0644); err != nil {
296+
if err := os.WriteFile(ide.PropertiesPath, data, 0644); err != nil {
298297
return fmt.Errorf("failed to restore backup: %w", err)
299298
}
300299

@@ -309,7 +308,7 @@ func (jc *JetbrainsCommand) modifyPropertiesFile(ide IDEInstallation, repoURL st
309308

310309
// Read existing properties if file exists
311310
if _, err := os.Stat(ide.PropertiesPath); err == nil {
312-
data, err := ioutil.ReadFile(ide.PropertiesPath)
311+
data, err := os.ReadFile(ide.PropertiesPath)
313312
if err != nil {
314313
return fmt.Errorf("failed to read properties file: %w", err)
315314
}
@@ -352,7 +351,7 @@ func (jc *JetbrainsCommand) modifyPropertiesFile(ide IDEInstallation, repoURL st
352351

353352
// Write modified properties file
354353
content := strings.Join(lines, "\n") + "\n"
355-
if err := ioutil.WriteFile(ide.PropertiesPath, []byte(content), 0644); err != nil {
354+
if err := os.WriteFile(ide.PropertiesPath, []byte(content), 0644); err != nil {
356355
return fmt.Errorf("failed to write properties file: %w", err)
357356
}
358357

general/ide/vscode/vscode.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package vscode
33
import (
44
"fmt"
55
"io"
6-
"io/ioutil"
76
"net/http"
87
"os"
98
"os/exec"
@@ -264,12 +263,12 @@ func (vc *VscodeCommand) createBackup() error {
264263
backupFileName := fmt.Sprintf("product.json.backup.%s", timestamp)
265264
vc.backupPath = filepath.Join(ideBackupDir, backupFileName)
266265

267-
data, err := ioutil.ReadFile(vc.productPath)
266+
data, err := os.ReadFile(vc.productPath)
268267
if err != nil {
269268
return fmt.Errorf("failed to read original product.json: %w", err)
270269
}
271270

272-
if err := ioutil.WriteFile(vc.backupPath, data, 0644); err != nil {
271+
if err := os.WriteFile(vc.backupPath, data, 0644); err != nil {
273272
return fmt.Errorf("failed to create backup: %w", err)
274273
}
275274

@@ -283,12 +282,12 @@ func (vc *VscodeCommand) restoreBackup() error {
283282
return fmt.Errorf("no backup path available")
284283
}
285284

286-
data, err := ioutil.ReadFile(vc.backupPath)
285+
data, err := os.ReadFile(vc.backupPath)
287286
if err != nil {
288287
return fmt.Errorf("failed to read backup: %w", err)
289288
}
290289

291-
if err := ioutil.WriteFile(vc.productPath, data, 0644); err != nil {
290+
if err := os.WriteFile(vc.productPath, data, 0644); err != nil {
292291
return fmt.Errorf("failed to restore backup: %w", err)
293292
}
294293
return nil
@@ -389,7 +388,7 @@ func (vc *VscodeCommand) modifyWithPowerShell(repoURL string) error {
389388

390389
// verifyModification checks that the serviceUrl was actually changed
391390
func (vc *VscodeCommand) verifyModification(expectedURL string) error {
392-
data, err := ioutil.ReadFile(vc.productPath)
391+
data, err := os.ReadFile(vc.productPath)
393392
if err != nil {
394393
return fmt.Errorf("failed to read file for verification: %w", err)
395394
}

0 commit comments

Comments
 (0)