From 717dcb56db04e49d641a3971b3395b156eaa8404 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Tue, 25 Jun 2024 05:06:32 +0000 Subject: [PATCH] fix(deps): update patch digest dependencies --- go.mod | 6 +- go.sum | 8 +- .../longhorn/go-common-libs/io/file.go | 89 ++++++++++++++++++- .../go-common-libs/utils/longhorn_naming.go | 11 --- .../longhorn/go-common-libs/utils/misc.go | 20 +++++ .../longhorn/go-common-libs/utils/mount.go | 14 --- vendor/modules.txt | 6 +- 7 files changed, 117 insertions(+), 37 deletions(-) delete mode 100644 vendor/github.com/longhorn/go-common-libs/utils/longhorn_naming.go delete mode 100644 vendor/github.com/longhorn/go-common-libs/utils/mount.go diff --git a/go.mod b/go.mod index f1c4f7b7..e33ffc7c 100644 --- a/go.mod +++ b/go.mod @@ -46,8 +46,8 @@ replace ( require ( github.com/google/fscrypt v0.3.5 - github.com/longhorn/go-common-libs v0.0.0-20240616051056-103c7d62a0d5 - github.com/longhorn/types v0.0.0-20240612122407-553c71ad6514 + github.com/longhorn/go-common-libs v0.0.0-20240623073303-1d8b9c5efb84 + github.com/longhorn/types v0.0.0-20240624083620-f11ba48bf396 github.com/mitchellh/go-ps v1.0.0 github.com/pkg/errors v0.9.1 github.com/sirupsen/logrus v1.9.3 @@ -76,6 +76,6 @@ require ( github.com/yusufpapurcu/wmi v1.2.4 // indirect golang.org/x/text v0.16.0 // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20240318140521-94a12d6c2237 // indirect - k8s.io/apimachinery v0.0.0 // indirect + k8s.io/apimachinery v0.28.5 // indirect k8s.io/klog/v2 v2.120.1 // indirect ) diff --git a/go.sum b/go.sum index 665e53ea..e29543ed 100644 --- a/go.sum +++ b/go.sum @@ -24,10 +24,10 @@ github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= -github.com/longhorn/go-common-libs v0.0.0-20240616051056-103c7d62a0d5 h1:Ljroa7ftGJQsu38xoUlRVqZpfpkoIdrpzLM2/Qov/Vw= -github.com/longhorn/go-common-libs v0.0.0-20240616051056-103c7d62a0d5/go.mod h1:f4+Aeju9AmWPDfy7t2n0bv0Zyte8Hhs6ZhWFVf2BfWU= -github.com/longhorn/types v0.0.0-20240612122407-553c71ad6514 h1:IUAe0Lw2Wz5GrUznw6Sp65qA8J0tWi9qVIIuFZZF5O0= -github.com/longhorn/types v0.0.0-20240612122407-553c71ad6514/go.mod h1:fonrC6SwGpvt+YVlfJ3xMmg0MlOH94T1Qx2+ZEy8n3U= +github.com/longhorn/go-common-libs v0.0.0-20240623073303-1d8b9c5efb84 h1:Xs/R238l7vkix/zu5XfLHmzMWwkN985j9I5msJ1DmgA= +github.com/longhorn/go-common-libs v0.0.0-20240623073303-1d8b9c5efb84/go.mod h1:g9PDfwta/vyRjIadpborYon3OR3c58Dz6zEjHksw6Tk= +github.com/longhorn/types v0.0.0-20240624083620-f11ba48bf396 h1:dvrppUjQ5i9wPOuU1qnanksHe82cSaNckGaWzn3f8QY= +github.com/longhorn/types v0.0.0-20240624083620-f11ba48bf396/go.mod h1:fonrC6SwGpvt+YVlfJ3xMmg0MlOH94T1Qx2+ZEy8n3U= github.com/mitchellh/go-ps v1.0.0 h1:i6ampVEEF4wQFF+bkYfwYgY+F/uYJDktmvLPf7qIgjc= github.com/mitchellh/go-ps v1.0.0/go.mod h1:J4lOc8z8yJs6vUwklHw2XEIiT4z4C40KtWVN3nvg8Pg= github.com/moby/sys/mountinfo v0.6.2 h1:BzJjoreD5BMFNmD9Rus6gdd1pLuecOFPt8wC+Vygl78= diff --git a/vendor/github.com/longhorn/go-common-libs/io/file.go b/vendor/github.com/longhorn/go-common-libs/io/file.go index 945be4d7..40e60a3d 100644 --- a/vendor/github.com/longhorn/go-common-libs/io/file.go +++ b/vendor/github.com/longhorn/go-common-libs/io/file.go @@ -5,6 +5,7 @@ import ( "io" "os" "path/filepath" + "strings" "syscall" "time" @@ -164,12 +165,29 @@ func GetEmptyFiles(directory string) (filePaths []string, err error) { // FindFiles searches for files in the specified directory with the given fileName. // If fileName is empty, it retrieves all files in the directory. +// If maxDepth is greater than 0, it limits the search to the specified depth. // It returns a slice of filePaths and an error if any. -func FindFiles(directory, fileName string) (filePaths []string, err error) { +func FindFiles(directory, fileName string, maxDepth int) (filePaths []string, err error) { err = filepath.Walk(directory, func(path string, info os.FileInfo, err error) error { if err != nil { - return err + // If the directory contains symbolic links, it might lead to a non-existing file error. + // Ignore this error and continue walking the directory. + logrus.WithError(err).Warn("Encountered error while searching for files") + return nil } + + // Calculate the depth of the directory + depth := strings.Count(strings.TrimPrefix(path, directory), string(os.PathSeparator)) + + // Skip the directory if it exceeds the maximum depth + if maxDepth > 0 && depth > maxDepth { + if info.IsDir() { + return filepath.SkipDir // Skip this directory + } + + return nil // Skip this file + } + if fileName == "" || info.Name() == fileName { filePaths = append(filePaths, path) } @@ -241,3 +259,70 @@ func GetDiskStat(path string) (diskStat types.DiskStat, err error) { StorageAvailable: int64(statfs.Bfree) * statfs.Bsize, }, nil } + +// ListOpenFiles returns a list of open files in the specified directory. +func ListOpenFiles(procDirectory, directory string) ([]string, error) { + // Check if the specified directory exists + if _, err := os.Stat(directory); err != nil { + return nil, err + } + + // Get the list of all processes in the provided procDirectory + procs, err := os.ReadDir(procDirectory) + if err != nil { + return nil, err + } + + // Iterate over each process in the procDirectory + var openedFiles []string + for _, proc := range procs { + // Skip non-directory entries + if !proc.IsDir() { + continue + } + + // Read the file descriptor directory for the process + pid := proc.Name() + fdDir := filepath.Join(procDirectory, pid, "fd") + files, err := os.ReadDir(fdDir) + if err != nil { + logrus.WithError(err).Tracef("Failed to read file descriptors for process %v", pid) + continue + } + + // Iterate over each file in the file descriptor directory + for _, file := range files { + filePath, err := os.Readlink(filepath.Join(fdDir, file.Name())) + if err != nil { + logrus.WithError(err).Tracef("Failed to read link for file descriptor %v", file.Name()) + continue + } + + // Check if the file path is within the specified directory + if strings.HasPrefix(filePath, directory+"/") || filePath == directory { + openedFiles = append(openedFiles, filePath) + } + } + } + + return openedFiles, nil +} + +// IsDirectoryEmpty returns true if the specified directory is empty. +func IsDirectoryEmpty(directory string) (bool, error) { + f, err := os.Open(directory) + if err != nil { + return false, err + } + defer f.Close() + + _, err = f.Readdirnames(1) + if err == io.EOF { + return true, nil + } + if err != nil { + return false, err + } + + return false, nil +} diff --git a/vendor/github.com/longhorn/go-common-libs/utils/longhorn_naming.go b/vendor/github.com/longhorn/go-common-libs/utils/longhorn_naming.go deleted file mode 100644 index 5db2d4b4..00000000 --- a/vendor/github.com/longhorn/go-common-libs/utils/longhorn_naming.go +++ /dev/null @@ -1,11 +0,0 @@ -package utils - -import ( - "regexp" -) - -// IsEngineProcess distinguish if the process is a engine process by its name. -func IsEngineProcess(processName string) bool { - // engine process name example: pvc-5a8ee916-5989-46c6-bafc-ddbf7c802499-e-0 - return regexp.MustCompile(`.+?-e-[^-]*\d$`).MatchString(processName) -} diff --git a/vendor/github.com/longhorn/go-common-libs/utils/misc.go b/vendor/github.com/longhorn/go-common-libs/utils/misc.go index 8485c679..69aced9c 100644 --- a/vendor/github.com/longhorn/go-common-libs/utils/misc.go +++ b/vendor/github.com/longhorn/go-common-libs/utils/misc.go @@ -2,10 +2,12 @@ package utils import ( "crypto/rand" + "fmt" "math/big" "path/filepath" "reflect" "runtime" + "strconv" "strings" "github.com/google/uuid" @@ -99,3 +101,21 @@ func GenerateRandomNumber(lower, upper int64) (int64, error) { } return (lower + randNum.Int64()), nil } + +// ConvertTypeToString converts the given value to string. +func ConvertTypeToString[T any](value T) string { + v := reflect.ValueOf(value) + + switch v.Kind() { + case reflect.String: + return v.String() + case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: + return strconv.FormatInt(v.Int(), 10) + case reflect.Float32, reflect.Float64: + return strconv.FormatFloat(v.Float(), 'f', -1, 64) + case reflect.Bool: + return strconv.FormatBool(v.Bool()) + default: + return fmt.Sprintf("Unsupported type: %v", v.Kind()) + } +} diff --git a/vendor/github.com/longhorn/go-common-libs/utils/mount.go b/vendor/github.com/longhorn/go-common-libs/utils/mount.go deleted file mode 100644 index f234ae1a..00000000 --- a/vendor/github.com/longhorn/go-common-libs/utils/mount.go +++ /dev/null @@ -1,14 +0,0 @@ -package utils - -import ( - "k8s.io/mount-utils" -) - -func IsMountPointReadOnly(mp mount.MountPoint) bool { - for _, opt := range mp.Opts { - if opt == "ro" { - return true - } - } - return false -} diff --git a/vendor/modules.txt b/vendor/modules.txt index 7723fc91..8c188322 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -22,7 +22,7 @@ github.com/google/fscrypt/util # github.com/google/uuid v1.6.0 ## explicit github.com/google/uuid -# github.com/longhorn/go-common-libs v0.0.0-20240616051056-103c7d62a0d5 +# github.com/longhorn/go-common-libs v0.0.0-20240623073303-1d8b9c5efb84 ## explicit; go 1.22.0 github.com/longhorn/go-common-libs/exec github.com/longhorn/go-common-libs/io @@ -32,7 +32,7 @@ github.com/longhorn/go-common-libs/sync github.com/longhorn/go-common-libs/sys github.com/longhorn/go-common-libs/types github.com/longhorn/go-common-libs/utils -# github.com/longhorn/types v0.0.0-20240612122407-553c71ad6514 +# github.com/longhorn/types v0.0.0-20240624083620-f11ba48bf396 ## explicit; go 1.21 github.com/longhorn/types/pkg/generated/smrpc # github.com/mitchellh/go-ps v1.0.0 @@ -188,7 +188,7 @@ google.golang.org/protobuf/types/known/anypb google.golang.org/protobuf/types/known/durationpb google.golang.org/protobuf/types/known/emptypb google.golang.org/protobuf/types/known/timestamppb -# k8s.io/apimachinery v0.0.0 => k8s.io/apimachinery v0.30.2 +# k8s.io/apimachinery v0.28.5 => k8s.io/apimachinery v0.30.2 ## explicit; go 1.22.0 k8s.io/apimachinery/pkg/util/runtime k8s.io/apimachinery/pkg/util/wait