Skip to content

Commit

Permalink
fix(cache): use process.geteuid() for virtual users (#376)
Browse files Browse the repository at this point in the history
Co-authored-by: Hiroki Osame <hiroki.osame@gmail.com>
  • Loading branch information
ST-DDT and privatenumber committed Nov 10, 2023
1 parent 9835a9f commit bf033b0
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/utils/transform/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,21 @@ const getTime = () => Math.floor(Date.now() / 1e8);

const tmpdir = os.tmpdir();
const noop = () => {};

/**
* Cache directory is based on the user's identifier
* to avoid permission issues when accessed by a different user
*/
const { geteuid } = process;
const userId = (
geteuid
// For Linux users with virtual users on CI (e.g. Docker)
? geteuid()

// Use username on Windows because it doesn't have id
: os.userInfo().username
);

class FileCache<ReturnType> extends Map<string, ReturnType> {
/**
* By using tmpdir, the expectation is for the OS to clean any files
Expand All @@ -22,9 +37,7 @@ class FileCache<ReturnType> extends Map<string, ReturnType> {
cacheDirectory = path.join(
// Write permissions by anyone
tmpdir,

// Write permissions only by current user
`tsx-${os.userInfo().uid}`,
`tsx-${userId}`,
);

// Maintained so we can remove it on Windows
Expand Down

0 comments on commit bf033b0

Please sign in to comment.