From 9d557af2ced178102e5d8047ebd5eb8c1e49e24a Mon Sep 17 00:00:00 2001 From: Peres Kereotubo Date: Mon, 14 Aug 2023 13:27:25 -0400 Subject: [PATCH] updating deprecated packages --- gofsutil_mount_linux.go | 5 ++--- gofsutil_mount_test.go | 5 ++--- gofsutil_mount_unix.go | 27 +++++++++++++-------------- gofsutil_unix_test.go | 5 ++--- 4 files changed, 19 insertions(+), 23 deletions(-) diff --git a/gofsutil_mount_linux.go b/gofsutil_mount_linux.go index c30ae47..f3f2844 100644 --- a/gofsutil_mount_linux.go +++ b/gofsutil_mount_linux.go @@ -16,7 +16,6 @@ import ( "bytes" "context" "fmt" - "io/ioutil" "os" "os/exec" "path/filepath" @@ -639,12 +638,12 @@ func (fs *FS) deviceRescan(ctx context.Context, } func (fs *FS) consistentRead(filename string, retry int) ([]byte, error) { - oldContent, err := ioutil.ReadFile(filepath.Clean(filename)) + oldContent, err := os.ReadFile(filepath.Clean(filename)) if err != nil { return nil, err } for i := 0; i < retry; i++ { - newContent, err := ioutil.ReadFile(filepath.Clean(filename)) + newContent, err := os.ReadFile(filepath.Clean(filename)) if err != nil { return nil, err } diff --git a/gofsutil_mount_test.go b/gofsutil_mount_test.go index dca1af6..3d4dad6 100644 --- a/gofsutil_mount_test.go +++ b/gofsutil_mount_test.go @@ -14,7 +14,6 @@ package gofsutil_test import ( "context" - "io/ioutil" "os" "testing" @@ -22,11 +21,11 @@ import ( ) func TestBindMount(t *testing.T) { - src, err := ioutil.TempDir("", "") + src, err := os.MkdirTemp("", "") if err != nil { t.Fatal(err) } - tgt, err := ioutil.TempDir("", "") + tgt, err := os.MkdirTemp("", "") if err != nil { os.RemoveAll(src) t.Fatal(err) diff --git a/gofsutil_mount_unix.go b/gofsutil_mount_unix.go index 0d15529..2fdbbd1 100644 --- a/gofsutil_mount_unix.go +++ b/gofsutil_mount_unix.go @@ -18,7 +18,6 @@ package gofsutil import ( "context" "fmt" - "io/ioutil" "os" "os/exec" "path/filepath" @@ -232,7 +231,7 @@ func (fs *FS) wwnToDevicePath( func (fs *FS) targetIPLUNToDevicePath(ctx context.Context, targetIP string, lunID int) (map[string]string, error) { result := make(map[string]string, 0) bypathdir := "/dev/disk/by-path" - entries, err := ioutil.ReadDir(bypathdir) + entries, err := os.ReadDir(bypathdir) if err != nil { log.Printf("/dev/disk/by-path not found: %s", err.Error()) return result, err @@ -335,7 +334,7 @@ func (fs *FS) rescanSCSIHost(ctx context.Context, targets []string, lun string) // Fallback... we didn't find any target devices... so rescan all the hosts // Gather up the host devices. log.Printf("No targeted devices found... rescanning all the hosts") - hosts, err := ioutil.ReadDir(hostsdir) + hosts, err := os.ReadDir(hostsdir) if err != nil { log.WithField("error", err).Error("Cannot read directory: " + hostsdir) return err @@ -379,7 +378,7 @@ func getFCTargetHosts(targets []string) ([]*targetdev, error) { } // Read the directory entries for fc_remote_ports fcRemotePortsDir := "/sys/class/fc_remote_ports" - remotePortEntries, err := ioutil.ReadDir(fcRemotePortsDir) + remotePortEntries, err := os.ReadDir(fcRemotePortsDir) if err != nil { log.WithField("error", err).Error("Cannot read directory: " + fcRemotePortsDir) } @@ -395,7 +394,7 @@ func getFCTargetHosts(targets []string) ([]*targetdev, error) { continue } - arrayPortNameBytes, err := ioutil.ReadFile(fcRemotePortsDir + "/" + remotePort.Name() + "/" + "port_name") + arrayPortNameBytes, err := os.ReadFile(fcRemotePortsDir + "/" + remotePort.Name() + "/" + "port_name") if err != nil { continue } @@ -434,7 +433,7 @@ func getIscsiTargetHosts(targets []string) ([]*targetdev, error) { } // Read the sessions. sessionsdir := "/sys/class/iscsi_session" - sessions, err := ioutil.ReadDir(sessionsdir) + sessions, err := os.ReadDir(sessionsdir) if err != nil { log.WithField("error", err).Error("Cannot read directory: " + sessionsdir) return targetDev, err @@ -446,7 +445,7 @@ func getIscsiTargetHosts(targets []string) ([]*targetdev, error) { } log.Debug("Processing iscsi_session: " + session.Name()) if len(targets) > 0 { - targetBytes, err := ioutil.ReadFile(sessionsdir + "/" + session.Name() + "/" + "targetname") + targetBytes, err := os.ReadFile(sessionsdir + "/" + session.Name() + "/" + "targetname") if err != nil { continue } @@ -463,7 +462,7 @@ func getIscsiTargetHosts(targets []string) ([]*targetdev, error) { } // Read device/target entry to get the data for rescan. devicedir := sessionsdir + "/" + session.Name() + "/" + "device" - devices, err := ioutil.ReadDir(devicedir) + devices, err := os.ReadDir(devicedir) if err != nil { log.WithField("error", err).Error("Cannot read directory: " + devicedir) continue @@ -514,7 +513,7 @@ func (fs *FS) removeBlockDevice(ctx context.Context, blockDevicePath string) err if len(devicePathComponents) > 1 { deviceName := devicePathComponents[len(devicePathComponents)-1] statePath := fmt.Sprintf("/sys/block/%s/device/state", deviceName) - stateBytes, err := ioutil.ReadFile(filepath.Clean(statePath)) + stateBytes, err := os.ReadFile(filepath.Clean(statePath)) if err != nil { return fmt.Errorf("Cannot read %s: %s", statePath, err) } @@ -583,7 +582,7 @@ func (fs *FS) getFCHostPortWWNs(ctx context.Context) ([]string, error) { portWWNs := make([]string, 0) // Read the directory entries for fc_remote_ports fcHostsDir := "/sys/class/fc_host" - hostEntries, err := ioutil.ReadDir(fcHostsDir) + hostEntries, err := os.ReadDir(fcHostsDir) if err != nil { log.WithField("error", err).Error("Cannot read directory: " + fcHostsDir) return portWWNs, err @@ -595,7 +594,7 @@ func (fs *FS) getFCHostPortWWNs(ctx context.Context) ([]string, error) { continue } - hostPortNameBytes, err := ioutil.ReadFile(fcHostsDir + "/" + host.Name() + "/" + "port_name") + hostPortNameBytes, err := os.ReadFile(fcHostsDir + "/" + host.Name() + "/" + "port_name") if err != nil { continue } @@ -610,7 +609,7 @@ func (fs *FS) issueLIPToAllFCHosts(ctx context.Context) error { var savedError error // Read the directory entries for fc_remote_ports fcHostsDir := "/sys/class/fc_host" - fcHostEntries, err := ioutil.ReadDir(fcHostsDir) + fcHostEntries, err := os.ReadDir(fcHostsDir) if err != nil { log.WithField("error", err).Error("Cannot read directory: " + fcHostsDir) } @@ -646,7 +645,7 @@ func (fs *FS) getSysBlockDevicesForVolumeWWN(ctx context.Context, volumeWWN stri start := time.Now() result := make([]string, 0) sysBlockDir := "/sys/block" - sysBlocks, err := ioutil.ReadDir(sysBlockDir) + sysBlocks, err := os.ReadDir(sysBlockDir) if err != nil { return result, fmt.Errorf("Error reading %s: %s", sysBlockDir, err) } @@ -656,7 +655,7 @@ func (fs *FS) getSysBlockDevicesForVolumeWWN(ctx context.Context, volumeWWN stri continue } wwidPath := sysBlockDir + "/" + name + "/device/wwid" - bytes, err := ioutil.ReadFile(filepath.Clean(wwidPath)) + bytes, err := os.ReadFile(filepath.Clean(wwidPath)) if err != nil { continue } diff --git a/gofsutil_unix_test.go b/gofsutil_unix_test.go index 029770a..2254d12 100644 --- a/gofsutil_unix_test.go +++ b/gofsutil_unix_test.go @@ -18,7 +18,6 @@ package gofsutil_test import ( "context" "fmt" - "io/ioutil" "os" "strings" "testing" @@ -30,7 +29,7 @@ func TestFCRescanSCSIHost(t *testing.T) { var targets []string // Scan the remote ports to find the array port WWNs fcRemotePortsDir := "/sys/class/fc_remote_ports" - remotePortEntries, err := ioutil.ReadDir(fcRemotePortsDir) + remotePortEntries, err := os.ReadDir(fcRemotePortsDir) if err != nil { t.Errorf("error reading %s: %s", fcRemotePortsDir, err) } @@ -43,7 +42,7 @@ func TestFCRescanSCSIHost(t *testing.T) { continue } - arrayPortNameBytes, err := ioutil.ReadFile(fcRemotePortsDir + "/" + remotePort.Name() + "/" + "port_name") + arrayPortNameBytes, err := os.ReadFile(fcRemotePortsDir + "/" + remotePort.Name() + "/" + "port_name") if err != nil { continue }