From b5d72fb393472feabd6ecc9c091c4cb2e009fc9d Mon Sep 17 00:00:00 2001 From: Jonathon Anderson Date: Sat, 10 May 2025 11:26:11 -0600 Subject: [PATCH] Address unhandled deadcode issues - Fix `make deadcode` to properly fail GitHub checks - Resolve "dead" code by refactoring other code to use it Signed-off-by: Jonathon Anderson --- Makefile | 2 +- go.mod | 1 - go.sum | 2 -- internal/pkg/api/image/image.go | 10 ++-------- 4 files changed, 3 insertions(+), 12 deletions(-) diff --git a/Makefile b/Makefile index 11563960..c61d612f 100644 --- a/Makefile +++ b/Makefile @@ -96,7 +96,7 @@ staticcheck: $(GOLANG_STATICCHECK) $(config) ## Run static code check .PHONY: deadcode deadcode: $(config) ## Check for unused code - $(GOLANG_DEADCODE) -test ./... + test $$($(GOLANG_DEADCODE) -test ./... | tee /dev/stderr | wc -l) = 0 .PHONY: vet vet: $(config) ## Check for invalid code diff --git a/go.mod b/go.mod index a7f17050..cb11d7f3 100644 --- a/go.mod +++ b/go.mod @@ -17,7 +17,6 @@ require ( github.com/creasty/defaults v1.8.0 github.com/fatih/color v1.18.0 github.com/go-chi/chi/v5 v5.2.1 - github.com/golang/glog v1.2.4 github.com/google/uuid v1.6.0 github.com/grpc-ecosystem/grpc-gateway/v2 v2.26.1 github.com/hashicorp/go-version v1.7.0 diff --git a/go.sum b/go.sum index 7e7fc110..7284a028 100644 --- a/go.sum +++ b/go.sum @@ -160,8 +160,6 @@ github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5x github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= -github.com/golang/glog v1.2.4 h1:CNNw5U8lSiiBk7druxtSHHTsRWcxKoac6kZKm2peBBc= -github.com/golang/glog v1.2.4/go.mod h1:6AhwSGph0fcJtXVM/PEHPqZlFeoLxhs7/t5UDAwmO+w= github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= diff --git a/internal/pkg/api/image/image.go b/internal/pkg/api/image/image.go index a55588d4..d1c6be96 100644 --- a/internal/pkg/api/image/image.go +++ b/internal/pkg/api/image/image.go @@ -230,14 +230,8 @@ func ImageList() (imageInfo []*wwapiv1.ImageInfo, err error) { if err == nil { modTime = uint64(imageStat.ModTime().Unix()) } - imgSize := 0 - if imgF, err := os.Stat(image.ImageFile(source)); err == nil { - imgSize = int(imgF.Size()) - } - imgCSize := 0 - if imgFC, err := os.Stat(image.ImageFile(source) + ".gz"); err == nil { - imgCSize = int(imgFC.Size()) - } + imgSize := image.ImageSize(source) + imgCSize := image.CompressedImageSize(source) imageInfo = append(imageInfo, &wwapiv1.ImageInfo{ Name: source, NodeCount: uint32(nodemap[source]),