@samitouri / QOSami-HFS / commits / 762e4f58

fix: (regression beta) EACCES errors starting after `sudo npm i -g`

Massimo Melina committed Jul 7, 2024 at 18:52 UTC 762e4f581b4d2f713199969f75f01024c9e8def1
1 file changed +5 -3
src/plugins.ts
+5 -3
@@ -16,7 +16,7 @@ import { DirEntry } from './api.get_file_list'
16 import { VfsNode } from './vfs'
17 import { serveFile } from './serveFile'
18 import events from './events'
19 -import { mkdir, readFile } from 'fs/promises'
19 +import { mkdir, readFile, rename } from 'fs/promises'
20 import { existsSync, mkdirSync } from 'fs'
21 import { getConnections } from './connections'
22 import { dirname, join, resolve } from 'path'
@@ -323,7 +323,7 @@ export async function rescan() {
323 console.debug('scanning plugins')
324 const patterns = [PATH + '/*']
325 if (APP_PATH !== process.cwd())
326 - patterns.push(adjustStaticPathForGlob(APP_PATH) + '/' + patterns[0])
326 + patterns.unshift(adjustStaticPathForGlob(APP_PATH) + '/' + patterns[0]) // first search bundled plugins, because otherwise they won't be loaded because of the folders with same name in .hfs/plugins (used for storage)
327 const met = []
328 for (const { path, dirent } of await glob(patterns, { onlyFiles: false, suppressErrors: true, objectMode: true })) {
329 if (!dirent.isDirectory() || path.endsWith(DISABLING_SUFFIX)) continue
@@ -415,7 +415,9 @@ function watchPlugin(id: string, path: string) {
415
416 await alreadyRunning?.unload(true)
417 console.debug("starting plugin", id)
418 - const storageDir = resolve(module, '..', STORAGE_FOLDER) + (IS_WINDOWS ? '\\' : '/')
418 + const storageDir = resolve(PATH, id, STORAGE_FOLDER) + (IS_WINDOWS ? '\\' : '/')
419 + if (!module.startsWith(process.cwd())) //legacy pre-0.53.0, bundled plugins' storageDir was not under cwd
420 + await rename(resolve(module, '..', STORAGE_FOLDER), storageDir).catch(() => {})
421 await mkdir(storageDir, { recursive: true })
422 const dbs: KvStorage[] = []
423 await initPlugin(pluginData, {