Skip to content

Commit ea23ed9

Browse files
committed
feat: support single files in user-access
1 parent 70c228e commit ea23ed9

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

packages/user-access/src/index.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import { isSudo, execRootSync } from "admina"
2+
import { statSync } from "fs"
23

34
/**
4-
* Give the user access to the given path and its sub-directories. It changes the owner to the SUDO_USER. This allows
5-
* the user to use the folder without sudo
5+
* Give the user access to the given path (and its sub-directories if a directory). It changes the owner to the
6+
* SUDO_USER. This allows the user to use the folder without sudo
67
*
78
* @param path The path to give the user access to
89
*/
@@ -12,6 +13,11 @@ export function giveUserAccess(path: string) {
1213
isSudo() &&
1314
process.env.SUDO_USER !== undefined
1415
) {
15-
execRootSync("chown", ["-R", process.env.SUDO_USER, path], { cwd: path, stdio: "inherit", shell: true })
16+
const isDirectory = statSync(path).isDirectory()
17+
execRootSync("chown", [...(isDirectory ? ["-R"] : []), process.env.SUDO_USER, path], {
18+
cwd: path,
19+
stdio: "inherit",
20+
shell: true,
21+
})
1622
}
1723
}

0 commit comments

Comments
 (0)