This is an automated email from the ASF dual-hosted git repository.

djwang pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/cloudberry-backup.git

commit 8238ddae059dc2fd72fe40f1dba60d5d08b71a6d
Author: woblerr <[email protected]>
AuthorDate: Tue Apr 7 14:56:54 2026 +0300

    Fix lint issues introduced by golangci-lint v2 migration.
    
    Changes:
    - Fix variable shadowing and declaring variables before use 
(backup_helper.go, restore_helper.go, history.go, s3plugin.go, data.go).
    - Fix in testutils/functions.go where := was shadowing the host parameter, 
preventing PGHOST env var from being applied.
    - Remove unused test helper functions batchMapToString and 
contentMapToString from restore/data_test.go.
    - Add lint exclusion rules in .golangci.yml for test files: govet shadow, 
errcheck, and unparam — these are pre-existing issues in tests, not regressions 
from the v2 migration.
    
    Pre-existing issues are not fixed here and will be addressed separately.
---
 .golangci.yml                | 10 ++++++++++
 helper/backup_helper.go      | 11 +++++++----
 helper/restore_helper.go     |  8 +++++---
 history/history.go           |  3 ++-
 plugins/s3plugin/s3plugin.go |  8 +++++---
 restore/data.go              |  2 +-
 restore/data_test.go         | 22 ----------------------
 testutils/functions.go       |  2 +-
 8 files changed, 31 insertions(+), 35 deletions(-)

diff --git a/.golangci.yml b/.golangci.yml
index 7625a743..60638624 100644
--- a/.golangci.yml
+++ b/.golangci.yml
@@ -35,6 +35,16 @@ linters:
       - linters:
           - revive
         text: don't use an underscore in package name
+      - linters:
+          - govet
+        text: "shadow:"
+        path: _test\.go
+      - linters:
+          - errcheck
+        path: _test\.go
+      - linters:
+          - unparam
+        path: _test\.go
     paths:
       - vendor
 
