diff --git a/azure/package_pool.go b/azure/package_pool.go index 97be8e63..ad32a11f 100644 --- a/azure/package_pool.go +++ b/azure/package_pool.go @@ -29,7 +29,7 @@ func NewPackagePool(accountName, accountKey, container, prefix, endpoint string) return &PackagePool{az: azctx}, nil } -// String returns the storage as string +// String func (pool *PackagePool) String() string { return pool.az.String() } @@ -104,7 +104,7 @@ func (pool *PackagePool) Open(path string) (aptly.ReadSeekerCloser, error) { if err != nil { return nil, errors.Wrapf(err, "error creating tempfile for %s", path) } - defer func () { _ = os.Remove(temp.Name()) }() + defer os.Remove(temp.Name()) _, err = pool.az.client.DownloadFile(context.TODO(), pool.az.container, path, temp, nil) if err != nil { @@ -156,7 +156,7 @@ func (pool *PackagePool) Import(srcPath, basename string, checksums *utils.Check if err != nil { return "", err } - defer func() { _ = source.Close() }() + defer source.Close() err = pool.az.putFile(path, source, checksums.MD5) if err != nil { diff --git a/azure/package_pool_test.go b/azure/package_pool_test.go index ef562cb3..a32bbff7 100644 --- a/azure/package_pool_test.go +++ b/azure/package_pool_test.go @@ -2,7 +2,7 @@ package azure import ( "context" - "io" + "io/ioutil" "os" "path/filepath" "runtime" @@ -69,8 +69,8 @@ func (s *PackagePoolSuite) TestFilepathList(c *C) { c.Check(err, IsNil) c.Check(list, DeepEquals, []string{}) - _, _ = s.pool.Import(s.debFile, "a.deb", &utils.ChecksumInfo{}, false, s.cs) - _, _ = s.pool.Import(s.debFile, "b.deb", &utils.ChecksumInfo{}, false, s.cs) + s.pool.Import(s.debFile, "a.deb", &utils.ChecksumInfo{}, false, s.cs) + s.pool.Import(s.debFile, "b.deb", &utils.ChecksumInfo{}, false, s.cs) list, err = s.pool.FilepathList(nil) c.Check(err, IsNil) @@ -81,8 +81,8 @@ func (s *PackagePoolSuite) TestFilepathList(c *C) { } func (s *PackagePoolSuite) TestRemove(c *C) { - _, _ = s.pool.Import(s.debFile, "a.deb", &utils.ChecksumInfo{}, false, s.cs) - _, _ = s.pool.Import(s.debFile, "b.deb", &utils.ChecksumInfo{}, false, s.cs) + s.pool.Import(s.debFile, "a.deb", &utils.ChecksumInfo{}, false, s.cs) + s.pool.Import(s.debFile, "b.deb", &utils.ChecksumInfo{}, false, s.cs) size, err := s.pool.Remove("c7/6b/4bd12fd92e4dfe1b55b18a67a669_a.deb") c.Check(err, IsNil) @@ -247,7 +247,7 @@ func (s *PackagePoolSuite) TestOpen(c *C) { f, err := s.pool.Open(path) c.Assert(err, IsNil) - contents, err := io.ReadAll(f) + contents, err := ioutil.ReadAll(f) c.Assert(err, IsNil) c.Check(len(contents), Equals, 2738) c.Check(f.Close(), IsNil) diff --git a/azure/public.go b/azure/public.go index 6775e14c..8792ee24 100644 --- a/azure/public.go +++ b/azure/public.go @@ -18,7 +18,7 @@ import ( // PublishedStorage abstract file system with published files (actually hosted on Azure) type PublishedStorage struct { - // FIXME: unused ???? prefix string + prefix string az *azContext pathCache map[string]map[string]string } @@ -38,7 +38,7 @@ func NewPublishedStorage(accountName, accountKey, container, prefix, endpoint st return &PublishedStorage{az: azctx}, nil } -// String returns the storage as string +// String func (storage *PublishedStorage) String() string { return storage.az.String() } @@ -65,7 +65,7 @@ func (storage *PublishedStorage) PutFile(path string, sourceFilename string) err if err != nil { return err } - defer func() { _ = source.Close() }() + defer source.Close() err = storage.az.putFile(path, source, sourceMD5) if err != nil { @@ -158,7 +158,7 @@ func (storage *PublishedStorage) LinkFromPool(publishedPrefix, publishedRelPath, if err != nil { return err } - defer func() { _ = source.Close() }() + defer source.Close() err = storage.az.putFile(relFilePath, source, sourceMD5) if err == nil { @@ -193,9 +193,7 @@ func (storage *PublishedStorage) internalCopyOrMoveBlob(src, dst string, metadat if err != nil { return fmt.Errorf("error acquiring lease on source blob %s", src) } - defer func() { - _, _ = blobLeaseClient.BreakLease(context.Background(), &lease.BlobBreakOptions{BreakPeriod: to.Ptr(int32(60))}) - }() + defer blobLeaseClient.BreakLease(context.Background(), &lease.BlobBreakOptions{BreakPeriod: to.Ptr(int32(60))}) dstBlobClient := containerClient.NewBlobClient(dst) copyResp, err := dstBlobClient.StartCopyFromURL(context.Background(), srcBlobClient.URL(), &blob.StartCopyFromURLOptions{ diff --git a/azure/public_test.go b/azure/public_test.go index 5c912c51..3acd767f 100644 --- a/azure/public_test.go +++ b/azure/public_test.go @@ -4,7 +4,7 @@ import ( "context" "crypto/md5" "crypto/rand" - "io" + "io/ioutil" "os" "path/filepath" "bytes" @@ -36,7 +36,7 @@ func randString(n int) string { } const alphanum = "0123456789abcdefghijklmnopqrstuvwxyz" var bytes = make([]byte, n) - _, _ = rand.Read(bytes) + rand.Read(bytes) for i, b := range bytes { bytes[i] = alphanum[b%byte(len(alphanum))] } @@ -87,7 +87,7 @@ func (s *PublishedStorageSuite) TearDownTest(c *C) { func (s *PublishedStorageSuite) GetFile(c *C, path string) []byte { resp, err := s.storage.az.client.DownloadStream(context.Background(), s.storage.az.container, path, nil) c.Assert(err, IsNil) - data, err := io.ReadAll(resp.Body) + data, err := ioutil.ReadAll(resp.Body) c.Assert(err, IsNil) return data } @@ -121,7 +121,7 @@ func (s *PublishedStorageSuite) TestPutFile(c *C) { filename := "a/b.txt" dir := c.MkDir() - err := os.WriteFile(filepath.Join(dir, "a"), content, 0644) + err := ioutil.WriteFile(filepath.Join(dir, "a"), content, 0644) c.Assert(err, IsNil) err = s.storage.PutFile(filename, filepath.Join(dir, "a")) @@ -140,7 +140,7 @@ func (s *PublishedStorageSuite) TestPutFilePlus(c *C) { filename := "a/b+c.txt" dir := c.MkDir() - err := os.WriteFile(filepath.Join(dir, "a"), content, 0644) + err := ioutil.WriteFile(filepath.Join(dir, "a"), content, 0644) c.Assert(err, IsNil) err = s.storage.PutFile(filename, filepath.Join(dir, "a")) @@ -258,7 +258,7 @@ func (s *PublishedStorageSuite) TestRemoveDirsPlus(c *C) { func (s *PublishedStorageSuite) TestRenameFile(c *C) { dir := c.MkDir() - err := os.WriteFile(filepath.Join(dir, "a"), []byte("Welcome to Azure!"), 0644) + err := ioutil.WriteFile(filepath.Join(dir, "a"), []byte("Welcome to Azure!"), 0644) c.Assert(err, IsNil) err = s.storage.PutFile("source.txt", filepath.Join(dir, "a")) @@ -280,18 +280,18 @@ func (s *PublishedStorageSuite) TestLinkFromPool(c *C) { cs := files.NewMockChecksumStorage() tmpFile1 := filepath.Join(c.MkDir(), "mars-invaders_1.03.deb") - err := os.WriteFile(tmpFile1, []byte("Contents"), 0644) + err := ioutil.WriteFile(tmpFile1, []byte("Contents"), 0644) c.Assert(err, IsNil) cksum1 := utils.ChecksumInfo{MD5: "c1df1da7a1ce305a3b60af9d5733ac1d"} tmpFile2 := filepath.Join(c.MkDir(), "mars-invaders_1.03.deb") - err = os.WriteFile(tmpFile2, []byte("Spam"), 0644) + err = ioutil.WriteFile(tmpFile2, []byte("Spam"), 0644) c.Assert(err, IsNil) cksum2 := utils.ChecksumInfo{MD5: "e9dfd31cc505d51fc26975250750deab"} tmpFile3 := filepath.Join(c.MkDir(), "netboot/boot.img.gz") - _ = os.MkdirAll(filepath.Dir(tmpFile3), 0777) - err = os.WriteFile(tmpFile3, []byte("Contents"), 0644) + os.MkdirAll(filepath.Dir(tmpFile3), 0777) + err = ioutil.WriteFile(tmpFile3, []byte("Contents"), 0644) c.Assert(err, IsNil) cksum3 := utils.ChecksumInfo{MD5: "c1df1da7a1ce305a3b60af9d5733ac1d"}