avoid starting 2 instances on the same config folder
Massimo Melina committed
Feb 24, 2026 at 22:54 UTC
6765e56d78737fe24ad048309cc351ce5f509578
4 files changed
+13
-9
package.json
+1
-1
@@ -79,7 +79,7 @@
79
},
80
"dependencies": {
81
"@gregoranders/csv": "^0.0.13",
82
- "@rejetto/kvstorage": "^0.15.1",
82
+ "@rejetto/kvstorage": "^0.15.4",
83
"acme-client": "^5.4.0",
84
"busboy": "^1.6.0",
85
"crc-32": "^1.2.2",
src/commands.ts
+4
-4
@@ -36,7 +36,7 @@ if (!argv.updating && !showHelp) {
36
function clean() {
37
if (isClean) return
38
return cleaning ||= new Promise(resolve => {
39
- cursorTo(process.stdout, 0, undefined, () => {// we don't need to clean as long as the prompt is never longer then the printed line
39
+ cursorTo(process.stdout, 0, undefined, () => { // we don't need to clean as long as the prompt is never longer than the printed line
40
resolve()
41
cleaning = undefined
42
isClean = true
@@ -50,7 +50,7 @@ if (!argv.updating && !showHelp) {
50
consoleHint("this is an interactive console, you can enter commands")
51
printHintOnce = undefined as any // never more
52
}, 2000)
53
- _.each(console, (v: any, k) => {
53
+ setTimeout(() => _.each(console, (v: any, k) => {
54
if (!_.isFunction(v)) return
55
;(console as any)[k] = async (...args: any[]) => {
56
if (!quitting && tty)
@@ -61,7 +61,7 @@ if (!argv.updating && !showHelp) {
61
printHintOnce?.()
62
}
63
}
64
- })
64
+ }), 1000) // avoid messing in making console methods async too soon and so preventing fatal errors to be printed before process.exit – TODO investigate how to avoid this async thing at all
65
66
}
67
catch {
@@ -136,7 +136,7 @@ const commands = {
136
params: '[<key-mask>]',
137
cb(key='*') {
138
const matcher = makeMatcher(key)
139
- const filtered = _.pickBy(getWholeConfig({}), (v, k) => matcher(k))
139
+ const filtered = _.pickBy(getWholeConfig({}), (_v, k) => matcher(k))
140
console.log('\n' + yaml.stringify(filtered, { lineWidth:1000 }).trim())
141
}
142
},
src/fileAttr.ts
+4
-3
@@ -1,5 +1,4 @@
1
import { KvStorage } from '@rejetto/kvstorage'
2
-import { existsSync } from 'fs'
2
import { promisify } from 'util'
3
import { access } from 'fs/promises'
4
import { try_, tryJson } from './cross'
@@ -16,8 +15,10 @@ const fsx = try_(() => {
15
const fileAttrDb = new KvStorage({ defaultPutDelay: 1000, maxPutDelay: 5000 })
16
onProcessExit(() => fileAttrDb.flush())
17
const FN = 'file-attr.kv'
19
-if (existsSync(FN))
20
- fileAttrDb.open(FN)
18
+access(FN).then(() =>
19
+ fileAttrDb.open(FN).catch(e =>
20
+ console.error(String(e))),
21
+ () => {})
22
const FILE_ATTR_PREFIX = 'user.hfs.' // user. prefix to be linux compatible
23
24
/* @param v must be JSON-able or undefined */
src/persistence.ts
+4
-1
@@ -9,5 +9,8 @@ export const storedMap = new KvStorage({
9
rewriteLater: true,
10
bucketThreshold: 10_000,
11
})
12
-storedMap.open('data.kv')
12
+storedMap.open('data.kv').catch(e => {
13
+ console.error(e?.message.includes('locked') ? `Check if another HFS is running on the same config folder – ${e.message}` : String(e))
14
+ process.exit(3)
15
+})
16
onProcessExit(() => storedMap.flush())