Skip to content

Commit

Permalink
Merge pull request #27 from dell/updating-packages
Browse files Browse the repository at this point in the history
Updating gofsutil deprecated packages
  • Loading branch information
PeresKereotubo authored Aug 22, 2023
2 parents b9a2646 + d22a427 commit 6df3480
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 24 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/dell/gofsutil

go 1.20
go 1.21

require (
github.com/sirupsen/logrus v1.8.1
Expand Down
5 changes: 2 additions & 3 deletions gofsutil_mount_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
"bytes"
"context"
"fmt"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
Expand Down Expand Up @@ -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
}
Expand Down
5 changes: 2 additions & 3 deletions gofsutil_mount_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,18 @@ package gofsutil_test

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

"github.com/dell/gofsutil"
)

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)
Expand Down
27 changes: 13 additions & 14 deletions gofsutil_mount_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package gofsutil
import (
"context"
"fmt"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
Expand All @@ -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
}
Expand Down Expand Up @@ -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
Expand All @@ -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
}
Expand All @@ -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
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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
Expand All @@ -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
}
Expand All @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand All @@ -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
}
Expand Down
5 changes: 2 additions & 3 deletions gofsutil_unix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package gofsutil_test
import (
"context"
"fmt"
"io/ioutil"
"os"
"strings"
"testing"
Expand All @@ -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)
}
Expand All @@ -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
}
Expand Down

0 comments on commit 6df3480

Please sign in to comment.