aboutsummaryrefslogtreecommitdiff
path: root/pkg
diff options
context:
space:
mode:
Diffstat (limited to 'pkg')
-rw-r--r--pkg/bindings/images/build.go23
-rw-r--r--pkg/domain/infra/abi/system.go22
-rw-r--r--pkg/machine/ignition.go5
-rw-r--r--pkg/machine/qemu/machine.go6
-rw-r--r--pkg/machine/wsl/machine.go7
-rw-r--r--pkg/specgen/generate/config_linux.go5
-rw-r--r--pkg/util/utils.go18
-rw-r--r--pkg/util/utils_linux.go9
8 files changed, 60 insertions, 35 deletions
diff --git a/pkg/bindings/images/build.go b/pkg/bindings/images/build.go
index e1b427742..f6739b7ca 100644
--- a/pkg/bindings/images/build.go
+++ b/pkg/bindings/images/build.go
@@ -7,6 +7,7 @@ import (
"encoding/json"
"fmt"
"io"
+ "io/fs"
"io/ioutil"
"net/http"
"net/url"
@@ -557,14 +558,14 @@ func nTar(excludes []string, sources ...string) (io.ReadCloser, error) {
merr = multierror.Append(merr, err)
return
}
- err = filepath.Walk(s, func(path string, info os.FileInfo, err error) error {
+ err = filepath.WalkDir(s, func(path string, d fs.DirEntry, err error) error {
if err != nil {
return err
}
// check if what we are given is an empty dir, if so then continue w/ it. Else return.
// if we are given a file or a symlink, we do not want to exclude it.
- if info.IsDir() && s == path {
+ if d.IsDir() && s == path {
var p *os.File
p, err = os.Open(path)
if err != nil {
@@ -588,7 +589,11 @@ func nTar(excludes []string, sources ...string) (io.ReadCloser, error) {
return nil
}
- if info.Mode().IsRegular() { // add file item
+ if d.Type().IsRegular() { // add file item
+ info, err := d.Info()
+ if err != nil {
+ return err
+ }
di, isHardLink := checkHardLink(info)
if err != nil {
return err
@@ -624,7 +629,11 @@ func nTar(excludes []string, sources ...string) (io.ReadCloser, error) {
seen[di] = name
}
return err
- } else if info.Mode().IsDir() { // add folders
+ } else if d.IsDir() { // add folders
+ info, err := d.Info()
+ if err != nil {
+ return err
+ }
hdr, lerr := tar.FileInfoHeader(info, name)
if lerr != nil {
return lerr
@@ -634,11 +643,15 @@ func nTar(excludes []string, sources ...string) (io.ReadCloser, error) {
if lerr := tw.WriteHeader(hdr); lerr != nil {
return lerr
}
- } else if info.Mode()&os.ModeSymlink != 0 { // add symlinks as it, not content
+ } else if d.Type()&os.ModeSymlink != 0 { // add symlinks as it, not content
link, err := os.Readlink(path)
if err != nil {
return err
}
+ info, err := d.Info()
+ if err != nil {
+ return err
+ }
hdr, lerr := tar.FileInfoHeader(info, link)
if lerr != nil {
return lerr
diff --git a/pkg/domain/infra/abi/system.go b/pkg/domain/infra/abi/system.go
index d12d14c1f..4361821d5 100644
--- a/pkg/domain/infra/abi/system.go
+++ b/pkg/domain/infra/abi/system.go
@@ -6,7 +6,6 @@ import (
"net/url"
"os"
"os/exec"
- "path/filepath"
"github.com/containers/common/pkg/cgroups"
"github.com/containers/common/pkg/config"
@@ -269,7 +268,7 @@ func (ic *ContainerEngine) SystemDf(ctx context.Context, options entities.System
}
dfVolumes := make([]*entities.SystemDfVolumeReport, 0, len(vols))
- var reclaimableSize int64
+ var reclaimableSize uint64
for _, v := range vols {
var consInUse int
mountPoint, err := v.MountPoint()
@@ -282,7 +281,7 @@ func (ic *ContainerEngine) SystemDf(ctx context.Context, options entities.System
// TODO: fix this.
continue
}
- volSize, err := sizeOfPath(mountPoint)
+ volSize, err := util.SizeOfPath(mountPoint)
if err != nil {
return nil, err
}
@@ -301,8 +300,8 @@ func (ic *ContainerEngine) SystemDf(ctx context.Context, options entities.System
report := entities.SystemDfVolumeReport{
VolumeName: v.Name(),
Links: consInUse,
- Size: volSize,
- ReclaimableSize: reclaimableSize,
+ Size: int64(volSize),
+ ReclaimableSize: int64(reclaimableSize),
}
dfVolumes = append(dfVolumes, &report)
}
@@ -313,19 +312,6 @@ func (ic *ContainerEngine) SystemDf(ctx context.Context, options entities.System
}, nil
}
-// sizeOfPath determines the file usage of a given path. it was called volumeSize in v1
-// and now is made to be generic and take a path instead of a libpod volume
-func sizeOfPath(path string) (int64, error) {
- var size int64
- err := filepath.Walk(path, func(path string, info os.FileInfo, err error) error {
- if err == nil && !info.IsDir() {
- size += info.Size()
- }
- return err
- })
- return size, err
-}
-
func (se *SystemEngine) Reset(ctx context.Context) error {
return se.Libpod.Reset(ctx)
}
diff --git a/pkg/machine/ignition.go b/pkg/machine/ignition.go
index b2dabb689..fe47437e3 100644
--- a/pkg/machine/ignition.go
+++ b/pkg/machine/ignition.go
@@ -6,6 +6,7 @@ package machine
import (
"encoding/json"
"fmt"
+ "io/fs"
"io/ioutil"
"net/url"
"os"
@@ -507,8 +508,8 @@ func getCerts(certsDir string, isDir bool) []File {
)
if isDir {
- err := filepath.Walk(certsDir, func(path string, info os.FileInfo, err error) error {
- if err == nil && !info.IsDir() {
+ err := filepath.WalkDir(certsDir, func(path string, d fs.DirEntry, err error) error {
+ if err == nil && !d.IsDir() {
certPath, err := filepath.Rel(certsDir, path)
if err != nil {
logrus.Warnf("%s", err)
diff --git a/pkg/machine/qemu/machine.go b/pkg/machine/qemu/machine.go
index ffc90b2a0..f04625781 100644
--- a/pkg/machine/qemu/machine.go
+++ b/pkg/machine/qemu/machine.go
@@ -895,10 +895,10 @@ func GetVMInfos() ([]*machine.ListResponse, error) {
var listed []*machine.ListResponse
- if err = filepath.Walk(vmConfigDir, func(path string, info os.FileInfo, err error) error {
+ if err = filepath.WalkDir(vmConfigDir, func(path string, d fs.DirEntry, err error) error {
vm := new(MachineVM)
- if strings.HasSuffix(info.Name(), ".json") {
- fullPath := filepath.Join(vmConfigDir, info.Name())
+ if strings.HasSuffix(d.Name(), ".json") {
+ fullPath := filepath.Join(vmConfigDir, d.Name())
b, err := ioutil.ReadFile(fullPath)
if err != nil {
return err
diff --git a/pkg/machine/wsl/machine.go b/pkg/machine/wsl/machine.go
index 5b0c757f0..5128fa313 100644
--- a/pkg/machine/wsl/machine.go
+++ b/pkg/machine/wsl/machine.go
@@ -8,6 +8,7 @@ import (
"encoding/json"
"fmt"
"io"
+ "io/fs"
"io/ioutil"
"net/url"
"os"
@@ -1175,10 +1176,10 @@ func GetVMInfos() ([]*machine.ListResponse, error) {
var listed []*machine.ListResponse
- if err = filepath.Walk(vmConfigDir, func(path string, info os.FileInfo, err error) error {
+ if err = filepath.WalkDir(vmConfigDir, func(path string, d fs.DirEntry, err error) error {
vm := new(MachineVM)
- if strings.HasSuffix(info.Name(), ".json") {
- fullPath := filepath.Join(vmConfigDir, info.Name())
+ if strings.HasSuffix(d.Name(), ".json") {
+ fullPath := filepath.Join(vmConfigDir, d.Name())
b, err := ioutil.ReadFile(fullPath)
if err != nil {
return err
diff --git a/pkg/specgen/generate/config_linux.go b/pkg/specgen/generate/config_linux.go
index 35d7f0252..8f83fc09b 100644
--- a/pkg/specgen/generate/config_linux.go
+++ b/pkg/specgen/generate/config_linux.go
@@ -2,6 +2,7 @@ package generate
import (
"fmt"
+ "io/fs"
"io/ioutil"
"os"
"path"
@@ -101,8 +102,8 @@ func DevicesFromPath(g *generate.Generator, devicePath string) error {
}
// mount the internal devices recursively
- if err := filepath.Walk(resolvedDevicePath, func(dpath string, f os.FileInfo, e error) error {
- if f.Mode()&os.ModeDevice == os.ModeDevice {
+ if err := filepath.WalkDir(resolvedDevicePath, func(dpath string, d fs.DirEntry, e error) error {
+ if d.Type()&os.ModeDevice == os.ModeDevice {
found = true
device := fmt.Sprintf("%s:%s", dpath, filepath.Join(dest, strings.TrimPrefix(dpath, src)))
if devmode != "" {
diff --git a/pkg/util/utils.go b/pkg/util/utils.go
index 334a44a88..b89978601 100644
--- a/pkg/util/utils.go
+++ b/pkg/util/utils.go
@@ -3,6 +3,7 @@ package util
import (
"encoding/json"
"fmt"
+ "io/fs"
"math"
"os"
"os/user"
@@ -731,3 +732,20 @@ func LookupUser(name string) (*user.User, error) {
}
return user.Lookup(name)
}
+
+// SizeOfPath determines the file usage of a given path. it was called volumeSize in v1
+// and now is made to be generic and take a path instead of a libpod volume
+func SizeOfPath(path string) (uint64, error) {
+ var size uint64
+ err := filepath.WalkDir(path, func(path string, d fs.DirEntry, err error) error {
+ if err == nil && !d.IsDir() {
+ info, err := d.Info()
+ if err != nil {
+ return err
+ }
+ size += uint64(info.Size())
+ }
+ return err
+ })
+ return size, err
+}
diff --git a/pkg/util/utils_linux.go b/pkg/util/utils_linux.go
index 1cffab19d..0b21bf3c5 100644
--- a/pkg/util/utils_linux.go
+++ b/pkg/util/utils_linux.go
@@ -2,6 +2,7 @@ package util
import (
"fmt"
+ "io/fs"
"os"
"path/filepath"
"syscall"
@@ -23,17 +24,21 @@ func GetContainerPidInformationDescriptors() ([]string, error) {
// Symlinks to nodes are ignored.
func FindDeviceNodes() (map[string]string, error) {
nodes := make(map[string]string)
- err := filepath.Walk("/dev", func(path string, info os.FileInfo, err error) error {
+ err := filepath.WalkDir("/dev", func(path string, d fs.DirEntry, err error) error {
if err != nil {
logrus.Warnf("Error descending into path %s: %v", path, err)
return filepath.SkipDir
}
// If we aren't a device node, do nothing.
- if info.Mode()&(os.ModeDevice|os.ModeCharDevice) == 0 {
+ if d.Type()&(os.ModeDevice|os.ModeCharDevice) == 0 {
return nil
}
+ info, err := d.Info()
+ if err != nil {
+ return err
+ }
// We are a device node. Get major/minor.
sysstat, ok := info.Sys().(*syscall.Stat_t)
if !ok {