Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

spawn-wrap causes failure due to unwritable homedir #951

Closed
Krinkle opened this issue Dec 13, 2018 · 1 comment
Closed

spawn-wrap causes failure due to unwritable homedir #951

Krinkle opened this issue Dec 13, 2018 · 1 comment

Comments

@Krinkle
Copy link
Contributor

Krinkle commented Dec 13, 2018

Observed Behavior

When using nyc as a system user that is not allowed to write to its home directory (e.g. HOME=/nonexistent), a command like nyc qunit test or some other use of nyc fails as follows:

+ npm run-script test

> nyc -r text -r html qunit test/

/src/node_modules/nyc/node_modules/mkdirp/index.js:90
                    throw err0;
                    ^

Error: EACCES: permission denied, mkdir '/nonexistent'
    at Error (native)
    at Object.fs.mkdirSync (fs.js:923:18)
    at sync (/src/node_modules/nyc/node_modules/mkdirp/index.js:71:13)
    at Function.sync (/src/node_modules/nyc/node_modules/mkdirp/index.js:77:24)
    at setup (/src/node_modules/nyc/node_modules/spawn-wrap/index.js:414:10)
    at wrap (/src/node_modules/nyc/node_modules/spawn-wrap/index.js:60:18)
    at Object.<anonymous> (/src/node_modules/nyc/bin/nyc.js:57:3)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)

I believe this is because spawn-wrap, unlike nyc, defaults to using a a sub directory of HOME as its working directory. Instead of using process.cwd() or TMPDIR etc, like nyc does.

This should probably be fixed upstream in spawn-wrap, but could be worked around in nyc by passing NYC_CWD as the workingDir parameter to the spawn-wrap function.

Currently (nyc@v13.1.0:/bin/nyc.js), nyc invokes spwan-wrap with two parameters, leaving the third parameter (workingDir) unset. In spawn-wrap (spawn-wrap:/index.js, this means it defaults to the setup of creating a directory in the os-home directory.

Node v11.4.0
npm 6.5.0
@Krinkle
Copy link
Contributor Author

Krinkle commented Dec 13, 2018

For the record, I was able to workaround this bug by forcing spawn-wrap to use a the current working directory instead, through the environment variable it considers:

	"@script.test": "# see spawn-wrap bug at https://github.com/istanbuljs/nyc/issues/951",
	"scripts": {
		"test": "SPAWN_WRAP_SHIM_ROOT=. nyc -r text -r html qunit test/"
	},

Krinkle added a commit to Krinkle/nyc that referenced this issue Jan 3, 2019
By default, spawn-wrap writes temporary files to HOME.
It used to be /tmp, but it changed that to HOME to support
environments that have 'noexec' flags set on their tmpfs mount.
Ref istanbuljs/spawn-wrap#3.

The problem with this is that nyc now no longer works in environments
without a (writable) home directory (e.g. the 'nobody' user on
Linux).

While it is fine to fallback to HOME, it should write elsewhere
if that is unavailable, and ideally in a way that doesn't require
every sysadmin or end-user to hardcode some environmnet variable
in their package.json specifically for nyc or spawn-wrap.

A common way to communicate this intent is with the XDG_CACHE_HOME
environment variable.

Fixes istanbuljs#951.
Krinkle added a commit to Krinkle/nyc that referenced this issue Jan 3, 2019
By default, spawn-wrap writes temporary files to HOME.
It used to be /tmp, but it changed that to HOME to support
environments that have 'noexec' flags set on their tmpfs mount.
Ref istanbuljs/spawn-wrap#3.

The problem with this is that nyc now no longer works in environments
without a (writable) home directory (e.g. the 'nobody' user on
Linux).

While it is fine to fallback to HOME, it should write elsewhere
if that is unavailable, and ideally in a way that doesn't require
every sysadmin or end-user to hardcode some environment variable
in their package.json specifically for nyc or spawn-wrap.

A common way to communicate this intent is with the XDG_CACHE_HOME
environment variable.

Fixes istanbuljs#951.
Krinkle added a commit to Krinkle/nyc that referenced this issue Jan 15, 2019
By default, spawn-wrap writes temporary files to HOME.
It used to be /tmp, but it changed that to HOME to support
environments that have 'noexec' flags set on their tmpfs mount.
Ref istanbuljs/spawn-wrap#3.

The problem with this is that nyc now no longer works in environments
without a (writable) home directory (e.g. the 'nobody' user on
Linux).

While it is fine to fallback to HOME, it should write elsewhere
if that is unavailable, and ideally in a way that doesn't require
every sysadmin or end-user to hardcode some environment variable
in their package.json specifically for nyc or spawn-wrap.

A common way to communicate this intent is with the XDG_CACHE_HOME
environment variable.

Fixes istanbuljs#951.
Krinkle added a commit to Krinkle/nyc that referenced this issue Jan 15, 2019
By default, spawn-wrap writes temporary files to HOME.
It used to be /tmp, but it changed that to HOME to support
environments that have 'noexec' flags set on their tmpfs mount.
Ref istanbuljs/spawn-wrap#3.

The problem with this is that nyc now no longer works in environments
without a (writable) home directory (e.g. the 'nobody' user on
Linux).

While it is fine to fallback to HOME, it should write elsewhere
if that is unavailable, and ideally in a way that doesn't require
every sysadmin or end-user to hardcode some environment variable
in their package.json specifically for nyc or spawn-wrap.

A common way to communicate this intent is with the XDG_CACHE_HOME
environment variable.

Fixes istanbuljs#951.
coreyfarrell pushed a commit that referenced this issue Jan 15, 2019
By default, spawn-wrap writes temporary files to HOME.
It used to be /tmp, but it changed that to HOME to support
environments that have 'noexec' flags set on their tmpfs mount.
Ref istanbuljs/spawn-wrap#3.

The problem with this is that nyc now no longer works in environments
without a (writable) home directory (e.g. the 'nobody' user on
Linux).

While it is fine to fallback to HOME, it should write elsewhere
if that is unavailable, and ideally in a way that doesn't require
every sysadmin or end-user to hardcode some environment variable
in their package.json specifically for nyc or spawn-wrap.

A common way to communicate this intent is with the XDG_CACHE_HOME
environment variable.

Fixes #951.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant