Skip to content

Commit

Permalink
handle execSync error
Browse files Browse the repository at this point in the history
  • Loading branch information
Vap0r1ze committed Mar 2, 2023
1 parent 70e1cc0 commit 9e0cd04
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,18 @@ export const configPathFn = (): string => {
if (process.env.XDG_CONFIG_HOME) {
return join(process.env.XDG_CONFIG_HOME, REPLUGGED_FOLDER_NAME);
}
if (realUser) {
// Get the home directory of the sudo user from /etc/passwd
const homeDir = execSync(`getent passwd ${realUser}`).toString('utf-8').split(':')[5];
return join(homeDir, ".config", REPLUGGED_FOLDER_NAME);
try {
if (realUser) {
// Get the home directory of the sudo user from /etc/passwd
const homeDir = execSync(`getent passwd ${realUser}`, {
stdio: [null, null, "ignore"],
})
.toString("utf-8")
.split(":")[5];
return join(homeDir, ".config", REPLUGGED_FOLDER_NAME);
}
} catch {
console.error("Could not get home directory of sudo/doas user. Falling back to $HOME.");
}
return join(process.env.HOME || "", ".config", REPLUGGED_FOLDER_NAME);
}
Expand Down

0 comments on commit 9e0cd04

Please sign in to comment.