Other: Update golangci-lint to v1.50.0

This commit is contained in:
Leander Beernaert
2022-10-17 11:02:56 +02:00
parent e0603f741f
commit 9d800324af
70 changed files with 247 additions and 277 deletions

View File

@ -20,7 +20,6 @@ package users
import (
"errors"
"io"
"io/ioutil"
"os"
"path/filepath"
@ -30,7 +29,7 @@ import (
// isFolderEmpty checks whether a folder is empty.
// path must point to an existing folder.
func isFolderEmpty(path string) (bool, error) {
files, err := ioutil.ReadDir(path)
files, err := os.ReadDir(path)
if err != nil {
return true, err
}
@ -90,13 +89,13 @@ func copyFolder(srcPath, dstPath string) error {
if err = os.MkdirAll(dstPath, 0o700); err != nil {
return err
}
files, err := ioutil.ReadDir(srcPath)
files, err := os.ReadDir(srcPath)
if err != nil {
return err
}
// copy only regular files and folders
for _, fileInfo := range files {
mode := fileInfo.Mode()
mode := fileInfo.Type()
if mode&os.ModeSymlink != 0 {
continue // we skip symbolic links to avoid potential endless recursion
}
@ -227,7 +226,7 @@ func (u *Users) MigrateCache(srcPath, dstPath string) error {
// GODT-1381 Edge case: read-only source migration: prevent re-naming
// (read-only is conserved). Do copy instead.
tmp, err := ioutil.TempFile(srcPath, "tmp")
tmp, err := os.CreateTemp(srcPath, "tmp")
if err == nil {
// Removal of tmp file cannot be deferred, as we are going to try to move the containing folder.
if err = tmp.Close(); err == nil {

View File

@ -21,7 +21,6 @@ import (
"crypto/sha1"
"encoding/hex"
"io"
"io/ioutil"
"os"
"path/filepath"
"testing"
@ -37,7 +36,7 @@ const (
// tempFileWithContent() creates a temporary file in folderPath containing the string content.
// Returns the path of the created file.
func tempFileWithContent(folderPath, content string) (string, error) {
file, err := ioutil.TempFile(folderPath, "")
file, err := os.CreateTemp(folderPath, "")
if err != nil {
return "", err
}
@ -49,7 +48,7 @@ func tempFileWithContent(folderPath, content string) (string, error) {
// itemCountInFolder() counts the number of items (files, folders, etc) in a folder.
// Returns -1 if an error occurred.
func itemCountInFolder(path string) int {
files, err := ioutil.ReadDir(path)
files, err := os.ReadDir(path)
if err != nil {
return -1
}
@ -83,13 +82,13 @@ func filesAreIdentical(path1, path2 string) bool {
func TestCache_IsFolderEmpty(t *testing.T) {
_, err := isFolderEmpty("")
r.Error(t, err)
tempDirPath, err := ioutil.TempDir("", "")
tempDirPath, err := os.MkdirTemp("", "")
defer func() { r.NoError(t, os.Remove(tempDirPath)) }()
r.NoError(t, err)
result, err := isFolderEmpty(tempDirPath)
r.NoError(t, err)
r.True(t, result)
tempFile, err := ioutil.TempFile(tempDirPath, "")
tempFile, err := os.CreateTemp(tempDirPath, "")
r.NoError(t, err)
defer func() { r.NoError(t, os.Remove(tempFile.Name())) }()
r.NoError(t, tempFile.Close())
@ -101,10 +100,10 @@ func TestCache_IsFolderEmpty(t *testing.T) {
}
func TestCache_CheckFolderIsSuitableDestinationForCache(t *testing.T) {
tempDirPath, err := ioutil.TempDir("", "")
tempDirPath, err := os.MkdirTemp("", "")
defer func() { _ = os.Remove(tempDirPath) }() // cleanup in case we fail before removing it.
r.NoError(t, err)
tempFile, err := ioutil.TempFile(tempDirPath, "")
tempFile, err := os.CreateTemp(tempDirPath, "")
r.NoError(t, err)
defer func() { _ = os.Remove(tempFile.Name()) }() // cleanup in case we fail before removing it.
r.NoError(t, tempFile.Close())
@ -122,10 +121,10 @@ func TestCache_CopyFolder(t *testing.T) {
// |-srcSubDir/
// |-file2
srcDir, err := ioutil.TempDir("", "")
srcDir, err := os.MkdirTemp("", "")
defer func() { r.NoError(t, os.RemoveAll(srcDir)) }()
r.NoError(t, err)
srcSubDir, err := ioutil.TempDir(srcDir, "")
srcSubDir, err := os.MkdirTemp(srcDir, "")
r.NoError(t, err)
subDirName := filepath.Base(srcSubDir)
file1, err := tempFileWithContent(srcDir, str1)
@ -162,7 +161,7 @@ func TestCache_CopyFolder(t *testing.T) {
}
func TestCache_IsSubfolderOf(t *testing.T) {
dir, err := ioutil.TempDir("", "")
dir, err := os.MkdirTemp("", "")
defer func() { r.NoError(t, os.Remove(dir)) }()
r.NoError(t, err)
r.True(t, isSubfolderOf(dir, dir))

View File

@ -19,7 +19,6 @@ package users
import (
"fmt"
"io/ioutil"
"os"
"runtime"
"runtime/debug"
@ -166,7 +165,7 @@ func initMocks(t *testing.T) mocks {
mockCtrl = gomock.NewController(t)
}
cacheFile, err := ioutil.TempFile("", "bridge-store-cache-*.db")
cacheFile, err := os.CreateTemp("", "bridge-store-cache-*.db")
r.NoError(t, err, "could not get temporary file for store cache")
r.NoError(t, cacheFile.Close())
@ -193,7 +192,7 @@ func initMocks(t *testing.T) mocks {
m.storeMaker.EXPECT().New(gomock.Any()).DoAndReturn(func(user store.BridgeUser) (*store.Store, error) {
var sentryReporter *sentry.Reporter // Sentry reporter is not used under unit tests.
dbFile, err := ioutil.TempFile(t.TempDir(), "bridge-store-db-*.db")
dbFile, err := os.CreateTemp(t.TempDir(), "bridge-store-db-*.db")
r.NoError(t, err, "could not get temporary file for store db")
r.NoError(t, dbFile.Close())