Skip to content

Commit

Permalink
Cleanup migrated contract JSON with full path (#231)
Browse files Browse the repository at this point in the history
Signed-off-by: Peter Broadhurst <[email protected]>

Signed-off-by: Peter Broadhurst <[email protected]>
  • Loading branch information
peterbroadhurst authored Oct 12, 2022
1 parent da2de30 commit 77e3c90
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions internal/contractregistry/contractstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,24 +290,26 @@ func (cs *contractStore) migrateFilesToLevelDB() {
abiGroups := abiMatcher.FindStringSubmatch(fileName)
instanceGroups := instanceMatcher.FindStringSubmatch(fileName)
cleanup := false
filePath := path.Join(cs.conf.StoragePath, fileName)
if legacyContractGroups != nil {
cleanup = cs.migrateLegacyContractFile(legacyContractGroups[1], path.Join(cs.conf.StoragePath, fileName), file.ModTime())
cleanup = cs.migrateLegacyContractFile(legacyContractGroups[1], filePath, file.ModTime())
} else if instanceGroups != nil {
cleanup = cs.migrateContractFile(instanceGroups[1], path.Join(cs.conf.StoragePath, fileName), file.ModTime())
cleanup = cs.migrateContractFile(instanceGroups[1], filePath, file.ModTime())
} else if abiGroups != nil {
cleanup = cs.migrateABIFile(abiGroups[1], path.Join(cs.conf.StoragePath, fileName), file.ModTime())
cleanup = cs.migrateABIFile(abiGroups[1], filePath, file.ModTime())
}
if cleanup {
cs.cleanupMigratedFile(fileName)
cs.cleanupMigratedFile(filePath)
}
}
}
}

func (cs *contractStore) cleanupMigratedFile(fileName string) {
if err := os.Remove(fileName); err != nil {
log.Errorf("Failed to clean-up migrated file %s: %s", fileName, err)
func (cs *contractStore) cleanupMigratedFile(filePath string) {
if err := os.Remove(filePath); err != nil {
log.Errorf("Failed to clean-up migrated file %s: %s", filePath, err)
}
log.Infof("Cleaned up migrated file: %s", filePath)
}

func (cs *contractStore) Init() (err error) {
Expand Down

0 comments on commit 77e3c90

Please sign in to comment.