Skip to content

Commit ef6c026

Browse files
committed
fix-lint
1 parent 9bcec8c commit ef6c026

File tree

4 files changed

+12
-11
lines changed

4 files changed

+12
-11
lines changed

cmd/cronosd/cmd/patch_db.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -229,15 +229,15 @@ Examples:
229229
} else {
230230
// For multiple databases, validate that targetPath is a directory, not a *.db file
231231
cleanedTargetPath := filepath.Clean(targetPath)
232-
if filepath.Ext(cleanedTargetPath) == ".db" {
232+
if filepath.Ext(cleanedTargetPath) == dbmigrate.DbExtension {
233233
return fmt.Errorf("when patching multiple databases, --target-path must be a data directory (e.g., ~/.cronos/data), not a *.db file path (got %q); remove the .db suffix", targetPath)
234234
}
235235
// Treat targetPath as data directory
236-
dbTargetPath = filepath.Join(targetPath, dbName+".db")
236+
dbTargetPath = filepath.Join(targetPath, dbName+dbmigrate.DbExtension)
237237
}
238238

239239
cleanTargetPath := filepath.Clean(dbTargetPath)
240-
if filepath.Ext(cleanTargetPath) != ".db" {
240+
if filepath.Ext(cleanTargetPath) != dbmigrate.DbExtension {
241241
return fmt.Errorf("--target-path must reference a *.db directory (got %q)", dbTargetPath)
242242
}
243243

cmd/cronosd/cmd/patch_db_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"path/filepath"
55
"testing"
66

7+
"github.com/crypto-org-chain/cronos/cmd/cronosd/dbmigrate"
78
"github.com/stretchr/testify/require"
89
)
910

@@ -65,7 +66,7 @@ func TestTargetPathValidation(t *testing.T) {
6566
} else {
6667
// Multiple DBs: validate targetPath is not a *.db file
6768
cleanedTargetPath := filepath.Clean(tt.targetPath)
68-
if filepath.Ext(cleanedTargetPath) == ".db" {
69+
if filepath.Ext(cleanedTargetPath) == dbmigrate.DbExtension {
6970
err = &targetPathError{path: tt.targetPath}
7071
}
7172
}

cmd/cronosd/dbmigrate/migrate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ func Migrate(opts MigrateOptions) (*MigrationStats, error) {
117117
// For migration, we need to ensure we don't accidentally overwrite an existing DB
118118
// Unified path format for all backends: <dbName>.migrate-temp.db
119119
tempTargetDir := filepath.Join(targetDataDir, opts.DBName+".migrate-temp.db")
120-
finalTargetDir := filepath.Join(targetDataDir, opts.DBName+".db")
120+
finalTargetDir := filepath.Join(targetDataDir, opts.DBName+DbExtension)
121121

122122
var targetDB dbm.DB
123123
if opts.TargetBackend == dbm.RocksDBBackend {

cmd/cronosd/dbmigrate/patch.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import (
1818
)
1919

2020
const (
21-
dbExtension = ".db"
21+
DbExtension = ".db"
2222
)
2323

2424
// EthTxInfo stores information needed to search for event-indexed keys in source DB
@@ -70,7 +70,7 @@ func validatePatchOptions(opts PatchOptions) error {
7070
}
7171

7272
// Construct and validate source database path
73-
sourceDBPath := filepath.Join(opts.SourceHome, "data", opts.DBName+".db")
73+
sourceDBPath := filepath.Join(opts.SourceHome, "data", opts.DBName+DbExtension)
7474
if _, err := os.Stat(sourceDBPath); os.IsNotExist(err) {
7575
return fmt.Errorf("source database does not exist: %s", sourceDBPath)
7676
}
@@ -85,11 +85,11 @@ func validatePatchOptions(opts PatchOptions) error {
8585

8686
// openSourceDatabase opens the source database for reading
8787
func openSourceDatabase(opts PatchOptions) (dbm.DB, string, error) {
88-
sourceDBPath := filepath.Join(opts.SourceHome, "data", opts.DBName+".db")
88+
sourceDBPath := filepath.Join(opts.SourceHome, "data", opts.DBName+DbExtension)
8989
sourceDir := filepath.Dir(sourceDBPath)
9090
sourceName := filepath.Base(sourceDBPath)
91-
if len(sourceName) > len(dbExtension) && sourceName[len(sourceName)-len(dbExtension):] == dbExtension {
92-
sourceName = sourceName[:len(sourceName)-len(dbExtension)]
91+
if len(sourceName) > len(DbExtension) && sourceName[len(sourceName)-len(DbExtension):] == DbExtension {
92+
sourceName = sourceName[:len(sourceName)-len(DbExtension)]
9393
}
9494

9595
sourceDB, err := dbm.NewDB(sourceName, opts.SourceBackend, sourceDir)
@@ -109,7 +109,7 @@ func openTargetDatabase(opts PatchOptions) (dbm.DB, error) {
109109
} else {
110110
targetDir := filepath.Dir(opts.TargetPath)
111111
targetName := filepath.Base(opts.TargetPath)
112-
targetName = strings.TrimSuffix(targetName, dbExtension)
112+
targetName = strings.TrimSuffix(targetName, DbExtension)
113113
targetDB, err = dbm.NewDB(targetName, opts.TargetBackend, targetDir)
114114
}
115115
if err != nil {

0 commit comments

Comments
 (0)