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

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

commit 51ae0a506a1585cd08aac7ca4e30fa4cdb7bb3da
Author: woblerr <[email protected]>
AuthorDate: Tue Mar 17 21:46:27 2026 +0300

    Replace duplicate utility functions.
    
    - Replace searchFilter() with utils.Exists() in gpbckpconfig/helpers.go
    - Remove searchFilter() from gpbckpconfig/utils.go and its test
    - Replace getCurrentTimestamp() with history.CurrentTimestamp() in 
cmd/backup_delete.go
    - Remove getCurrentTimestamp() from cmd/wrappers.go and its test
---
 gpbackman/cmd/backup_delete.go       |  5 +++--
 gpbackman/cmd/wrappers.go            |  5 -----
 gpbackman/cmd/wrappers_test.go       |  9 ---------
 gpbackman/gpbckpconfig/helpers.go    |  9 +++++----
 gpbackman/gpbckpconfig/utils.go      | 10 +---------
 gpbackman/gpbckpconfig/utils_test.go | 19 +------------------
 6 files changed, 10 insertions(+), 47 deletions(-)

diff --git a/gpbackman/cmd/backup_delete.go b/gpbackman/cmd/backup_delete.go
index bd673a96..bae6bdf3 100644
--- a/gpbackman/cmd/backup_delete.go
+++ b/gpbackman/cmd/backup_delete.go
@@ -19,6 +19,7 @@ import (
 
        "github.com/apache/cloudberry-backup/gpbackman/gpbckpconfig"
        "github.com/apache/cloudberry-backup/gpbackman/textmsg"
+       "github.com/apache/cloudberry-backup/history"
        "github.com/apache/cloudberry-backup/utils"
 )
 
