path fix
This commit is contained in:
parent
531947a497
commit
ea28cbc1b5
3 changed files with 13 additions and 13 deletions
|
|
@ -9,9 +9,9 @@ export default class {
|
|||
last24hCache: { ts: number, ok: number, fail: number }[] = []
|
||||
lastPersistedCache: number = 0
|
||||
constructor(settings: StorageSettings) {
|
||||
const metricsPath = [settings.dataDir, "metric_events"].join("/")
|
||||
const metricsPath = [settings.dataDir, "metric_events"].filter(s => !!s).join("/")
|
||||
this.tlvStorage = new TlvFilesStorage(metricsPath)
|
||||
this.cachePath = [settings.dataDir, "metric_cache"].join("/")
|
||||
this.cachePath = [settings.dataDir, "metric_cache"].filter(s => !!s).join("/")
|
||||
if (!fs.existsSync(this.cachePath)) {
|
||||
fs.mkdirSync(this.cachePath, { recursive: true });
|
||||
}
|
||||
|
|
@ -60,12 +60,12 @@ export default class {
|
|||
}
|
||||
|
||||
persistCache = () => {
|
||||
const last24CachePath = [this.cachePath, "last24hSF.json"].join("/")
|
||||
const last24CachePath = [this.cachePath, "last24hSF.json"].filter(s => !!s).filter(s => !!s).join("/")
|
||||
fs.writeFileSync(last24CachePath, JSON.stringify(this.last24hCache), {})
|
||||
}
|
||||
|
||||
loadCache = () => {
|
||||
const last24CachePath = [this.cachePath, "last24hSF.json"].join("/")
|
||||
const last24CachePath = [this.cachePath, "last24hSF.json"].filter(s => !!s).filter(s => !!s).join("/")
|
||||
if (fs.existsSync(last24CachePath)) {
|
||||
this.last24hCache = JSON.parse(fs.readFileSync(last24CachePath, 'utf-8'))
|
||||
this.rotateCache(Math.floor(Date.now() / 1000))
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ export class StateBundler {
|
|||
tlvStorage: TlvFilesStorage
|
||||
reportLog = getLogger({ component: 'stateBundlerReport' })
|
||||
constructor(settings: StorageSettings) {
|
||||
const bundlerPath = [settings.dataDir, "bundler_events"].join("/")
|
||||
const bundlerPath = [settings.dataDir, "bundler_events"].filter(s => !!s).join("/")
|
||||
this.tlvStorage = new TlvFilesStorage(bundlerPath)
|
||||
this.tlvStorage.initMeta()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ export class TlvFilesStorage {
|
|||
if (!this.metaReady || !this.meta[app] || !this.meta[app][dataName] || !this.meta[app][dataName].chunks.includes(chunk)) {
|
||||
throw new Error("metrics not found")
|
||||
}
|
||||
const fullPath = [this.storagePath, app, dataName, `${chunk}.mtlv`].join("/")
|
||||
const fullPath = [this.storagePath, app, dataName, `${chunk}.mtlv`].filter(s => !!s).join("/")
|
||||
const fileData = fs.readFileSync(fullPath)
|
||||
return { fileData, chunks: this.meta[app][dataName].chunks }
|
||||
}
|
||||
|
|
@ -51,9 +51,9 @@ export class TlvFilesStorage {
|
|||
const data: LatestData = {}
|
||||
this.foreachFile((app, dataName, tlvFiles) => {
|
||||
if (tlvFiles.length === 0) { return }
|
||||
const methodPath = [this.storagePath, app, dataName].join("/")
|
||||
const methodPath = [this.storagePath, app, dataName].filter(s => !!s).join("/")
|
||||
const latest = tlvFiles[tlvFiles.length - 1]
|
||||
const tlvFile = [methodPath, `${latest}.mtlv`].join("/")
|
||||
const tlvFile = [methodPath, `${latest}.mtlv`].filter(s => !!s).join("/")
|
||||
const tlv = fs.readFileSync(tlvFile)
|
||||
const decoded = decodeListTLV(parseTLV(tlv))
|
||||
if (!data[app]) {
|
||||
|
|
@ -80,13 +80,13 @@ export class TlvFilesStorage {
|
|||
this.pending = {}
|
||||
const apps = Object.keys(tosync)
|
||||
apps.map(app => {
|
||||
const appPath = [this.storagePath, app].join("/")
|
||||
const appPath = [this.storagePath, app].filter(s => !!s).join("/")
|
||||
if (!fs.existsSync(appPath)) {
|
||||
fs.mkdirSync(appPath, { recursive: true });
|
||||
}
|
||||
const dataNames = Object.keys(tosync[app])
|
||||
dataNames.map(dataName => {
|
||||
const dataPath = [appPath, dataName].join("/")
|
||||
const dataPath = [appPath, dataName].filter(s => !!s).join("/")
|
||||
if (!fs.existsSync(dataPath)) {
|
||||
fs.mkdirSync(dataPath, { recursive: true });
|
||||
}
|
||||
|
|
@ -95,7 +95,7 @@ export class TlvFilesStorage {
|
|||
const chunks = meta.chunks.length > 0 ? meta.chunks : [0]
|
||||
const latest = chunks[chunks.length - 1]
|
||||
const tlv = encodeTLV(encodeListTLV(data.tlvs))
|
||||
const tlvFile = [dataPath, `${latest}.mtlv`].join("/")
|
||||
const tlvFile = [dataPath, `${latest}.mtlv`].filter(s => !!s).join("/")
|
||||
fs.appendFileSync(tlvFile, Buffer.from(tlv))
|
||||
if (fs.lstatSync(tlvFile).size > chunkSizeBytes) {
|
||||
this.updateMeta(app, dataName, [...chunks, latest + 1])
|
||||
|
|
@ -131,13 +131,13 @@ export class TlvFilesStorage {
|
|||
}
|
||||
const apps = fs.readdirSync(this.storagePath)
|
||||
apps.forEach(appDir => {
|
||||
const appPath = [this.storagePath, appDir].join("/")
|
||||
const appPath = [this.storagePath, appDir].filter(s => !!s).join("/")
|
||||
if (!fs.lstatSync(appPath).isDirectory()) {
|
||||
return
|
||||
}
|
||||
const dataNames = fs.readdirSync(appPath)
|
||||
dataNames.forEach(dataName => {
|
||||
const dataPath = [appPath, dataName].join("/")
|
||||
const dataPath = [appPath, dataName].filter(s => !!s).join("/")
|
||||
if (!fs.lstatSync(dataPath).isDirectory()) {
|
||||
return
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue