admin/plugins: early check of disk permissions when updating
Massimo Melina committed
Aug 1, 2025 at 12:15 UTC
5c11764b0c4e3f38ddb91e69718e66a5d40cd112
1 file changed
+4
-3
src/github.ts
+4
-3
@@ -15,9 +15,9 @@ import {
15
HFS_REPO, HFS_REPO_BRANCH, HTTP_BAD_REQUEST, HTTP_CONFLICT, HTTP_FORBIDDEN, HTTP_NOT_ACCEPTABLE,
16
HTTP_SERVER_ERROR, VERSION
17
} from './const'
18
-import { readFile, rename, rm, writeFile } from 'fs/promises'
18
+import { access, readFile, rename, rm, writeFile } from 'fs/promises'
19
import { join } from 'path'
20
-import { readFileSync } from 'fs'
20
+import fs from 'fs'
21
import { storedMap } from './persistence'
22
import { argv } from './argv'
23
@@ -82,6 +82,7 @@ export async function downloadPlugin(repo: Repo, { branch='', overwrite=false }=
82
83
async function go(url: string, folder: string, zipRoot: string) {
84
const installPath = PLUGINS_PATH + '/' + folder
85
+ await access(installPath, fs.constants.W_OK) // early check for permission
86
const tempInstallPath = installPath + '-installing' + DISABLING_SUFFIX
87
const foldersToCopy = [ // from longer to shorter, so we first test the longer
88
zipRoot + '-' + process.platform + '-' + process.arch,
@@ -255,7 +256,7 @@ const cachedCentralInfo = storedMap.singleSync('cachedCentralInfo', '') // persi
256
export let blacklistedInstalledPlugins: string[] = []
257
// centralized hosted information, to be used as little as possible
258
const FN = 'central.json'
258
-let builtIn = JSON.parse(readFileSync(join(__dirname, '..', FN), 'utf8'))
259
+let builtIn = JSON.parse(fs.readFileSync(join(__dirname, '..', FN), 'utf8'))
260
export const getProjectInfo = debounceAsync(
261
() => argv.central === false ? Promise.resolve(builtIn) : readGithubFile(`${HFS_REPO}/${HFS_REPO_BRANCH}/${FN}`)
262
.then(JSON.parse, () => null)