@@ -300,7 +301,7 @@ func backupDeleteDBCascade(backupList []string, 
deleteForce, ignoreErrors, skipL
 
 func backupDeleteDBPluginFunc(backupName, pluginConfigPath string, 
pluginConfig *utils.PluginConfig, hDB *sql.DB, ignoreErrors bool) error {
        var err error
-       dateDeleted := getCurrentTimestamp()
+       dateDeleted := history.CurrentTimestamp()
        gplog.Info("%s", textmsg.InfoTextBackupDeleteStart(backupName))
        err = gpbckpconfig.UpdateDeleteStatus(backupName, 
gpbckpconfig.DateDeletedInProgress, hDB)
        if err != nil {
@@ -353,7 +354,7 @@ func backupDeleteDBPluginFunc(backupName, pluginConfigPath 
string, pluginConfig
 
 func backupDeleteDBLocalFunc(backupName, backupDir string, 
maxParallelProcesses int, hDB *sql.DB, ignoreErrors bool) error {
        var err, errUpdate error
-       dateDeleted := getCurrentTimestamp()
+       dateDeleted := history.CurrentTimestamp()
        gplog.Info("%s", textmsg.InfoTextBackupDeleteStart(backupName))
        errUpdate = gpbckpconfig.UpdateDeleteStatus(backupName, 
gpbckpconfig.DateDeletedInProgress, hDB)
        if errUpdate != nil {
diff --git a/gpbackman/cmd/wrappers.go b/gpbackman/cmd/wrappers.go
index 81c8bec0..48549b51 100644
--- a/gpbackman/cmd/wrappers.go
+++ b/gpbackman/cmd/wrappers.go
@@ -6,7 +6,6 @@ import (
        "os"
        "path/filepath"
        "strings"
-       "time"
 
        "github.com/apache/cloudberry-go-libs/gplog"
        "github.com/spf13/pflag"
@@ -71,10 +70,6 @@ func getHistoryDBPath(historyDBPath string) string {
        return historyDBName
 }
 
-func getCurrentTimestamp() string {
-       return time.Now().Format(gpbckpconfig.Layout)
-}
-
 func checkCompatibleFlags(flags *pflag.FlagSet, flagNames ...string) error {
        n := 0
        for _, name := range flagNames {
diff --git a/gpbackman/cmd/wrappers_test.go b/gpbackman/cmd/wrappers_test.go
index ddd4634a..550a91d9 100644
--- a/gpbackman/cmd/wrappers_test.go
+++ b/gpbackman/cmd/wrappers_test.go
@@ -4,7 +4,6 @@ import (
        "fmt"
        "os"
        "path/filepath"
-       "time"
 
        "github.com/apache/cloudberry-backup/gpbackman/gpbckpconfig"
        "github.com/apache/cloudberry-backup/history"
@@ -41,14 +40,6 @@ var _ = Describe("wrappers tests", func() {
                })
        })
 
-       Describe("getCurrentTimestamp", func() {
-               It("returns valid timestamp", func() {
-                       result := getCurrentTimestamp()
-                       _, err := time.Parse(gpbckpconfig.Layout, result)
-                       Expect(err).ToNot(HaveOccurred())
-               })
-       })
-
        Describe("checkCompatibleFlags", func() {
                It("does not return error when no flags changed", func() {
                        flags := pflag.NewFlagSet("test", pflag.ContinueOnError)
diff --git a/gpbackman/gpbckpconfig/helpers.go 
b/gpbackman/gpbckpconfig/helpers.go
index 81c1da6b..3336c026 100644
--- a/gpbackman/gpbckpconfig/helpers.go
+++ b/gpbackman/gpbckpconfig/helpers.go
@@ -6,6 +6,7 @@ import (
        "time"
 
        "github.com/apache/cloudberry-backup/history"
+       "github.com/apache/cloudberry-backup/utils"
 )
 
 // GetBackupType Get backup type.
@@ -210,22 +211,22 @@ func CheckObjectFilteringExists(backupConfig 
*history.BackupConfig, tableFilter,
        switch {
        case tableFilter != "" && !excludeFilter:
                if objectFilter == objectFilteringIncludeTable {
-                       return searchFilter(backupConfig.IncludeRelations, 
tableFilter)
+                       return utils.Exists(backupConfig.IncludeRelations, 
tableFilter)
                }
                return false
        case tableFilter != "" && excludeFilter:
                if objectFilter == objectFilteringExcludeTable {
-                       return searchFilter(backupConfig.ExcludeRelations, 
tableFilter)
+                       return utils.Exists(backupConfig.ExcludeRelations, 
tableFilter)
                }
                return false
        case schemaFilter != "" && !excludeFilter:
                if objectFilter == objectFilteringIncludeSchema {
-                       return searchFilter(backupConfig.IncludeSchemas, 
schemaFilter)
+                       return utils.Exists(backupConfig.IncludeSchemas, 
schemaFilter)
                }
                return false
        case schemaFilter != "" && excludeFilter:
                if objectFilter == objectFilteringExcludeSchema {
-                       return searchFilter(backupConfig.ExcludeSchemas, 
schemaFilter)
+                       return utils.Exists(backupConfig.ExcludeSchemas, 
schemaFilter)
                }
                return false
        default:
diff --git a/gpbackman/gpbckpconfig/utils.go b/gpbackman/gpbckpconfig/utils.go
index ecfd223f..55954966 100644
--- a/gpbackman/gpbckpconfig/utils.go
+++ b/gpbackman/gpbckpconfig/utils.go
@@ -153,12 +153,4 @@ func BackupDirPath(backupDir, timestamp string) string {
        return filepath.Join(backupDir, "backups", timestamp[0:8], timestamp)
 }
 
-// searchFilter returns true if the value is present in the list
-func searchFilter(list []string, value string) bool {
-       for _, item := range list {
-               if item == value {
-                       return true
-               }
-       }
-       return false
-}
+
diff --git a/gpbackman/gpbckpconfig/utils_test.go 
b/gpbackman/gpbckpconfig/utils_test.go
index 95b01b24..0703194c 100644
--- a/gpbackman/gpbckpconfig/utils_test.go
+++ b/gpbackman/gpbckpconfig/utils_test.go
@@ -232,22 +232,5 @@ var _ = Describe("utils tests", func() {
                })
        })
 
-       Describe("searchFilter", func() {
-               It("returns correct result for various inputs", func() {
-                       tests := []struct {
-                               name  string
-                               list  []string
-                               value string
-                               want  bool
-                       }{
-                               {"value in list", []string{"item1", "item2", 
"item3"}, "item2", true},
-                               {"value not in list", []string{"item1", 
"item2", "item3"}, "item4", false},
-                               {"empty list", []string{}, "item1", false},
-                               {"empty value", []string{"item1", "item2", 
"item3"}, "", false},
-                       }
-                       for _, tt := range tests {
-                               Expect(searchFilter(tt.list, 
tt.value)).To(Equal(tt.want), tt.name)
-                       }
-               })
-       })
+
 })


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

Reply via email to