Skip to content

Commit

Permalink
Remove ioutil
Browse files Browse the repository at this point in the history
Signed-off-by: Cléo Rebert <[email protected]>
  • Loading branch information
constantoine committed Oct 4, 2023
1 parent b4caf96 commit 17ca25c
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 19 deletions.
3 changes: 1 addition & 2 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package main

import (
"bytes"
"io/ioutil"
"log"
"os"
"path/filepath"
Expand Down Expand Up @@ -78,7 +77,7 @@ func writeConfig(conf *config) {
if err := toml.NewEncoder(&buffer).Encode(&conf); err != nil {
log.Fatalf("Couldn't write config file: %v\n", err)
}
ioutil.WriteFile(f, buffer.Bytes(), 0644)
os.WriteFile(f, buffer.Bytes(), 0644)
}

func configDir() string {
Expand Down
6 changes: 3 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package main
import (
"fmt"
"image"
"io/ioutil"
"io"
"log"
"os"
"regexp"
Expand Down Expand Up @@ -60,7 +60,7 @@ func main() {
if opt.doLog {
log.SetOutput(os.Stdout)
} else {
log.SetOutput(ioutil.Discard)
log.SetOutput(io.Discard)
}
log.Printf("Application starting. Version: %s (%s)\n", version, distribution)
log.Printf("CAP_SYS_RESOURCE: %t\n", hasCapSysResource(getCurrentCaps()))
Expand Down Expand Up @@ -106,7 +106,7 @@ func main() {
}

func dumpLib() string {
f, err := ioutil.TempFile("", "librnnoise-*.so")
f, err := os.CreateTemp("", "librnnoise-*.so")
if err != nil {
log.Fatalf("Couldn't open temp file for librnnoise\n")
}
Expand Down
4 changes: 2 additions & 2 deletions rlimit.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
package main

import (
"io/ioutil"
"log"
"os"
"strconv"
"strings"
"syscall"
Expand All @@ -21,7 +21,7 @@ func getPulsePid() (int, error) {
if err != nil {
return 0, err
}
pidbuf, err := ioutil.ReadFile(pulsepidfile)
pidbuf, err := os.ReadFile(pulsepidfile)
if err != nil {
return 0, err
}
Expand Down
3 changes: 1 addition & 2 deletions scripts/embedlicenses.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package main

import (
"io/ioutil"
"os"
"path/filepath"
"strings"
Expand All @@ -28,7 +27,7 @@ func main() { //nolint
}
dir := filepath.Dir(rel)
out.WriteString("FILES: " + dir + "\n")
c, err := ioutil.ReadFile(path)
c, err := os.ReadFile(path)
str := string(c)
str = strings.ReplaceAll(str, "`", "`"+" + \"`\" + `") // escape backticks in license text for go src
if err != nil {
Expand Down
13 changes: 6 additions & 7 deletions scripts/signer.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"encoding/base64"
"flag"
"fmt"
"io/ioutil"
"os"
"path/filepath"

Expand Down Expand Up @@ -46,7 +45,7 @@ func main() { //nolint
if doSign && artifactFile != "" {
_, priv := loadKeys()

file, err := ioutil.ReadFile(artifactFile)
file, err := os.ReadFile(artifactFile)
if err != nil {
panic(err)
}
Expand All @@ -56,7 +55,7 @@ func main() { //nolint
panic(err)
}

err = ioutil.WriteFile(signatureFile, sig, 0640)
err = os.WriteFile(signatureFile, sig, 0640)
if err != nil {
panic(err)
}
Expand All @@ -69,12 +68,12 @@ func main() { //nolint
panic(err)
}

file, err := ioutil.ReadFile(artifactFile)
file, err := os.ReadFile(artifactFile)
if err != nil {
panic(err)
}

sig, err := ioutil.ReadFile(signatureFile)
sig, err := os.ReadFile(signatureFile)
if err != nil {
panic(err)
}
Expand All @@ -86,7 +85,7 @@ func main() { //nolint
}

func loadKeys() (ed25519.PublicKey, ed25519.PrivateKey) {
seed, err := ioutil.ReadFile(filepath.Join(os.Getenv("HOME"), ".config/noisetorch/private.key"))
seed, err := os.ReadFile(filepath.Join(os.Getenv("HOME"), ".config/noisetorch/private.key"))
if err != nil {
panic(err)
}
Expand All @@ -103,7 +102,7 @@ func generateKeypair() {
panic(err)
os.Exit(1)
}
if err := ioutil.WriteFile(filepath.Join(os.Getenv("HOME"), ".config/noisetorch/private.key"), priv.Seed(), 0600); err != nil {
if err := os.WriteFile(filepath.Join(os.Getenv("HOME"), ".config/noisetorch/private.key"), priv.Seed(), 0600); err != nil {
panic(err)
os.Exit(2)
}
Expand Down
6 changes: 3 additions & 3 deletions update.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"encoding/base64"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"log"
"net/http"
"os"
Expand Down Expand Up @@ -155,7 +155,7 @@ func fetchFile(file string) ([]byte, error) {
if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("received on 200 status code when fetching %s. Status: %s", file, resp.Status)
}
body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -197,7 +197,7 @@ func getLatestRelease() (string, error) {
defer res.Body.Close()
}

body, readErr := ioutil.ReadAll(res.Body)
body, readErr := io.ReadAll(res.Body)
if readErr != nil {
log.Fatal(readErr)
}
Expand Down

0 comments on commit 17ca25c

Please sign in to comment.