From 076874a155ad44d764d25081125f950e8194d023 Mon Sep 17 00:00:00 2001 From: Noel Georgi Date: Wed, 26 Apr 2023 14:55:11 +0530 Subject: [PATCH] chore: resolve blockdevice symlinks Resolve blockdevice symlinks before opening. Also rekres. Signed-off-by: Noel Georgi --- .drone.yml | 8 ++++++-- Dockerfile | 6 +++--- Makefile | 12 ++++++------ blockdevice/blkpg/blkpg_linux.go | 6 +----- blockdevice/blockdevice_linux.go | 6 ++++++ blockdevice/blockdevice_test.go | 2 +- blockdevice/probe/probe_test.go | 13 +++++++++++++ blockdevice/serde/serde_test.go | 2 +- 8 files changed, 37 insertions(+), 18 deletions(-) diff --git a/.drone.yml b/.drone.yml index 74b701d..b27d8f7 100644 --- a/.drone.yml +++ b/.drone.yml @@ -1,7 +1,7 @@ --- # THIS FILE WAS AUTOMATICALLY GENERATED, PLEASE DO NOT EDIT. # -# Generated on 2022-09-20T19:45:44Z by kres 255fc05. +# Generated on 2023-04-26T10:18:59Z by kres latest. kind: pipeline type: kubernetes @@ -174,7 +174,7 @@ steps: services: - name: docker - image: docker:20.10-dind + image: docker:23.0-dind entrypoint: - dockerd commands: @@ -212,6 +212,10 @@ trigger: exclude: - renovate/* - dependabot/* + event: + exclude: + - promote + - cron --- kind: pipeline diff --git a/Dockerfile b/Dockerfile index 81243fa..1c883e2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,8 +1,8 @@ -# syntax = docker/dockerfile-upstream:1.2.0-labs +# syntax = docker/dockerfile-upstream:1.5.2-labs # THIS FILE WAS AUTOMATICALLY GENERATED, PLEASE DO NOT EDIT. # -# Generated on 2023-02-13T11:37:21Z by kres latest. +# Generated on 2023-04-26T10:18:59Z by kres latest. ARG TOOLCHAIN @@ -10,7 +10,7 @@ ARG TOOLCHAIN FROM scratch AS generate # runs markdownlint -FROM docker.io/node:19.6.0-alpine3.16 AS lint-markdown +FROM docker.io/node:20.0.0-alpine3.16 AS lint-markdown WORKDIR /src RUN npm i -g markdownlint-cli@0.33.0 RUN npm i sentences-per-line@0.2.1 diff --git a/Makefile b/Makefile index 2090f4c..4343a1c 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ # THIS FILE WAS AUTOMATICALLY GENERATED, PLEASE DO NOT EDIT. # -# Generated on 2023-02-13T11:37:21Z by kres latest. +# Generated on 2023-04-26T10:18:59Z by kres latest. # common variables @@ -13,13 +13,13 @@ WITH_RACE ?= false REGISTRY ?= ghcr.io USERNAME ?= siderolabs REGISTRY_AND_USERNAME ?= $(REGISTRY)/$(USERNAME) -GOLANGCILINT_VERSION ?= v1.51.1 -GOFUMPT_VERSION ?= v0.4.0 +GOLANGCILINT_VERSION ?= v1.52.2 +GOFUMPT_VERSION ?= v0.5.0 GO_VERSION ?= 1.20 -GOIMPORTS_VERSION ?= v0.5.0 +GOIMPORTS_VERSION ?= v0.8.0 PROTOBUF_GO_VERSION ?= 1.28.1 -GRPC_GO_VERSION ?= 1.2.0 -GRPC_GATEWAY_VERSION ?= 2.15.0 +GRPC_GO_VERSION ?= 1.3.0 +GRPC_GATEWAY_VERSION ?= 2.15.2 VTPROTOBUF_VERSION ?= 0.4.0 DEEPCOPY_VERSION ?= v0.5.5 GO_BUILDFLAGS ?= diff --git a/blockdevice/blkpg/blkpg_linux.go b/blockdevice/blkpg/blkpg_linux.go index b574b25..28091e8 100644 --- a/blockdevice/blkpg/blkpg_linux.go +++ b/blockdevice/blkpg/blkpg_linux.go @@ -90,11 +90,7 @@ func inform(f *os.File, first, length uint64, n, op int32) error { } } - if err = f.Sync(); err != nil { - return err - } - - return nil + return f.Sync() }) if err != nil { diff --git a/blockdevice/blockdevice_linux.go b/blockdevice/blockdevice_linux.go index c045750..f568025 100644 --- a/blockdevice/blockdevice_linux.go +++ b/blockdevice/blockdevice_linux.go @@ -9,6 +9,7 @@ import ( "fmt" "io" "os" + "path/filepath" "syscall" "time" "unsafe" @@ -56,6 +57,11 @@ func Open(devname string, setters ...Option) (_ *BlockDevice, rerr error) { //no err error ) + devname, err = filepath.EvalSymlinks(devname) + if err != nil { + return nil, fmt.Errorf("error resolving device symlink: %w", err) + } + if f, err = os.OpenFile(devname, opts.Mode, os.ModeDevice); err != nil { return nil, err } diff --git a/blockdevice/blockdevice_test.go b/blockdevice/blockdevice_test.go index 1394e35..1fb3361 100644 --- a/blockdevice/blockdevice_test.go +++ b/blockdevice/blockdevice_test.go @@ -8,7 +8,7 @@ import ( "testing" ) -func TestEmpty(t *testing.T) { +func TestEmpty(_ *testing.T) { // added for accurate coverage estimation // // please remove it once any unit-test is added diff --git a/blockdevice/probe/probe_test.go b/blockdevice/probe/probe_test.go index 6294bac..054faab 100644 --- a/blockdevice/probe/probe_test.go +++ b/blockdevice/probe/probe_test.go @@ -14,6 +14,7 @@ import ( "github.com/stretchr/testify/suite" + "github.com/siderolabs/go-blockdevice/blockdevice" "github.com/siderolabs/go-blockdevice/blockdevice/partition/gpt" "github.com/siderolabs/go-blockdevice/blockdevice/probe" "github.com/siderolabs/go-blockdevice/blockdevice/test" @@ -66,6 +67,18 @@ func (suite *ProbeSuite) setSystemLabelEXT4(name string) { suite.Require().NoError(cmd.Run()) } +func (suite *ProbeSuite) TestBlockDeviceWithSymlinkResolves() { + // Create a symlink to the block device + symlink := suite.Dev.Name() + ".link" + suite.Require().NoError(os.Symlink(suite.Dev.Name(), symlink)) + + defer os.Remove(symlink) //nolint:errcheck + + bd, err := blockdevice.Open(symlink) + suite.Require().NoError(err) + suite.Require().Equal(suite.Dev.Name(), bd.Device().Name()) +} + func (suite *ProbeSuite) TestDevForPartitionLabel() { part12 := suite.addPartition("devpart12", 1024*1024, 12) part32 := suite.addPartition("devpart32", 1024*1024*256, 32) diff --git a/blockdevice/serde/serde_test.go b/blockdevice/serde/serde_test.go index 6a52e7e..9f90f26 100644 --- a/blockdevice/serde/serde_test.go +++ b/blockdevice/serde/serde_test.go @@ -6,7 +6,7 @@ package serde_test import "testing" -func TestEmpty(t *testing.T) { +func TestEmpty(_ *testing.T) { // added for accurate coverage estimation // // please remove it once any unit-test is added