From 96d802bc2ca60577fa9e418309f1e06ae514bf9b Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Sat, 6 Jul 2024 02:37:48 +0000 Subject: [PATCH] fix(deps): update patch digest dependencies --- go.mod | 4 +-- go.sum | 4 +-- .../longhorn/go-common-libs/io/file.go | 32 ++++++++++++++++--- vendor/modules.txt | 2 +- 4 files changed, 33 insertions(+), 9 deletions(-) diff --git a/go.mod b/go.mod index a04d6b7..248665a 100644 --- a/go.mod +++ b/go.mod @@ -2,10 +2,10 @@ module github.com/longhorn/go-iscsi-helper go 1.22.0 -toolchain go1.22.4 +toolchain go1.22.5 require ( - github.com/longhorn/go-common-libs v0.0.0-20240627075631-d78642cff5e1 + github.com/longhorn/go-common-libs v0.0.0-20240702014532-ad3e7f0caf5c github.com/pkg/errors v0.9.1 github.com/sirupsen/logrus v1.9.3 golang.org/x/sys v0.21.0 diff --git a/go.sum b/go.sum index 046156a..91cb8d4 100644 --- a/go.sum +++ b/go.sum @@ -15,8 +15,8 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= 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-20240627075631-d78642cff5e1 h1:VGSNK9AEL6r9UocxZ0LoFPv1mn/jcstEc3LDS3GedZk= -github.com/longhorn/go-common-libs v0.0.0-20240627075631-d78642cff5e1/go.mod h1:wpLEAlsDCnqBA7QfZg0gxYeR8MmLbWHbdidWYwnRbyM= +github.com/longhorn/go-common-libs v0.0.0-20240702014532-ad3e7f0caf5c h1:DQvBkqE7Ge3/8kIHMujCVQzDoROgFS7TOPwyShfuLBA= +github.com/longhorn/go-common-libs v0.0.0-20240702014532-ad3e7f0caf5c/go.mod h1:wpLEAlsDCnqBA7QfZg0gxYeR8MmLbWHbdidWYwnRbyM= 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/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= 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 9bd9d4c..d4ad1c0 100644 --- a/vendor/github.com/longhorn/go-common-libs/io/file.go +++ b/vendor/github.com/longhorn/go-common-libs/io/file.go @@ -327,7 +327,8 @@ func IsDirectoryEmpty(directory string) (bool, error) { return false, nil } -// CheckIsFileSizeSame verifies if all files in the provided paths have the same size. +// CheckIsFileSizeSame verifies if all files in the provided paths have the same +// apparent and actual size. // It returns an error if any file is a directory, does not exist, or has a different size. func CheckIsFileSizeSame(paths ...string) error { referenceInfo, err := os.Stat(paths[0]) @@ -339,7 +340,12 @@ func CheckIsFileSizeSame(paths ...string) error { return errors.Errorf("file %v is a directory", paths[0]) } - referenceSize := referenceInfo.Size() + referenceApparentSize := referenceInfo.Size() + + referenceActualSize, err := getFileBlockSizeEstimate(paths[0]) + if err != nil { + return err + } for _, path := range paths { fileInfo, err := os.Stat(path) @@ -352,10 +358,28 @@ func CheckIsFileSizeSame(paths ...string) error { } - if fileInfo.Size() != referenceSize { - return errors.Errorf("file %v size %v is not equal to %v", path, fileInfo.Size(), referenceSize) + if fileInfo.Size() != referenceApparentSize { + return errors.Errorf("file %v apparent size %v is not equal to %v", path, fileInfo.Size(), referenceApparentSize) + } + + actualSize, err := getFileBlockSizeEstimate(path) + if err != nil { + return err + } + + if actualSize != referenceActualSize { + return errors.Errorf("file %v actual size %v is not equal to %v", path, actualSize, referenceActualSize) } } return nil } + +func getFileBlockSizeEstimate(path string) (uint64, error) { + var stat syscall.Stat_t + if err := syscall.Stat(path, &stat); err != nil { + return 0, err + } + + return uint64(stat.Blocks) * uint64(stat.Blksize), nil +} diff --git a/vendor/modules.txt b/vendor/modules.txt index dfe2611..041b014 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -14,7 +14,7 @@ github.com/kr/pretty # github.com/kr/text v0.2.0 ## explicit github.com/kr/text -# github.com/longhorn/go-common-libs v0.0.0-20240627075631-d78642cff5e1 +# github.com/longhorn/go-common-libs v0.0.0-20240702014532-ad3e7f0caf5c ## explicit; go 1.22.0 github.com/longhorn/go-common-libs/exec github.com/longhorn/go-common-libs/io