Skip to content

Commit

Permalink
assume path is already expanded and move check earlier
Browse files Browse the repository at this point in the history
  • Loading branch information
milapsheth committed Feb 28, 2024
1 parent f8923f9 commit 4be0354
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 25 deletions.
9 changes: 9 additions & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,15 @@ func NewAxelarApp(
tkeys := sdk.NewTransientStoreKeys(paramstypes.TStoreKey)
memKeys := sdk.NewMemoryStoreKeys(capabilitytypes.MemStoreKey)

if wasmDir != "" {
wasmPath, err := filepath.Abs(wasmDir)
if err != nil {
panic(fmt.Sprintf("failed to resolve absolute path for new wasm dir %s: %v", wasmDir, err))

Check warning on line 220 in app/app.go

View check run for this annotation

Codecov / codecov/patch

app/app.go#L218-L220

Added lines #L218 - L220 were not covered by tests
}

wasmDir = wasmPath

Check warning on line 223 in app/app.go

View check run for this annotation

Codecov / codecov/patch

app/app.go#L223

Added line #L223 was not covered by tests
}

keepers := NewKeeperCache()
SetKeeper(keepers, InitParamsKeeper(encodingConfig, keys[paramstypes.StoreKey], tkeys[paramstypes.TStoreKey]))

Expand Down
29 changes: 4 additions & 25 deletions app/keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,41 +165,20 @@ func InitStakingKeeper(appCodec codec.Codec, keys map[string]*sdk.KVStoreKey, ke
return &stakingK
}

// expandPath resolves paths containing the "~" character to the user's home directory.
func expandPath(path string) string {
if !strings.HasPrefix(path, "~/") {
return path
}

homeDir := funcs.Must(os.UserHomeDir())

return filepath.Join(homeDir, path[2:])
}

func migrateWasmDir(oldWasmDir, newWasmDir string) error {
// Resolve paths
oldWasmPath, err := filepath.Abs(expandPath(oldWasmDir))
if err != nil {
return fmt.Errorf("failed to resolve absolute path for old wasm dir %s: %v", oldWasmDir, err)
}
newWasmPath, err := filepath.Abs(expandPath(newWasmDir))
if err != nil {
return fmt.Errorf("failed to resolve absolute path for new wasm dir %s: %v", newWasmDir, err)
}

// If the new wasm dir exists, there's nothing to do
if _, err := os.Stat(newWasmPath); err == nil {
if _, err := os.Stat(newWasmDir); err == nil {
return nil
}

// If the old wasm dir doesn't exist, there's nothing to do
if _, err := os.Stat(oldWasmPath); err != nil && os.IsNotExist(err) {
if _, err := os.Stat(oldWasmDir); err != nil && os.IsNotExist(err) {
return nil
}

// Move the wasm dir from old path to new path
if err := os.Rename(oldWasmPath, newWasmPath); err != nil {
return fmt.Errorf("failed to move wasm directory from %s to %s: %v", oldWasmPath, newWasmPath, err)
if err := os.Rename(oldWasmDir, newWasmDir); err != nil {
return fmt.Errorf("failed to move wasm directory from %s to %s: %v", oldWasmDir, newWasmDir, err)

Check warning on line 181 in app/keepers.go

View check run for this annotation

Codecov / codecov/patch

app/keepers.go#L180-L181

Added lines #L180 - L181 were not covered by tests
}

return nil

Check warning on line 184 in app/keepers.go

View check run for this annotation

Codecov / codecov/patch

app/keepers.go#L184

Added line #L184 was not covered by tests
Expand Down

0 comments on commit 4be0354

Please sign in to comment.