feat: support single files in user-access

This commit is contained in:
Amin Yahyaabadi 2022-11-20 23:02:23 -08:00
parent 70c228ecc9
commit ea23ed92ca
1 changed files with 9 additions and 3 deletions

View File

@ -1,8 +1,9 @@
import { isSudo, execRootSync } from "admina" import { isSudo, execRootSync } from "admina"
import { statSync } from "fs"
/** /**
* Give the user access to the given path and its sub-directories. It changes the owner to the SUDO_USER. This allows * Give the user access to the given path (and its sub-directories if a directory). It changes the owner to the
* the user to use the folder without sudo * SUDO_USER. This allows the user to use the folder without sudo
* *
* @param path The path to give the user access to * @param path The path to give the user access to
*/ */
@ -12,6 +13,11 @@ export function giveUserAccess(path: string) {
isSudo() && isSudo() &&
process.env.SUDO_USER !== undefined process.env.SUDO_USER !== undefined
) { ) {
execRootSync("chown", ["-R", process.env.SUDO_USER, path], { cwd: path, stdio: "inherit", shell: true }) const isDirectory = statSync(path).isDirectory()
execRootSync("chown", [...(isDirectory ? ["-R"] : []), process.env.SUDO_USER, path], {
cwd: path,
stdio: "inherit",
shell: true,
})
} }
} }