diff --git a/helper/backup_helper.go b/helper/backup_helper.go
index 56ed9a3c..1c77ee48 100644
--- a/helper/backup_helper.go
+++ b/helper/backup_helper.go
@@ -19,9 +19,12 @@ import (
 
 func doBackupAgent() error {
        var lastRead uint64
+       var numBytes int64
        var (
                pipeWriter BackupPipeWriterCloser
                writeCmd   *exec.Cmd
+               reader     io.Reader
+               readHandle io.ReadCloser
        )
        tocfile := &toc.SegmentTOC{}
        tocfile.DataEntries = make(map[uint]toc.SegmentDataEntry)
@@ -48,7 +51,7 @@ func doBackupAgent() error {
                if i < len(oidList)-*copyQueue {
                        nextPipeToCreate := fmt.Sprintf("%s_%d", *pipeFile, 
oidList[i+*copyQueue])
                        logVerbose(fmt.Sprintf("Oid %d: Creating pipe %s\n", 
oidList[i+*copyQueue], nextPipeToCreate))
-                       err := createPipe(nextPipeToCreate)
+                       err = createPipe(nextPipeToCreate)
                        if err != nil {
                                logError(fmt.Sprintf("Oid %d: Failed to create 
pipe %s\n", oidList[i+*copyQueue], nextPipeToCreate))
                                return err
@@ -56,7 +59,7 @@ func doBackupAgent() error {
                }
 
                logInfo(fmt.Sprintf("Oid %d: Opening pipe %s", oid, 
currentPipe))
-               reader, readHandle, err := getBackupPipeReader(currentPipe)
+               reader, readHandle, err = getBackupPipeReader(currentPipe)
                if err != nil {
                        logError(fmt.Sprintf("Oid %d: Error encountered getting 
backup pipe reader: %v", oid, err))
                        return err
@@ -70,7 +73,7 @@ func doBackupAgent() error {
                }
 
                logInfo(fmt.Sprintf("Oid %d: Backing up table with pipe %s", 
oid, currentPipe))
-               numBytes, err := io.Copy(pipeWriter, reader)
+               numBytes, err = io.Copy(pipeWriter, reader)
                if err != nil {
                        logError(fmt.Sprintf("Oid %d: Error encountered copying 
bytes from pipeWriter to reader: %v", oid, err))
                        return errors.Wrap(err, strings.Trim(errBuf.String(), 
"\x00"))
@@ -96,7 +99,7 @@ func doBackupAgent() error {
                 * written to verify the agent completed.
                 */
                logVerbose("Uploading remaining data to plugin destination")
-               err := writeCmd.Wait()
+               err = writeCmd.Wait()
                if err != nil {
                        logError(fmt.Sprintf("Error encountered writing either 
TOC file or error file: %v", err))
                        return errors.Wrap(err, strings.Trim(errBuf.String(), 
"\x00"))
diff --git a/helper/restore_helper.go b/helper/restore_helper.go
index 84c0086d..50b32820 100644
--- a/helper/restore_helper.go
+++ b/helper/restore_helper.go
@@ -193,7 +193,7 @@ func doRestoreAgent() error {
                        nextBatchNum := nextOidWithBatch.batch
                        nextPipeToCreate := fmt.Sprintf("%s_%d_%d", *pipeFile, 
nextOid, nextBatchNum)
                        logVerbose(fmt.Sprintf("Oid %d, Batch %d: Creating pipe 
%s\n", nextOid, nextBatchNum, nextPipeToCreate))
-                       err := createPipe(nextPipeToCreate)
+                       err = createPipe(nextPipeToCreate)
                        if err != nil {
                                logError(fmt.Sprintf("Oid %d, Batch %d: Failed 
to create pipe %s\n", nextOid, nextBatchNum, nextPipeToCreate))
                                // In the case this error is hit it means we 
have lost the
@@ -366,6 +366,8 @@ func replaceContentInFilename(filename string, content int) 
string {
 func getRestoreDataReader(fileToRead string, objToc *toc.SegmentTOC, oidList 
[]int) (*RestoreReader, error) {
        var readHandle io.Reader
        var seekHandle io.ReadSeeker
+       var gzipReader *gzip.Reader
+       var zstdReader *zstd.Decoder
        var isSubset bool
        var err error = nil
        restoreReader := new(RestoreReader)
@@ -402,14 +404,14 @@ func getRestoreDataReader(fileToRead string, objToc 
*toc.SegmentTOC, oidList []i
        if restoreReader.readerType == SEEKABLE {
                restoreReader.seekReader = seekHandle
        } else if strings.HasSuffix(fileToRead, ".gz") {
-               gzipReader, err := gzip.NewReader(readHandle)
+               gzipReader, err = gzip.NewReader(readHandle)
                if err != nil {
                        // error logging handled by calling functions
                        return nil, err
                }
                restoreReader.bufReader = bufio.NewReader(gzipReader)
        } else if strings.HasSuffix(fileToRead, ".zst") {
-               zstdReader, err := zstd.NewReader(readHandle)
+               zstdReader, err = zstd.NewReader(readHandle)
                if err != nil {
                        // error logging handled by calling functions
                        return nil, err
diff --git a/history/history.go b/history/history.go
index ff07e106..05e1406e 100644
--- a/history/history.go
+++ b/history/history.go
@@ -414,7 +414,8 @@ func GetBackupConfig(timestamp string, historyDB *sql.DB) 
(*BackupConfig, error)
                restorePlan.Timestamp = restorePlanTimestamp
 
                restorePlanTablesQuery := fmt.Sprintf("SELECT table_fqn FROM 
restore_plan_tables WHERE timestamp = '%s' and restore_plan_timestamp = '%s'", 
timestamp, restorePlanTimestamp)
-               restorePlanTableRows, err := 
historyDB.Query(restorePlanTablesQuery)
+               var restorePlanTableRows *sql.Rows
+               restorePlanTableRows, err = 
historyDB.Query(restorePlanTablesQuery)
                if err != nil {
                        return nil, err
                }
diff --git a/plugins/s3plugin/s3plugin.go b/plugins/s3plugin/s3plugin.go
index 9a2a4e83..501bad08 100644
--- a/plugins/s3plugin/s3plugin.go
+++ b/plugins/s3plugin/s3plugin.go
@@ -111,6 +111,7 @@ func readAndValidatePluginConfig(configFile string) 
(*PluginConfig, error) {
 func InitializeAndValidateConfig(config *PluginConfig) error {
        var err error
        var errTxt string
+       var chunkSize bytesize.ByteSize
        opt := &config.Options
 
        // Initialize defaults
@@ -155,7 +156,7 @@ func InitializeAndValidateConfig(config *PluginConfig) 
error {
                errTxt += fmt.Sprintf("Invalid value for 
remove_duplicate_bucket. Valid choices are true or false.\n")
        }
        if opt.BackupMultipartChunksize != "" {
-               chunkSize, err := bytesize.Parse(opt.BackupMultipartChunksize)
+               chunkSize, err = bytesize.Parse(opt.BackupMultipartChunksize)
                if err != nil {
                        errTxt += fmt.Sprintf("Invalid 
backup_multipart_chunksize. Err: %s\n", err)
                }
@@ -170,7 +171,7 @@ func InitializeAndValidateConfig(config *PluginConfig) 
error {
                }
        }
        if opt.RestoreMultipartChunksize != "" {
-               chunkSize, err := bytesize.Parse(opt.RestoreMultipartChunksize)
+               chunkSize, err = bytesize.Parse(opt.RestoreMultipartChunksize)
                if err != nil {
                        errTxt += fmt.Sprintf("Invalid 
restore_multipart_chunksize. Err: %s\n", err)
                }
@@ -363,6 +364,7 @@ func DeleteBackup(c *cli.Context) error {
 
 func ListDirectory(c *cli.Context) error {
        var err error
+       var totalBytes int64
        config, sess, err := readConfigAndStartSession(c)
        if err != nil {
                return err
@@ -392,7 +394,7 @@ func ListDirectory(c *cli.Context) error {
                        u.PartSize = config.Options.DownloadChunkSize
                })
 
-               totalBytes, err := getFileSize(downloader.S3, bucket, *key.Key)
+               totalBytes, err = getFileSize(downloader.S3, bucket, *key.Key)
                if err != nil {
                        return err
                }
diff --git a/restore/data.go b/restore/data.go
index 11d2deea..4175ad96 100644
--- a/restore/data.go
+++ b/restore/data.go
@@ -292,7 +292,7 @@ func restoreDataFromTimestamp(fpInfo filepath.FilePathInfo, 
dataEntries []toc.Co
                                var err error
                                if MustGetFlagBool(options.INCREMENTAL) || 
MustGetFlagBool(options.TRUNCATE_TABLE) {
                                        gplog.Verbose("Truncating table %s 
prior to restoring data", tableName)
-                                       _, err := connectionPool.Exec(`TRUNCATE 
`+tableName, whichConn)
+                                       _, err = connectionPool.Exec(`TRUNCATE 
`+tableName, whichConn)
                                        if err != nil {
                                                gplog.Error("%s", err.Error())
                                        }
diff --git a/restore/data_test.go b/restore/data_test.go
index 940a9927..01a03b05 100644
--- a/restore/data_test.go
+++ b/restore/data_test.go
@@ -1,10 +1,7 @@
 package restore_test
 
 import (
-       "fmt"
        "regexp"
-       "sort"
-       "strings"
 
        "github.com/DATA-DOG/go-sqlmock"
        "github.com/apache/cloudberry-backup/backup"
@@ -134,22 +131,3 @@ var _ = Describe("restore/data tests", func() {
                })
        })
 })
-
-func batchMapToString(m map[int]map[int]int) string {
-       outer := make([]string, len(m))
-       for num, batch := range m {
-               outer[num] = fmt.Sprintf("%d: %s", num, 
contentMapToString(batch))
-       }
-       return strings.Join(outer, "; ")
-}
-
-func contentMapToString(m map[int]int) string {
-       inner := make([]string, len(m))
-       index := 0
-       for orig, dest := range m {
-               inner[index] = fmt.Sprintf("%d:%d", orig, dest)
-               index++
-       }
-       sort.Strings(inner)
-       return fmt.Sprintf("{%s}", strings.Join(inner, ", "))
-}
diff --git a/testutils/functions.go b/testutils/functions.go
index 30e1b079..19d786aa 100644
--- a/testutils/functions.go
+++ b/testutils/functions.go
@@ -93,7 +93,7 @@ func SetupTestDBConnSegment(dbname string, port int, host 
string, gpVersion dbco
                username = currentUser.Username
        }
        if host == "" {
-               host := operating.System.Getenv("PGHOST")
+               host = operating.System.Getenv("PGHOST")
                if host == "" {
                        host, _ = operating.System.Hostname()
                }


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to