github.com/TrueBlocks/trueblocks-core/src/apps/chifra@v0.0.0-20241022031540-b362680128f7/pkg/index/paths.go (about) 1 package index 2 3 import ( 4 "path/filepath" 5 "strings" 6 ) 7 8 func isCacheType(path string, folder, extension string) bool { 9 if !strings.Contains(path, folder) { 10 return false 11 } 12 if !strings.HasSuffix(path, extension) { 13 return false 14 } 15 return true 16 } 17 18 // ToBloomPath returns a path pointing to the bloom filter given either a path to itself or its associated index data 19 func ToBloomPath(pathIn string) string { 20 if isCacheType(pathIn, "blooms", "bloom") { 21 return pathIn 22 } 23 ret := strings.Replace(filepath.Clean(pathIn), ".bin", ".bloom", -1) 24 ret = strings.Replace(ret, ".txt", ".bloom", -1) 25 ret = strings.Replace(ret, "finalized", "blooms", -1) 26 ret = strings.Replace(ret, "staging", "blooms", -1) 27 return ret 28 } 29 30 // ToIndexPath returns a path pointing to the index portion 31 func ToIndexPath(pathIn string) string { 32 if isCacheType(pathIn, "finalized", "bin") { 33 return pathIn 34 } 35 36 ret := strings.Replace(filepath.Clean(pathIn), ".bloom", ".bin", -1) 37 ret = strings.Replace(ret, ".txt", ".bin", -1) 38 ret = strings.Replace(ret, "blooms", "finalized", -1) 39 ret = strings.Replace(ret, "staging", "finalized", -1) 40 return ret 41 } 42 43 // ToStagingPath returns a path pointing to the staging folder given either a neighboring path 44 func ToStagingPath(pathIn string) string { 45 if strings.HasSuffix(pathIn, ".txt") { 46 return pathIn 47 } 48 49 ret := strings.Replace(filepath.Clean(pathIn), ".bin", ".txt", -1) 50 ret = strings.Replace(ret, ".bloom", ".txt", -1) 51 ret = strings.Replace(ret, "finalized", "staging", -1) 52 ret = strings.Replace(ret, "blooms", "staging", -1) 53 return ret 54 }