Skip to content

Commit

Permalink
chore: remove deprecated ioutil
Browse files Browse the repository at this point in the history
remove deprecated ioutil
  • Loading branch information
zsien committed Sep 25, 2024
1 parent f5e6bdb commit dc5af3b
Show file tree
Hide file tree
Showing 82 changed files with 191 additions and 229 deletions.
4 changes: 2 additions & 2 deletions accounts1/checkers/username.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package checkers

import (
"errors"
"io/ioutil"
"os"
"os/user"
"regexp"
"strconv"
Expand Down Expand Up @@ -159,7 +159,7 @@ func (name Username) getUid() (int64, error) {
}

func getAllUsername(file string) (UsernameList, error) {
content, err := ioutil.ReadFile(file)
content, err := os.ReadFile(file)
if err != nil {
return nil, err
}
Expand Down
7 changes: 3 additions & 4 deletions accounts1/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
Expand Down Expand Up @@ -252,7 +251,7 @@ func (m *Manager) initUsers(list []string) {
func (m *Manager) initUdcpCache() error {
// 解析json文件 新建udcp-cache对象
var ifcCfg InterfaceConfig
content, err := ioutil.ReadFile(interfacesFile)
content, err := os.ReadFile(interfacesFile)
if err != nil {
return err
}
Expand Down Expand Up @@ -592,7 +591,7 @@ func (m *Manager) loadDomainUserConfig() error {
return err
}
} else {
data, err := ioutil.ReadFile(configFile)
data, err := os.ReadFile(configFile)
if err != nil {
return err
}
Expand Down Expand Up @@ -622,7 +621,7 @@ func (m *Manager) saveDomainUserConfig(config DefaultDomainUserConfig) error {
return err
}

err = ioutil.WriteFile(configFile, data, 0644)
err = os.WriteFile(configFile, data, 0644)
return err
}

Expand Down
5 changes: 2 additions & 3 deletions accounts1/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"encoding/base64"
"errors"
"fmt"
"io/ioutil"
"os"
"path"
"path/filepath"
Expand Down Expand Up @@ -707,7 +706,7 @@ func scaleUserIcon(file string) (string, bool, error) {

// return temp file path and error
func getTempFile() (string, error) {
tmpfile, err := ioutil.TempFile("", "dde-daemon-accounts")
tmpfile, err := os.CreateTemp("", "dde-daemon-accounts")
if err != nil {
return "", err
}
Expand Down Expand Up @@ -739,7 +738,7 @@ func getUserSession(homeDir string) string {
}

func getSessionList() []string {
fileInfoList, err := ioutil.ReadDir("/usr/share/xsessions")
fileInfoList, err := os.ReadDir("/usr/share/xsessions")
if err != nil {
return nil
}
Expand Down
3 changes: 1 addition & 2 deletions accounts1/user_chpwd_union_id.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"os"
"os/exec"
"os/user"
Expand Down Expand Up @@ -692,7 +691,7 @@ func removeLoginKeyring(user *User) (err error) {
isUseWhiteboxFunc := func() bool {
statusFile := fmt.Sprintf("%s/status", dir)
if dutils.IsFileExist(dir) && dutils.IsFileExist(statusFile) {
content, err := ioutil.ReadFile(statusFile)
content, err := os.ReadFile(statusFile)
if err != nil {
return false
}
Expand Down
3 changes: 1 addition & 2 deletions accounts1/user_ifc.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"os"
"path"
"path/filepath"
Expand Down Expand Up @@ -1249,7 +1248,7 @@ func (u *User) SetSecretQuestions(sender dbus.Sender, list map[int][]byte) *dbus
content.WriteRune('\n')
}

err = ioutil.WriteFile(path, content.Bytes(), 0600)
err = os.WriteFile(path, content.Bytes(), 0600)
return dbusutil.ToError(err)
}

Expand Down
7 changes: 3 additions & 4 deletions accounts1/users/display_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package users

import (
"fmt"
"io/ioutil"
"os"
"path"
"path/filepath"
Expand Down Expand Up @@ -438,7 +437,7 @@ func getDefaultDM(file string) (string, error) {
return "", fmt.Errorf("Not found this file: %s", file)
}

content, err := ioutil.ReadFile(file)
content, err := os.ReadFile(file)
if err != nil {
return "", err
}
Expand Down Expand Up @@ -478,7 +477,7 @@ func getDMFromSystemService(service string) (string, error) {

// enable autologin: set 'auto_login' to 'yes', and 'default_user' to 'username'
func parseSlimConfig(filename, username string, isWirte bool) (string, error) {
content, err := ioutil.ReadFile(filename)
content, err := os.ReadFile(filename)
if err != nil {
return "", err
}
Expand Down Expand Up @@ -547,5 +546,5 @@ func parseSlimConfig(filename, username string, isWirte bool) (string, error) {
}

data := strings.Join(lines, "\n")
return "", ioutil.WriteFile(filename, []byte(data), 0644)
return "", os.WriteFile(filename, []byte(data), 0644)
}
3 changes: 1 addition & 2 deletions accounts1/users/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"bufio"
"errors"
"fmt"
"io/ioutil"
"os"
"strconv"
"strings"
Expand Down Expand Up @@ -131,7 +130,7 @@ func getUserInfo(condition UserInfo, file string) (UserInfo, error) {
}

func getUserInfosFromFile(file string) (UserInfos, error) {
content, err := ioutil.ReadFile(file)
content, err := os.ReadFile(file)
if err != nil {
return nil, err
}
Expand Down
3 changes: 1 addition & 2 deletions accounts1/users/prop.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"bytes"
"errors"
"fmt"
"io/ioutil"
"os"
"os/exec"
"sort"
Expand Down Expand Up @@ -417,7 +416,7 @@ func getGroupInfoWithCache(file string) (map[string]GroupInfo, error) {
return groupFileInfo, nil
}

content, err := ioutil.ReadFile(file)
content, err := os.ReadFile(file)
if err != nil {
return nil, err
}
Expand Down
3 changes: 1 addition & 2 deletions accounts1/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"math/rand"
"os"
"path/filepath"
Expand Down Expand Up @@ -328,7 +327,7 @@ func getValueFromLine(line, delim string) string {

// Get available shells from '/etc/shells'
func getAvailableShells(file string) []string {
contents, err := ioutil.ReadFile(file)
contents, err := os.ReadFile(file)
if err != nil || len(contents) == 0 {
return nil
}
Expand Down
3 changes: 1 addition & 2 deletions appinfo/rate.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
package appinfo

import (
"io/ioutil"
"os"

"github.com/linuxdeepin/go-gir/glib-2.0"
Expand Down Expand Up @@ -43,7 +42,7 @@ func saveKeyFile(file *glib.KeyFile, path string) error {
return err
}

err = ioutil.WriteFile(path, []byte(content), stat.Mode())
err = os.WriteFile(path, []byte(content), stat.Mode())
if err != nil {
return err
}
Expand Down
6 changes: 3 additions & 3 deletions apps1/subrecorder.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ import (
"crypto/md5"
"encoding/csv"
"fmt"
"github.com/linuxdeepin/go-lib/utils"
"io"
"io/ioutil"
"os"
"os/exec"
"os/user"
"path/filepath"
"strings"
"sync"
"time"

"github.com/linuxdeepin/go-lib/utils"
)

const (
Expand Down Expand Up @@ -216,7 +216,7 @@ func (sr *SubRecorder) writeStatus(w io.Writer) error {
func (sr *SubRecorder) save() error {
logger.Debug("SubRecorder.save", sr.root, sr.statusFile)
file := sr.statusFile
f, err := ioutil.TempFile("", fmt.Sprintf("%s.new%x-", filepath.Base(file), time.Now().UnixNano()))
f, err := os.CreateTemp("", fmt.Sprintf("%s.new%x-", filepath.Base(file), time.Now().UnixNano()))
if err != nil {
return err
}
Expand Down
6 changes: 3 additions & 3 deletions audio1/bluez_audio.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package audio

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

Expand Down Expand Up @@ -67,7 +67,7 @@ func (m *BluezAudioManager) Save() {
return
}

err = ioutil.WriteFile(m.file, data, 0644)
err = os.WriteFile(m.file, data, 0644)
if err != nil {
logger.Warning(err)
return
Expand All @@ -76,7 +76,7 @@ func (m *BluezAudioManager) Save() {

/* 加载配置 */
func (m *BluezAudioManager) Load() {
data, err := ioutil.ReadFile(m.file)
data, err := os.ReadFile(m.file)
if err != nil {
logger.Warning(err)
return
Expand Down
5 changes: 2 additions & 3 deletions audio1/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package audio

import (
"encoding/json"
"io/ioutil"
"os"
"path/filepath"
"sync"
Expand Down Expand Up @@ -61,7 +60,7 @@ func readConfig() (*config, error) {
}

var info config
content, err := ioutil.ReadFile(configFile)
content, err := os.ReadFile(configFile)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -93,7 +92,7 @@ func saveConfig(info *config) error {
if err != nil {
return err
}
err = ioutil.WriteFile(configFile, content, 0644)
err = os.WriteFile(configFile, content, 0644)
if err != nil {
return err
}
Expand Down
10 changes: 5 additions & 5 deletions audio1/config_keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package audio

import (
"encoding/json"
"io/ioutil"
"os"
"path/filepath"
"strings"
"sync"
Expand Down Expand Up @@ -113,7 +113,7 @@ func (ck *ConfigKeeper) Save() error {
return err
}

err = ioutil.WriteFile(ck.file, data, 0644)
err = os.WriteFile(ck.file, data, 0644)
if err != nil {
logger.Warning(err)
// 这里不返回,因为可能可以写另一个配置
Expand All @@ -125,7 +125,7 @@ func (ck *ConfigKeeper) Save() error {
return err
}

err = ioutil.WriteFile(ck.muteFile, data, 0644)
err = os.WriteFile(ck.muteFile, data, 0644)
if err != nil {
logger.Warning(err)
return err
Expand All @@ -135,7 +135,7 @@ func (ck *ConfigKeeper) Save() error {
}

func (ck *ConfigKeeper) Load() error {
data, err := ioutil.ReadFile(ck.file)
data, err := os.ReadFile(ck.file)
if err != nil {
logger.Warning(err)
return err
Expand All @@ -146,7 +146,7 @@ func (ck *ConfigKeeper) Load() error {
logger.Warning(err)
}

data, err = ioutil.ReadFile(ck.muteFile)
data, err = os.ReadFile(ck.muteFile)
if err != nil {
logger.Warning(err)
return err
Expand Down
3 changes: 1 addition & 2 deletions audio1/config_keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
package audio

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

Expand Down Expand Up @@ -74,7 +73,7 @@ func TestConfigKeeper_Save(t *testing.T) {
require.NoError(t, err)
assert.Equal(t, 0644, int(s.Mode())&0777)

content, err := ioutil.ReadFile(tt.fields.file)
content, err := os.ReadFile(tt.fields.file)
require.NoError(t, err)
assert.Equal(t, tt.fileContent, string(content))

Expand Down
6 changes: 3 additions & 3 deletions audio1/priority_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package audio

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

"github.com/linuxdeepin/go-lib/pulse"
Expand Down Expand Up @@ -71,7 +71,7 @@ func (pm *PriorityManager) Save() {
return
}

err = ioutil.WriteFile(pm.file, data, 0644)
err = os.WriteFile(pm.file, data, 0644)
if err != nil {
logger.Warning(err)
return
Expand All @@ -80,7 +80,7 @@ func (pm *PriorityManager) Save() {

// 读取配置文件
func (pm *PriorityManager) Load() bool {
data, err := ioutil.ReadFile(pm.file)
data, err := os.ReadFile(pm.file)
if err != nil {
logger.Warningf("failed to read file '%s': %v", pm.file, err)
return false
Expand Down
Loading

0 comments on commit dc5af3b

Please sign in to comment.