Merge pull request #2307 from kolyshkin/nolint

ci: add nolintlint and unconvert linters, fix found issues
This commit is contained in:
openshift-merge-bot[bot] 2025-04-04 12:31:46 +00:00 committed by GitHub
commit 2dfd3025f0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
26 changed files with 65 additions and 82 deletions

View File

@ -5,6 +5,9 @@ formatters:
- gofumpt
linters:
enable:
- nolintlint
- unconvert
exclusions:
presets:
- comments

View File

@ -67,8 +67,8 @@ func layers(flags *mflag.FlagSet, action string, m storage.Store, args []string)
for _, layer := range layers {
if listLayersTree {
node := treeNode{
left: string(layer.Parent),
right: string(layer.ID),
left: layer.Parent,
right: layer.ID,
notes: []string{},
}
if node.left == "" {

View File

@ -36,8 +36,8 @@ func (c *platformChowner) LChown(path string, info os.FileInfo, toHost, toContai
}
i := inode{
Dev: uint64(st.Dev),
Ino: uint64(st.Ino),
Dev: uint64(st.Dev), //nolint:unconvert
Ino: st.Ino,
}
c.mutex.Lock()

View File

@ -160,7 +160,10 @@ func DirCopy(srcDir, dstDir string, copyMode Mode, copyXattrs bool) error {
switch mode := f.Mode(); {
case mode.IsRegular():
id := fileID{dev: uint64(stat.Dev), ino: stat.Ino}
id := fileID{
dev: uint64(stat.Dev), //nolint:unconvert
ino: stat.Ino,
}
if copyMode == Hardlink {
isHardlink = true
if err2 := os.Link(srcPath, dstPath); err2 != nil {
@ -242,12 +245,11 @@ func DirCopy(srcDir, dstDir string, copyMode Mode, copyXattrs bool) error {
}
// system.Chtimes doesn't support a NOFOLLOW flag atm
// nolint: unconvert
if f.IsDir() {
dirsToSetMtimes.PushFront(&dirMtimeInfo{dstPath: &dstPath, stat: stat})
} else if !isSymlink {
aTime := time.Unix(int64(stat.Atim.Sec), int64(stat.Atim.Nsec))
mTime := time.Unix(int64(stat.Mtim.Sec), int64(stat.Mtim.Nsec))
aTime := time.Unix(stat.Atim.Unix())
mTime := time.Unix(stat.Mtim.Unix())
if err := system.Chtimes(dstPath, aTime, mTime); err != nil {
return err
}

View File

@ -259,7 +259,7 @@ func supportsIdmappedLowerLayers(home string) (bool, error) {
}
defer cleanupFunc()
if err := idmap.CreateIDMappedMount(lowerDir, lowerMappedDir, int(pid)); err != nil {
if err := idmap.CreateIDMappedMount(lowerDir, lowerMappedDir, pid); err != nil {
return false, fmt.Errorf("create mapped mount: %w", err)
}
defer func() {

View File

@ -492,7 +492,7 @@ func parseOptions(options []string) (*overlayOptions, error) {
if err != nil {
return nil, err
}
o.quota.Inodes = uint64(inodes)
o.quota.Inodes = inodes
case "imagestore", "additionalimagestore":
logrus.Debugf("overlay: imagestore=%s", val)
// Additional read only image stores to use for lower paths
@ -1163,7 +1163,7 @@ func (d *Driver) parseStorageOpt(storageOpt map[string]string, driver *Driver) e
if err != nil {
return err
}
driver.options.quota.Inodes = uint64(inodes)
driver.options.quota.Inodes = inodes
default:
return fmt.Errorf("unknown option %s", key)
}
@ -1551,7 +1551,7 @@ func (d *Driver) get(id string, disableShifting bool, options graphdriver.MountO
permsKnown := false
st, err := os.Stat(filepath.Join(dir, nameWithSuffix("diff", diffN)))
if err == nil {
perms = os.FileMode(st.Mode())
perms = st.Mode()
permsKnown = true
}
for err == nil {
@ -1566,7 +1566,7 @@ func (d *Driver) get(id string, disableShifting bool, options graphdriver.MountO
if err != nil {
return "", err
}
idmappedMountProcessPid = int(pid)
idmappedMountProcessPid = pid
defer cleanupFunc()
}
@ -1638,7 +1638,7 @@ func (d *Driver) get(id string, disableShifting bool, options graphdriver.MountO
lower = path.Join(p, d.name, l)
if st2, err2 := os.Stat(lower); err2 == nil {
if !permsKnown {
perms = os.FileMode(st2.Mode())
perms = st2.Mode()
permsKnown = true
}
break
@ -1659,7 +1659,7 @@ func (d *Driver) get(id string, disableShifting bool, options graphdriver.MountO
}
} else {
if !permsKnown {
perms = os.FileMode(st.Mode())
perms = st.Mode()
permsKnown = true
}
lower = newpath
@ -2505,7 +2505,7 @@ func (d *Driver) UpdateLayerIDMap(id string, toContainer, toHost *idtools.IDMapp
perms = *d.options.forceMask
} else {
if err == nil {
perms = os.FileMode(st.Mode())
perms = st.Mode()
}
}
for err == nil {

View File

@ -48,7 +48,7 @@ func (d *dedupFiles) isFirstVisitOf(fi fs.FileInfo) (bool, error) {
if !ok {
return false, fmt.Errorf("unable to get raw syscall.Stat_t data")
}
return d.recordInode(uint64(st.Dev), st.Ino)
return d.recordInode(uint64(st.Dev), st.Ino) //nolint:unconvert
}
// dedup deduplicates the file at src path to dst path
@ -94,7 +94,7 @@ func (d *dedupFiles) dedup(src, dst string, fiDst fs.FileInfo) (uint64, error) {
}
err = unix.IoctlFileDedupeRange(int(srcFile.Fd()), &value)
if err == nil {
return uint64(value.Info[0].Bytes_deduped), nil
return value.Info[0].Bytes_deduped, nil
}
if errors.Is(err, unix.ENOTSUP) {

View File

@ -28,7 +28,7 @@ func NewListOptsRef(values *[]string, validator ValidatorFctType) *ListOpts {
}
func (opts *ListOpts) String() string {
return fmt.Sprintf("%v", []string((*opts.values)))
return fmt.Sprintf("%v", *opts.values)
}
// Set validates if needed the input value and adds it to the
@ -150,7 +150,7 @@ func (opts *MapOpts) GetAll() map[string]string {
}
func (opts *MapOpts) String() string {
return fmt.Sprintf("%v", map[string]string((opts.values)))
return fmt.Sprintf("%v", opts.values)
}
// Type returns a string name for this Option type

View File

@ -1406,7 +1406,7 @@ func remapIDs(readIDMappings, writeIDMappings *idtools.IDMappings, chownOpts *id
} else if runtime.GOOS == darwin {
uid, gid = hdr.Uid, hdr.Gid
if xstat, ok := hdr.PAXRecords[PaxSchilyXattr+idtools.ContainersOverrideXattr]; ok {
attrs := strings.Split(string(xstat), ":")
attrs := strings.Split(xstat, ":")
if len(attrs) >= 3 {
val, err := strconv.ParseUint(attrs[0], 10, 32)
if err != nil {

View File

@ -173,7 +173,7 @@ func (o overlayWhiteoutConverter) ConvertRead(hdr *tar.Header, path string) (boo
func isWhiteOut(stat os.FileInfo) bool {
s := stat.Sys().(*syscall.Stat_t)
return major(uint64(s.Rdev)) == 0 && minor(uint64(s.Rdev)) == 0
return major(uint64(s.Rdev)) == 0 && minor(uint64(s.Rdev)) == 0 //nolint:unconvert
}
func GetFileOwner(path string) (uint32, uint32, uint32, error) {

View File

@ -161,8 +161,7 @@ func getNlink(path string) (uint64, error) {
if !ok {
return 0, fmt.Errorf("expected type *syscall.Stat_t, got %t", stat.Sys())
}
// We need this conversion on ARM64
return uint64(statT.Nlink), nil
return uint64(statT.Nlink), nil //nolint:unconvert // Need the conversion for e.g. linux/arm64.
}
func getInode(path string) (uint64, error) {

View File

@ -65,7 +65,7 @@ func (bf *bloomFilter) writeTo(writer io.Writer) error {
if err := binary.Write(writer, binary.LittleEndian, uint64(len(bf.bitArray))); err != nil {
return err
}
if err := binary.Write(writer, binary.LittleEndian, uint32(bf.k)); err != nil {
if err := binary.Write(writer, binary.LittleEndian, bf.k); err != nil {
return err
}
if err := binary.Write(writer, binary.LittleEndian, bf.bitArray); err != nil {

View File

@ -238,7 +238,7 @@ func FuzzReadCache(f *testing.F) {
dest = nil
f.Fuzz(func(t *testing.T, orig []byte) {
cacheRead, err := readCacheFileFromMemory([]byte(orig))
cacheRead, err := readCacheFileFromMemory(orig)
if err != nil || cacheRead == nil {
return
}

View File

@ -87,7 +87,7 @@ func readEstargzChunkedManifest(blobStream ImageSourceSeekable, blobSize int64,
return nil, 0, fmt.Errorf("parse ToC offset: %w", err)
}
size := int64(blobSize - footerSize - tocOffset)
size := blobSize - footerSize - tocOffset
// set a reasonable limit
if size > maxTocSize {
// Not errFallbackCanConvert: we would still use too much memory.

View File

@ -43,7 +43,7 @@ func escaped(val []byte, escape int) string {
}
var result string
for _, c := range []byte(val) {
for _, c := range val {
hexEscape := false
var special string

View File

@ -177,8 +177,7 @@ func TestSafeLink(t *testing.T) {
err = syscall.Fstat(int(newFile.Fd()), &st)
assert.NoError(t, err)
// We need this conversion on ARM64
assert.Equal(t, uint64(st.Nlink), uint64(2))
assert.Equal(t, 2, int(st.Nlink))
err = newFile.Close()
assert.NoError(t, err)

View File

@ -234,7 +234,7 @@ func WriteZstdChunkedManifest(dest io.Writer, outMetadata map[string]string, off
Offset: manifestOffset,
LengthCompressed: uint64(len(compressedManifest)),
LengthUncompressed: uint64(len(manifest)),
OffsetTarSplit: uint64(tarSplitOffset),
OffsetTarSplit: tarSplitOffset,
LengthCompressedTarSplit: uint64(len(tarSplitData.Data)),
LengthUncompressedTarSplit: uint64(tarSplitData.UncompressedSize),
}

View File

@ -1011,7 +1011,7 @@ func mergeMissingChunks(missingParts []missingPart, target int) []missingPart {
!missingParts[prevIndex].Hole && !missingParts[i].Hole &&
len(missingParts[prevIndex].Chunks) == 1 && len(missingParts[i].Chunks) == 1 &&
missingParts[prevIndex].Chunks[0].File.Name == missingParts[i].Chunks[0].File.Name {
missingParts[prevIndex].SourceChunk.Length += uint64(gap) + missingParts[i].SourceChunk.Length
missingParts[prevIndex].SourceChunk.Length += gap + missingParts[i].SourceChunk.Length
missingParts[prevIndex].Chunks[0].CompressedSize += missingParts[i].Chunks[0].CompressedSize
missingParts[prevIndex].Chunks[0].UncompressedSize += missingParts[i].Chunks[0].UncompressedSize
} else {
@ -1069,7 +1069,7 @@ func mergeMissingChunks(missingParts []missingPart, target int) []missingPart {
} else {
gap := getGap(missingParts, i)
prev := &newMissingParts[len(newMissingParts)-1]
prev.SourceChunk.Length += uint64(gap) + missingParts[i].SourceChunk.Length
prev.SourceChunk.Length += gap + missingParts[i].SourceChunk.Length
prev.Hole = false
prev.OriginFile = nil
if gap > 0 {
@ -1761,7 +1761,7 @@ func (c *chunkedDiffer) ApplyDiff(dest string, options *archive.TarOptions, diff
// the file is missing, attempt to find individual chunks.
for _, chunk := range r.chunks {
compressedSize := int64(chunk.EndOffset - chunk.Offset)
compressedSize := chunk.EndOffset - chunk.Offset
size := remainingSize
if chunk.ChunkSize > 0 {
size = chunk.ChunkSize

View File

@ -42,13 +42,11 @@ func Usage(dir string) (usage *DiskUsage, err error) {
// Check inode to only count the sizes of files with multiple hard links once.
inode := fileInfo.Sys().(*syscall.Stat_t).Ino
// inode is not a uint64 on all platforms. Cast it to avoid issues.
if _, exists := data[uint64(inode)]; exists {
if _, exists := data[inode]; exists {
return nil
}
// inode is not a uint64 on all platforms. Cast it to avoid issues.
data[uint64(inode)] = struct{}{}
data[inode] = struct{}{}
// Ignore directory sizes
if entry.IsDir() {
return nil

View File

@ -38,7 +38,7 @@ func TestAtomicWriteToFile(t *testing.T) {
if err != nil {
t.Fatalf("Error statting file: %v", err)
}
if expected := os.FileMode(testMode); st.Mode() != expected {
if expected := testMode; st.Mode() != expected {
t.Fatalf("Mode mismatched, expected %o, got %o", expected, st.Mode())
}
}
@ -131,7 +131,7 @@ func TestAtomicWriteSetCommit(t *testing.T) {
if err != nil {
t.Fatalf("Error statting file: %v", err)
}
if expected := os.FileMode(testMode); st.Mode() != expected {
if expected := testMode; st.Mode() != expected {
t.Fatalf("Mode mismatched, expected %o, got %o", expected, st.Mode())
}
}

View File

@ -113,7 +113,7 @@ func openNextAvailableLoopback(sparseName string, sparseFile *os.File) (*os.File
logrus.Errorf("Getting loopback backing file: %s", err)
return nil, ErrGetLoopbackBackingFile
}
if dev != uint64(st.Dev) || ino != st.Ino {
if dev != uint64(st.Dev) || ino != st.Ino { //nolint:unconvert
logrus.Errorf("Loopback device and filesystem disagree on device/inode for %q: %#x(%d):%#x(%d) vs %#x(%d):%#x(%d)", sparseName, dev, dev, ino, ino, st.Dev, st.Dev, st.Ino, st.Ino)
}
return loopFile, nil

View File

@ -36,7 +36,7 @@ func FindLoopDeviceFor(file *os.File) *os.File {
return nil
}
targetInode := stat.Sys().(*syscall.Stat_t).Ino
targetDevice := stat.Sys().(*syscall.Stat_t).Dev
targetDevice := uint64(stat.Sys().(*syscall.Stat_t).Dev) //nolint:unconvert
for i := 0; true; i++ {
path := fmt.Sprintf("/dev/loop%d", i)
@ -53,7 +53,7 @@ func FindLoopDeviceFor(file *os.File) *os.File {
}
dev, inode, err := getLoopbackBackingFile(file)
if err == nil && dev == uint64(targetDevice) && inode == targetInode {
if err == nil && dev == targetDevice && inode == targetInode {
return file
}
file.Close()

View File

@ -49,7 +49,7 @@ func panicIfNotInitialized() {
}
}
func naiveSelf() string { //nolint: unused
func naiveSelf() string {
name := os.Args[0]
if filepath.Base(name) == name {
if lp, err := exec.LookPath(name); err == nil {

View File

@ -9,6 +9,18 @@ import (
"time"
)
func atime(t *testing.T, file string) time.Time {
t.Helper()
fi, err := os.Stat(file)
if err != nil {
t.Fatal(err)
}
stat := fi.Sys().(*syscall.Stat_t)
return time.Unix(stat.Atim.Unix())
}
// TestChtimesLinux tests Chtimes access time on a tempfile on Linux
func TestChtimesLinux(t *testing.T) {
file := prepareTempFile(t)
@ -23,13 +35,7 @@ func TestChtimesLinux(t *testing.T) {
t.Fatal(err)
}
f, err := os.Stat(file)
if err != nil {
t.Fatal(err)
}
stat := f.Sys().(*syscall.Stat_t)
aTime := time.Unix(int64(stat.Atim.Sec), int64(stat.Atim.Nsec))
aTime := atime(t, file)
if aTime != unixEpochTime {
t.Fatalf("Expected: %s, got: %s", unixEpochTime, aTime)
}
@ -39,13 +45,7 @@ func TestChtimesLinux(t *testing.T) {
t.Fatal(err)
}
f, err = os.Stat(file)
if err != nil {
t.Fatal(err)
}
stat = f.Sys().(*syscall.Stat_t)
aTime = time.Unix(int64(stat.Atim.Sec), int64(stat.Atim.Nsec))
aTime = atime(t, file)
if aTime != unixEpochTime {
t.Fatalf("Expected: %s, got: %s", unixEpochTime, aTime)
}
@ -55,13 +55,7 @@ func TestChtimesLinux(t *testing.T) {
t.Fatal(err)
}
f, err = os.Stat(file)
if err != nil {
t.Fatal(err)
}
stat = f.Sys().(*syscall.Stat_t)
aTime = time.Unix(int64(stat.Atim.Sec), int64(stat.Atim.Nsec))
aTime = atime(t, file)
if aTime != unixEpochTime {
t.Fatalf("Expected: %s, got: %s", unixEpochTime, aTime)
}
@ -71,13 +65,7 @@ func TestChtimesLinux(t *testing.T) {
t.Fatal(err)
}
f, err = os.Stat(file)
if err != nil {
t.Fatal(err)
}
stat = f.Sys().(*syscall.Stat_t)
aTime = time.Unix(int64(stat.Atim.Sec), int64(stat.Atim.Nsec))
aTime = atime(t, file)
if aTime != afterUnixEpochTime {
t.Fatalf("Expected: %s, got: %s", afterUnixEpochTime, aTime)
}
@ -87,13 +75,7 @@ func TestChtimesLinux(t *testing.T) {
t.Fatal(err)
}
f, err = os.Stat(file)
if err != nil {
t.Fatal(err)
}
stat = f.Sys().(*syscall.Stat_t)
aTime = time.Unix(int64(stat.Atim.Sec), int64(stat.Atim.Nsec))
aTime = atime(t, file)
if aTime.Truncate(time.Second) != unixMaxTime.Truncate(time.Second) {
t.Fatalf("Expected: %s, got: %s", unixMaxTime.Truncate(time.Second), aTime.Truncate(time.Second))
}

View File

@ -9,9 +9,9 @@ func fromStatT(s *syscall.Stat_t) (*StatT, error) {
mode: s.Mode,
uid: s.Uid,
gid: s.Gid,
rdev: uint64(s.Rdev),
rdev: uint64(s.Rdev), //nolint:unconvert
mtim: s.Mtim,
dev: uint64(s.Dev),
dev: uint64(s.Dev), //nolint:unconvert
}, nil
}

View File

@ -468,7 +468,7 @@ type Runnable interface {
Run() error
}
func bailOnError(err error, format string, a ...any) { // nolint: revive,goprintffuncname
func bailOnError(err error, format string, a ...any) { //nolint:revive,goprintffuncname
if err != nil {
if format != "" {
logrus.Errorf("%s: %v", fmt.Sprintf(format, a...), err)