Skip to content

Commit

Permalink
Runtime: Add delete-if-exists check for the no longer used indexer.sq…
Browse files Browse the repository at this point in the history
…lite file… (#5531)
  • Loading branch information
gmalouf authored Jul 10, 2023
1 parent a1569e5 commit 217f791
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions cmd/algod/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package main
import (
"flag"
"fmt"
"github.com/algorand/go-algorand/util"
"math/rand"
"os"
"path/filepath"
Expand Down Expand Up @@ -158,6 +159,23 @@ func run() int {
}
defer fileLock.Unlock()

// Delete legacy indexer.sqlite files if they happen to exist
checkAndDeleteIndexerFile := func(fileName string) {
indexerDBFilePath := filepath.Join(absolutePath, genesis.ID(), fileName)

if util.FileExists(indexerDBFilePath) {
if idxFileRemoveErr := os.Remove(indexerDBFilePath); idxFileRemoveErr != nil {
fmt.Fprintf(os.Stderr, "Error removing %s file from data directory: %v\n", fileName, idxFileRemoveErr)
} else {
fmt.Fprintf(os.Stdout, "Removed legacy %s file from data directory\n", fileName)
}
}
}

checkAndDeleteIndexerFile("indexer.sqlite")
checkAndDeleteIndexerFile("indexer.sqlite-shm")
checkAndDeleteIndexerFile("indexer.sqlite-wal")

cfg, err := config.LoadConfigFromDisk(absolutePath)
if err != nil && !os.IsNotExist(err) {
// log is not setup yet, this will log to stderr
Expand Down

0 comments on commit 217f791

Please sign in to comment.