mirror of
https://github.com/aptly-dev/aptly.git
synced 2026-06-09 06:04:12 +00:00
go1.24: fix lint, unit and system tests
- development env: base on debian trixie with go1.24 - lint: run with default config - fix lint errors - fix unit tests - fix system test
This commit is contained in:
@@ -240,7 +240,9 @@ func (pool *PackagePool) Import(srcPath, basename string, checksums *utils.Check
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
defer source.Close()
|
||||
defer func() {
|
||||
_ = source.Close()
|
||||
}()
|
||||
|
||||
sourceInfo, err := source.Stat()
|
||||
if err != nil {
|
||||
@@ -351,7 +353,9 @@ func (pool *PackagePool) Import(srcPath, basename string, checksums *utils.Check
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
defer target.Close()
|
||||
defer func() {
|
||||
_ = target.Close()
|
||||
}()
|
||||
|
||||
_, err = io.Copy(target, source)
|
||||
|
||||
|
||||
+22
-21
@@ -2,7 +2,6 @@ package files
|
||||
|
||||
import (
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
@@ -51,18 +50,18 @@ func (s *PackagePoolSuite) TestFilepathList(c *C) {
|
||||
c.Check(err, IsNil)
|
||||
c.Check(list, IsNil)
|
||||
|
||||
os.MkdirAll(filepath.Join(s.pool.rootPath, "bd", "0b"), 0755)
|
||||
os.MkdirAll(filepath.Join(s.pool.rootPath, "bd", "0a"), 0755)
|
||||
os.MkdirAll(filepath.Join(s.pool.rootPath, "ae", "0c"), 0755)
|
||||
_ = os.MkdirAll(filepath.Join(s.pool.rootPath, "bd", "0b"), 0755)
|
||||
_ = os.MkdirAll(filepath.Join(s.pool.rootPath, "bd", "0a"), 0755)
|
||||
_ = os.MkdirAll(filepath.Join(s.pool.rootPath, "ae", "0c"), 0755)
|
||||
|
||||
list, err = s.pool.FilepathList(nil)
|
||||
c.Check(err, IsNil)
|
||||
c.Check(list, DeepEquals, []string{})
|
||||
|
||||
ioutil.WriteFile(filepath.Join(s.pool.rootPath, "ae", "0c", "1.deb"), nil, 0644)
|
||||
ioutil.WriteFile(filepath.Join(s.pool.rootPath, "ae", "0c", "2.deb"), nil, 0644)
|
||||
ioutil.WriteFile(filepath.Join(s.pool.rootPath, "bd", "0a", "3.deb"), nil, 0644)
|
||||
ioutil.WriteFile(filepath.Join(s.pool.rootPath, "bd", "0b", "4.deb"), nil, 0644)
|
||||
_ = os.WriteFile(filepath.Join(s.pool.rootPath, "ae", "0c", "1.deb"), nil, 0644)
|
||||
_ = os.WriteFile(filepath.Join(s.pool.rootPath, "ae", "0c", "2.deb"), nil, 0644)
|
||||
_ = os.WriteFile(filepath.Join(s.pool.rootPath, "bd", "0a", "3.deb"), nil, 0644)
|
||||
_ = os.WriteFile(filepath.Join(s.pool.rootPath, "bd", "0b", "4.deb"), nil, 0644)
|
||||
|
||||
list, err = s.pool.FilepathList(nil)
|
||||
c.Check(err, IsNil)
|
||||
@@ -70,14 +69,14 @@ func (s *PackagePoolSuite) TestFilepathList(c *C) {
|
||||
}
|
||||
|
||||
func (s *PackagePoolSuite) TestRemove(c *C) {
|
||||
os.MkdirAll(filepath.Join(s.pool.rootPath, "bd", "0b"), 0755)
|
||||
os.MkdirAll(filepath.Join(s.pool.rootPath, "bd", "0a"), 0755)
|
||||
os.MkdirAll(filepath.Join(s.pool.rootPath, "ae", "0c"), 0755)
|
||||
_ = os.MkdirAll(filepath.Join(s.pool.rootPath, "bd", "0b"), 0755)
|
||||
_ = os.MkdirAll(filepath.Join(s.pool.rootPath, "bd", "0a"), 0755)
|
||||
_ = os.MkdirAll(filepath.Join(s.pool.rootPath, "ae", "0c"), 0755)
|
||||
|
||||
ioutil.WriteFile(filepath.Join(s.pool.rootPath, "ae", "0c", "1.deb"), []byte("1"), 0644)
|
||||
ioutil.WriteFile(filepath.Join(s.pool.rootPath, "ae", "0c", "2.deb"), []byte("22"), 0644)
|
||||
ioutil.WriteFile(filepath.Join(s.pool.rootPath, "bd", "0a", "3.deb"), []byte("333"), 0644)
|
||||
ioutil.WriteFile(filepath.Join(s.pool.rootPath, "bd", "0b", "4.deb"), []byte("4444"), 0644)
|
||||
_ = os.WriteFile(filepath.Join(s.pool.rootPath, "ae", "0c", "1.deb"), []byte("1"), 0644)
|
||||
_ = os.WriteFile(filepath.Join(s.pool.rootPath, "ae", "0c", "2.deb"), []byte("22"), 0644)
|
||||
_ = os.WriteFile(filepath.Join(s.pool.rootPath, "bd", "0a", "3.deb"), []byte("333"), 0644)
|
||||
_ = os.WriteFile(filepath.Join(s.pool.rootPath, "bd", "0b", "4.deb"), []byte("4444"), 0644)
|
||||
|
||||
size, err := s.pool.Remove("ae/0c/2.deb")
|
||||
c.Check(err, IsNil)
|
||||
@@ -99,7 +98,9 @@ func isSameDevice(s *PackagePoolSuite) bool {
|
||||
|
||||
source, _ := os.Open(s.debFile)
|
||||
sourceInfo, _ := source.Stat()
|
||||
defer source.Close()
|
||||
defer func() {
|
||||
_ = source.Close()
|
||||
}()
|
||||
|
||||
return poolDirInfo.Sys().(*syscall.Stat_t).Dev == sourceInfo.Sys().(*syscall.Stat_t).Dev
|
||||
}
|
||||
@@ -157,7 +158,7 @@ func (s *PackagePoolSuite) TestImportOk(c *C) {
|
||||
}
|
||||
|
||||
func (s *PackagePoolSuite) TestImportLegacy(c *C) {
|
||||
os.MkdirAll(filepath.Join(s.pool.rootPath, "00", "35"), 0755)
|
||||
_ = os.MkdirAll(filepath.Join(s.pool.rootPath, "00", "35"), 0755)
|
||||
err := utils.CopyFile(s.debFile, filepath.Join(s.pool.rootPath, "00", "35", "libboost-program-options-dev_1.49.0.1_i386.deb"))
|
||||
c.Assert(err, IsNil)
|
||||
|
||||
@@ -178,7 +179,7 @@ func (s *PackagePoolSuite) TestVerifyLegacy(c *C) {
|
||||
c.Check(err, IsNil)
|
||||
c.Check(exists, Equals, false)
|
||||
|
||||
os.MkdirAll(filepath.Join(s.pool.rootPath, "00", "35"), 0755)
|
||||
_ = os.MkdirAll(filepath.Join(s.pool.rootPath, "00", "35"), 0755)
|
||||
err = utils.CopyFile(s.debFile, filepath.Join(s.pool.rootPath, "00", "35", "libboost-program-options-dev_1.49.0.1_i386.deb"))
|
||||
c.Assert(err, IsNil)
|
||||
|
||||
@@ -299,8 +300,8 @@ func (s *PackagePoolSuite) TestImportNotExist(c *C) {
|
||||
}
|
||||
|
||||
func (s *PackagePoolSuite) TestImportOverwrite(c *C) {
|
||||
os.MkdirAll(filepath.Join(s.pool.rootPath, "c7", "6b"), 0755)
|
||||
ioutil.WriteFile(filepath.Join(s.pool.rootPath, "c7", "6b", "4bd12fd92e4dfe1b55b18a67a669_libboost-program-options-dev_1.49.0.1_i386.deb"), []byte("1"), 0644)
|
||||
_ = os.MkdirAll(filepath.Join(s.pool.rootPath, "c7", "6b"), 0755)
|
||||
_ = os.WriteFile(filepath.Join(s.pool.rootPath, "c7", "6b", "4bd12fd92e4dfe1b55b18a67a669_libboost-program-options-dev_1.49.0.1_i386.deb"), []byte("1"), 0644)
|
||||
|
||||
_, err := s.pool.Import(s.debFile, filepath.Base(s.debFile), &s.checksum, false, s.cs)
|
||||
c.Check(err, ErrorMatches, "unable to import into pool.*")
|
||||
@@ -336,7 +337,7 @@ func (s *PackagePoolSuite) TestOpen(c *C) {
|
||||
|
||||
f, err := s.pool.Open(path)
|
||||
c.Assert(err, IsNil)
|
||||
contents, err := ioutil.ReadAll(f)
|
||||
contents, err := io.ReadAll(f)
|
||||
c.Assert(err, IsNil)
|
||||
c.Check(len(contents), Equals, 2738)
|
||||
c.Check(f.Close(), IsNil)
|
||||
|
||||
+10
-6
@@ -86,13 +86,17 @@ func (storage *PublishedStorage) PutFile(path string, sourceFilename string) err
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer source.Close()
|
||||
defer func() {
|
||||
_ = source.Close()
|
||||
}()
|
||||
|
||||
f, err = os.Create(filepath.Join(storage.rootPath, path))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer f.Close()
|
||||
defer func() {
|
||||
_ = f.Close()
|
||||
}()
|
||||
|
||||
_, err = io.Copy(f, source)
|
||||
return err
|
||||
@@ -221,20 +225,20 @@ func (storage *PublishedStorage) LinkFromPool(publishedPrefix, publishedRelPath,
|
||||
var dst *os.File
|
||||
dst, err = os.Create(filepath.Join(poolPath, baseName))
|
||||
if err != nil {
|
||||
r.Close()
|
||||
_ = r.Close()
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = io.Copy(dst, r)
|
||||
if err != nil {
|
||||
r.Close()
|
||||
dst.Close()
|
||||
_ = r.Close()
|
||||
_ = dst.Close()
|
||||
return err
|
||||
}
|
||||
|
||||
err = r.Close()
|
||||
if err != nil {
|
||||
dst.Close()
|
||||
_ = dst.Close()
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package files
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"syscall"
|
||||
@@ -222,8 +221,8 @@ func (s *PublishedStorageSuite) TestLinkFromPool(c *C) {
|
||||
|
||||
for _, t := range tests {
|
||||
tmpPath := filepath.Join(c.MkDir(), t.sourcePath)
|
||||
os.MkdirAll(filepath.Dir(tmpPath), 0777)
|
||||
err := ioutil.WriteFile(tmpPath, []byte("Contents"), 0644)
|
||||
_ = os.MkdirAll(filepath.Dir(tmpPath), 0777)
|
||||
err := os.WriteFile(tmpPath, []byte("Contents"), 0644)
|
||||
c.Assert(err, IsNil)
|
||||
|
||||
sourceChecksum, err := utils.ChecksumsForFile(tmpPath)
|
||||
@@ -276,7 +275,7 @@ func (s *PublishedStorageSuite) TestLinkFromPool(c *C) {
|
||||
|
||||
// test linking files to duplicate final name
|
||||
tmpPath := filepath.Join(c.MkDir(), "mars-invaders_1.03.deb")
|
||||
err := ioutil.WriteFile(tmpPath, []byte("cONTENTS"), 0644)
|
||||
err := os.WriteFile(tmpPath, []byte("cONTENTS"), 0644)
|
||||
c.Assert(err, IsNil)
|
||||
|
||||
sourceChecksum, err := utils.ChecksumsForFile(tmpPath)
|
||||
@@ -330,11 +329,11 @@ func (s *PublishedStorageSuite) TestRootRemove(c *C) {
|
||||
|
||||
// Symlink
|
||||
linkedDir := filepath.Join(pwd, "linkedDir")
|
||||
os.Symlink(s.root, linkedDir)
|
||||
_ = os.Symlink(s.root, linkedDir)
|
||||
linkStorage := NewPublishedStorage(linkedDir, "", "")
|
||||
c.Assert(func() { linkStorage.Remove("") }, PanicMatches, "trying to remove empty path")
|
||||
c.Assert(func() { _ = linkStorage.Remove("") }, PanicMatches, "trying to remove empty path")
|
||||
|
||||
// Actual dir
|
||||
dirStorage := NewPublishedStorage(pwd, "", "")
|
||||
c.Assert(func() { dirStorage.RemoveDirs("", nil) }, PanicMatches, "trying to remove the root directory")
|
||||
c.Assert(func() { _ = dirStorage.RemoveDirs("", nil) }, PanicMatches, "trying to remove the root directory")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user