Skip to content

Commit

Permalink
chore: remove deprecated ioutil
Browse files Browse the repository at this point in the history
移除废弃的ioutil模块
  • Loading branch information
ice909 committed Sep 13, 2024
1 parent 9d4b722 commit a38e6f9
Show file tree
Hide file tree
Showing 12 changed files with 28 additions and 34 deletions.
3 changes: 1 addition & 2 deletions display/color_temp.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"bufio"
"bytes"
"errors"
"io/ioutil"
"math"
"os"
"os/exec"
Expand Down Expand Up @@ -115,7 +114,7 @@ func newRedshiftRunner() *redshiftRunner {
logger.Warning("new sys service failed:", err)
}
zoneInfoMap := make(map[string]*zoneInfo)
contents, err := ioutil.ReadFile(timeZoneFile)
contents, err := os.ReadFile(timeZoneFile)
if err != nil {
logger.Warning("Red timezone file failed:", err)
}
Expand Down
5 changes: 2 additions & 3 deletions display/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ package display
import (
"encoding/gob"
"encoding/json"
"io/ioutil"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -53,7 +52,7 @@ func updateSysMonitorConfigsName(configs SysMonitorConfigs, monitorMap map[uint3

func loadBuiltinMonitorConfig(filename string) (string, error) {
// #nosec G304
content, err := ioutil.ReadFile(filename)
content, err := os.ReadFile(filename)
if err != nil {
return "", err
}
Expand Down Expand Up @@ -87,7 +86,7 @@ func readConnectInfoCache(file string) (*ConnectInfo, error) {
// 加载 v5 或 v6 配置,v6 优先
func loadConfigV5V6(filename string) (*ConfigV6, error) {
// #nosec G304
data, err := ioutil.ReadFile(filename)
data, err := os.ReadFile(filename)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions display/config_v3_3.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package display

import (
"encoding/json"
"io/ioutil"
"os"
"sort"
"strings"
)
Expand Down Expand Up @@ -90,7 +90,7 @@ type ConfigV3D3 map[string]*ScreenConfigV3D3

func loadConfigV3D3(filename string) (ConfigV3D3, error) {
// #nosec G304
data, err := ioutil.ReadFile(filename)
data, err := os.ReadFile(filename)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions display/config_v4.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package display

import (
"encoding/json"
"io/ioutil"
"os"
)

type ConfigV4 map[string]*ScreenConfigV4
Expand Down Expand Up @@ -38,7 +38,7 @@ type OnlyOneModeConfig struct {

func loadConfigV4(filename string) (ConfigV4, error) {
// #nosec G304
data, err := ioutil.ReadFile(filename)
data, err := os.ReadFile(filename)
if err != nil {
return nil, err
}
Expand Down
8 changes: 4 additions & 4 deletions display/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import (
"encoding/json"
"errors"
"fmt"
"github.com/linuxdeepin/go-lib/keyfile"
"io/ioutil"
"math"
"os"
"os/exec"
Expand All @@ -20,6 +18,8 @@ import (
"sync"
"time"

"github.com/linuxdeepin/go-lib/keyfile"

"github.com/davecgh/go-spew/spew"
"github.com/godbus/dbus/v5"
"github.com/linuxdeepin/dde-api/dxinput"
Expand Down Expand Up @@ -2485,7 +2485,7 @@ func (m *Manager) associateTouch(monitor *Monitor, touchUUID string, auto bool)
}

func (m *Manager) loadUserConfig() error {
content, err := ioutil.ReadFile(userConfigFile)
content, err := os.ReadFile(userConfigFile)
if err != nil {
if os.IsNotExist(err) {
return nil
Expand Down Expand Up @@ -2532,7 +2532,7 @@ func (m *Manager) saveUserConfigNoLock() error {
}

filename := userConfigFile + ".new"
err = ioutil.WriteFile(filename, content, 0644)
err = os.WriteFile(filename, content, 0644)
if err != nil {
return err
}
Expand Down
10 changes: 5 additions & 5 deletions display/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
"bytes"
"encoding/json"
"errors"
"io/ioutil"
"math"
"os"
"path/filepath"
"regexp"
"sort"
Expand Down Expand Up @@ -301,7 +301,7 @@ func swapWidthHeightWithRotationInt32(rotation uint16, pWidth, pHeight *int32) {
}

func getConfigVersion(filename string) (string, error) {
content, err := ioutil.ReadFile(filename)
content, err := os.ReadFile(filename)
if err != nil {
return "", err
}
Expand All @@ -320,7 +320,7 @@ func getComputeChassis() (string, error) {
return "", err
}
if chassis == "" || chassis == "desktop" {
chassisNum, err := ioutil.ReadFile(chassisTypeFilePath)
chassisNum, err := os.ReadFile(chassisTypeFilePath)
if err != nil {
logger.Warning(err)
return "", err
Expand Down Expand Up @@ -380,7 +380,7 @@ var regCardOutput = regexp.MustCompile(`^card\d+-.+`)

func getStdMonitorName(edid []byte) (string, error) {
// /sys/class/drm/card0-HDMI-A-1
fileInfos, err := ioutil.ReadDir("/sys/class/drm")
fileInfos, err := os.ReadDir("/sys/class/drm")
if err != nil {
return "", err
}
Expand Down Expand Up @@ -413,6 +413,6 @@ func edidEqual(edid1, edid2 []byte) bool {
}

func readSysDrmEdid(name string) ([]byte, error) {
content, err := ioutil.ReadFile(filepath.Join("/sys/class/drm", name, "edid"))
content, err := os.ReadFile(filepath.Join("/sys/class/drm", name, "edid"))
return content, err
}
5 changes: 2 additions & 3 deletions wl_display/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package display

import (
"encoding/json"
"io/ioutil"
"os"
"path/filepath"

Expand Down Expand Up @@ -191,7 +190,7 @@ type MonitorConfig struct {
}

func loadConfigV4(filename string) (Config, error) {
data, err := ioutil.ReadFile(filename)
data, err := os.ReadFile(filename)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -252,7 +251,7 @@ func (c Config) save(filename string) error {
}
}

err = ioutil.WriteFile(filename, data, 0644)
err = os.WriteFile(filename, data, 0644)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions wl_display/config_v3_3.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package display

import (
"encoding/json"
"io/ioutil"
"os"
"sort"
"strings"
)
Expand Down Expand Up @@ -54,7 +54,7 @@ type MonitorConfiV3_3 struct {
type ConfigV3_3 map[string]*ScreenConfigV3_3

func loadConfigV3_3(filename string) (ConfigV3_3, error) {
data, err := ioutil.ReadFile(filename)
data, err := os.ReadFile(filename)
if err != nil {
return nil, err
}
Expand Down
3 changes: 1 addition & 2 deletions wl_display/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ package display
import (
"errors"
"fmt"
"io/ioutil"
"math"
"os"
"path/filepath"
Expand Down Expand Up @@ -1732,7 +1731,7 @@ func (m *Manager) saveConfig() error {
}

// #nosec G306
err = ioutil.WriteFile(configVersionFile, []byte(configVersion), 0644)
err = os.WriteFile(configVersionFile, []byte(configVersion), 0644)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions wl_display/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"os"
"os/exec"
"regexp"
"sort"
Expand Down Expand Up @@ -230,7 +230,7 @@ func needSwapWidthHeight(rotation uint16) bool {
}

func getConfigVersion(filename string) (string, error) {
content, err := ioutil.ReadFile(filename)
content, err := os.ReadFile(filename)
if err != nil {
return "", err
}
Expand Down
7 changes: 3 additions & 4 deletions xsettings/xsettings_dpi.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package xsettings

import (
"fmt"
"io/ioutil"
"os"
"path"
"strconv"
Expand Down Expand Up @@ -115,7 +114,7 @@ func (m *XSManager) updateFirefoxDPI() {
}

func getFirefoxConfigs(dir string) ([]string, error) {
finfos, err := ioutil.ReadDir(dir)
finfos, err := os.ReadDir(dir)
if err != nil {
return nil, err
}
Expand All @@ -131,7 +130,7 @@ func getFirefoxConfigs(dir string) ([]string, error) {
}

func setFirefoxDPI(value float64, src, dest string) error {
contents, err := ioutil.ReadFile(src)
contents, err := os.ReadFile(src)
if err != nil {
return err
}
Expand Down Expand Up @@ -164,5 +163,5 @@ func setFirefoxDPI(value float64, src, dest string) error {
lines[len(lines)-1] = target
lines = append(lines, tmp)
}
return ioutil.WriteFile(dest, []byte(strings.Join(lines, "\n")), 0644)
return os.WriteFile(dest, []byte(strings.Join(lines, "\n")), 0644)
}
5 changes: 2 additions & 3 deletions xsettings/xsettings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@ package xsettings

import (
"fmt"
"io/ioutil"
"os"
"testing"

C "gopkg.in/check.v1"
"github.com/linuxdeepin/go-lib/utils"
C "gopkg.in/check.v1"
)

type testWrapper struct{}
Expand Down Expand Up @@ -229,7 +228,7 @@ user_pref("toolkit.telemetry.reportingpolicy.firstRun", false);
c.Check(utils.IsFileExist(info.dest), C.Equals, false)
continue
}
contents, err := ioutil.ReadFile(info.dest)
contents, err := os.ReadFile(info.dest)
if err != nil {
fmt.Println("Failed to read file:", err)
continue
Expand Down

0 comments on commit a38e6f9

Please sign in to comment.