Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove references to io/ioutil package #45

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ on:
push:
branches:
- master

env:
GO_VERSION: 1.20.x
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to define env


jobs:
project:
name: Project Checks
Expand All @@ -13,7 +17,7 @@ jobs:
steps:
- uses: actions/setup-go@v3
with:
go-version: 1.19.x
go-version: ${{ env.GO_VERSION }}
- uses: actions/checkout@v3
with:
path: src/github.com/containerd/fuse-overlayfs-snapshotter
Expand All @@ -22,6 +26,25 @@ jobs:
with:
working-directory: src/github.com/containerd/fuse-overlayfs-snapshotter

linters:
name: Linters
permissions:
contents: read # for actions/checkout to fetch code
pull-requests: read # for golangci/golangci-lint-action to fetch pull requests
runs-on: ubuntu-22.04
timeout-minutes: 10
steps:
- uses: actions/checkout@v3
with:
path: src/github.com/containerd/fuse-overlayfs-snapshotter
- uses: actions/setup-go@v3
with:
go-version: ${{ env.GO_VERSION }}
- uses: golangci/golangci-lint-action@v3
with:
version: v1.51.1
working-directory: src/github.com/containerd/fuse-overlayfs-snapshotter

test:
runs-on: ubuntu-22.04
timeout-minutes: 30
Expand All @@ -41,6 +64,6 @@ jobs:
steps:
- uses: actions/setup-go@v3
with:
go-version: 1.19.x
go-version: ${{ env.GO_VERSION }}
- uses: actions/checkout@v3
- run: make artifacts
5 changes: 4 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,19 @@ on:
tags:
- 'v*'
- 'test-action-release-*'

env:
GO111MODULE: on
GO_VERSION: 1.20.x
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to define env


jobs:
release:
runs-on: ubuntu-22.04
timeout-minutes: 20
steps:
- uses: actions/setup-go@v3
with:
go-version: 1.19.x
go-version: ${{ env.GO_VERSION }}
- uses: actions/checkout@v3
with:
path: go/src/github.com/containerd/fuse-overlayfs-snapshotter
Expand Down
26 changes: 26 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
linters:
enable:
- depguard
- exportloopref
- gofmt
- gosec
- ineffassign
- misspell
- nolintlint
- revive
- staticcheck
- tenv
- unconvert
- unused
- vet
disable:
- errcheck

linters-settings:
depguard:
list-type: denylist
include-go-root: true
packages:
# use "io" or "os" instead
# https://go.dev/doc/go1.16#ioutil
- io/ioutil
3 changes: 1 addition & 2 deletions check.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ package fuseoverlayfs

import (
"fmt"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
Expand All @@ -33,7 +32,7 @@ import (
// supportsReadonlyMultipleLowerDir checks if read-only multiple lowerdirs can be mounted with fuse-overlayfs.
// https://github.com/containers/fuse-overlayfs/pull/133
func supportsReadonlyMultipleLowerDir(d string) error {
td, err := ioutil.TempDir(d, "fuseoverlayfs-check")
td, err := os.MkdirTemp(d, "fuseoverlayfs-check")
if err != nil {
return err
}
Expand Down
8 changes: 5 additions & 3 deletions fuseoverlayfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ package fuseoverlayfs
import (
"context"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -182,9 +181,12 @@ func (o *snapshotter) Mounts(ctx context.Context, key string) ([]mount.Mount, er
if err != nil {
return nil, err
}
defer t.Rollback()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved just for readability / matches the standard practice of other functions in this snapshotter.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be another PR

s, err := storage.GetSnapshot(ctx, key)
if err != nil {
return nil, fmt.Errorf("failed to get snapshot %s from storage: %w", key, err)
}
Comment on lines +186 to +188
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolves ineffectual assignment of err. If storage.GetSnapshot call fails then s == snapshots.Snapshot{} or empty snapshot struct. From my read it made sense to propagate the error here instead of continuing and attempting to mount an empty snapshot. Lmk your thoughts.

_, info, _, err := storage.GetInfo(ctx, key)
t.Rollback()
if err != nil {
return nil, fmt.Errorf("failed to get active mount: %w", err)
}
Expand Down Expand Up @@ -414,7 +416,7 @@ func (o *snapshotter) createSnapshot(ctx context.Context, kind snapshots.Kind, k
}

func (o *snapshotter) prepareDirectory(ctx context.Context, snapshotDir string, kind snapshots.Kind) (string, error) {
td, err := ioutil.TempDir(snapshotDir, "new-")
td, err := os.MkdirTemp(snapshotDir, "new-")
if err != nil {
return "", fmt.Errorf("failed to create temp dir: %w", err)
}
Expand Down
8 changes: 1 addition & 7 deletions fuseoverlayfs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ package fuseoverlayfs
import (
"context"
_ "crypto/sha256"
"io/ioutil"
"os"
"testing"

"github.com/containerd/containerd/pkg/testutil"
Expand All @@ -42,11 +40,7 @@ func newSnapshotter(ctx context.Context, root string) (snapshots.Snapshotter, fu

func TestFUSEOverlayFS(t *testing.T) {
testutil.RequiresRoot(t)
td, err := ioutil.TempDir("", "fuseoverlayfs-test")
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(td)
td := t.TempDir()
if err := Supported(td); err != nil {
t.Skipf("fuse-overlayfs not supported: %v", err)
}
Expand Down