aboutsummaryrefslogtreecommitdiff
path: root/weed/storage/disk_location.go
diff options
context:
space:
mode:
authorEng Zer Jun <engzerjun@gmail.com>2021-10-14 12:27:58 +0800
committerEng Zer Jun <engzerjun@gmail.com>2021-10-14 12:27:58 +0800
commita23bcbb7ecf93fcda35976f4f2fb42a67830e718 (patch)
tree3227e82e51346dad8649a17e991c9cf561ef8071 /weed/storage/disk_location.go
parent4cbd390fbe634e2370c36a61b1574e9d648c3cee (diff)
downloadseaweedfs-a23bcbb7ecf93fcda35976f4f2fb42a67830e718.tar.xz
seaweedfs-a23bcbb7ecf93fcda35976f4f2fb42a67830e718.zip
refactor: move from io/ioutil to io and os package
The io/ioutil package has been deprecated as of Go 1.16, see https://golang.org/doc/go1.16#ioutil. This commit replaces the existing io/ioutil functions with their new definitions in io and os packages. Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
Diffstat (limited to 'weed/storage/disk_location.go')
-rw-r--r--weed/storage/disk_location.go31
1 files changed, 15 insertions, 16 deletions
diff --git a/weed/storage/disk_location.go b/weed/storage/disk_location.go
index c6fceb2c2..a32a0093d 100644
--- a/weed/storage/disk_location.go
+++ b/weed/storage/disk_location.go
@@ -2,8 +2,6 @@ package storage
import (
"fmt"
- "github.com/chrislusf/seaweedfs/weed/storage/types"
- "io/ioutil"
"os"
"path/filepath"
"strings"
@@ -14,6 +12,7 @@ import (
"github.com/chrislusf/seaweedfs/weed/stats"
"github.com/chrislusf/seaweedfs/weed/storage/erasure_coding"
"github.com/chrislusf/seaweedfs/weed/storage/needle"
+ "github.com/chrislusf/seaweedfs/weed/storage/types"
"github.com/chrislusf/seaweedfs/weed/util"
)
@@ -85,9 +84,9 @@ func getValidVolumeName(basename string) string {
return ""
}
-func (l *DiskLocation) loadExistingVolume(fileInfo os.FileInfo, needleMapKind NeedleMapKind) bool {
- basename := fileInfo.Name()
- if fileInfo.IsDir() {
+func (l *DiskLocation) loadExistingVolume(dirEntry os.DirEntry, needleMapKind NeedleMapKind) bool {
+ basename := dirEntry.Name()
+ if dirEntry.IsDir() {
return false
}
volumeName := getValidVolumeName(basename)
@@ -103,7 +102,7 @@ func (l *DiskLocation) loadExistingVolume(fileInfo os.FileInfo, needleMapKind Ne
// check for incomplete volume
noteFile := l.Directory + "/" + volumeName + ".note"
if util.FileExists(noteFile) {
- note, _ := ioutil.ReadFile(noteFile)
+ note, _ := os.ReadFile(noteFile)
glog.Warningf("volume %s was not completed: %s", volumeName, string(note))
removeVolumeFiles(l.Directory + "/" + volumeName)
removeVolumeFiles(l.IdxDirectory + "/" + volumeName)
@@ -143,18 +142,18 @@ func (l *DiskLocation) loadExistingVolume(fileInfo os.FileInfo, needleMapKind Ne
func (l *DiskLocation) concurrentLoadingVolumes(needleMapKind NeedleMapKind, concurrency int) {
- task_queue := make(chan os.FileInfo, 10*concurrency)
+ task_queue := make(chan os.DirEntry, 10*concurrency)
go func() {
foundVolumeNames := make(map[string]bool)
- if fileInfos, err := ioutil.ReadDir(l.Directory); err == nil {
- for _, fi := range fileInfos {
- volumeName := getValidVolumeName(fi.Name())
+ if dirEntries, err := os.ReadDir(l.Directory); err == nil {
+ for _, entry := range dirEntries {
+ volumeName := getValidVolumeName(entry.Name())
if volumeName == "" {
continue
}
if _, found := foundVolumeNames[volumeName]; !found {
foundVolumeNames[volumeName] = true
- task_queue <- fi
+ task_queue <- entry
}
}
}
@@ -332,12 +331,12 @@ func (l *DiskLocation) Close() {
return
}
-func (l *DiskLocation) LocateVolume(vid needle.VolumeId) (os.FileInfo, bool) {
- if fileInfos, err := ioutil.ReadDir(l.Directory); err == nil {
- for _, fileInfo := range fileInfos {
- volId, _, err := volumeIdFromFileName(fileInfo.Name())
+func (l *DiskLocation) LocateVolume(vid needle.VolumeId) (os.DirEntry, bool) {
+ if dirEntries, err := os.ReadDir(l.Directory); err == nil {
+ for _, entry := range dirEntries {
+ volId, _, err := volumeIdFromFileName(entry.Name())
if vid == volId && err == nil {
- return fileInfo, true
+ return entry, true
}
}
}