Skip to content

Commit

Permalink
Replace depreciated functions from ioutils package
Browse files Browse the repository at this point in the history
ioutils has been depreciated since Go 1.19; since Go 1.16 [bookworm]
the same functionality is provided by the io or os packages. Use the
new packages instead.

Signed-off-by: Christopher Obbard <[email protected]>
  • Loading branch information
obbardc committed Oct 30, 2024
1 parent e5d575a commit aec0eb8
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
3 changes: 1 addition & 2 deletions backend_qemu.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package fakemachine
import (
"bytes"
"fmt"
"io/ioutil"
"os"
"os/exec"
"path"
Expand Down Expand Up @@ -85,7 +84,7 @@ func (b qemuBackend) KernelRelease() (string, error) {
return release, nil
}

files, err := ioutil.ReadDir("/lib/modules")
files, err := os.ReadDir("/lib/modules")
if err != nil {
return "", err
}
Expand Down
3 changes: 1 addition & 2 deletions backend_uml.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package fakemachine
import (
"errors"
"fmt"
"io/ioutil"
"os"
"os/exec"
"path"
Expand Down Expand Up @@ -71,7 +70,7 @@ func (b umlBackend) ModulePath() (string, error) {
}

// find the subdirectory containing the modules for the UML release
modSubdirs, err := ioutil.ReadDir(moddir)
modSubdirs, err := os.ReadDir(moddir)
if err != nil {
return "", err
}
Expand Down
10 changes: 6 additions & 4 deletions machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"errors"
"fmt"
"github.com/alessio/shellescape"
"io/ioutil"
"io"
"os"
"os/exec"
"path"
Expand Down Expand Up @@ -609,7 +609,7 @@ func (m *Machine) setupscratch() error {
return nil
}

tmpfile, err := ioutil.TempFile(m.scratchpath, "fake-scratch.img.")
tmpfile, err := os.CreateTemp(m.scratchpath, "fake-scratch.img.")
if err != nil {
return err
}
Expand Down Expand Up @@ -659,10 +659,12 @@ func (m *Machine) startup(command string, extracontent [][2]string) (int, error)
}
}

tmpdir, err := ioutil.TempDir("", "fakemachine-")
tmp, err := os.CreateTemp("", "fakemachine-")
if err != nil {
return -1, err
}

tmpdir := tmp.Name()
m.AddVolumeAt(tmpdir, "/run/fakemachine")
defer os.RemoveAll(tmpdir)

Expand Down Expand Up @@ -902,7 +904,7 @@ func (m *Machine) startup(command string, extracontent [][2]string) (int, error)
return -1, err
}

exitstr, _ := ioutil.ReadAll(result)
exitstr, _ := io.ReadAll(result)
exitcode, err := strconv.Atoi(strings.TrimSpace(string(exitstr)))

if err != nil {
Expand Down

0 comments on commit aec0eb8

Please sign in to comment.