Skip to content
This repository has been archived by the owner on Aug 11, 2022. It is now read-only.

npm cache clear can delete a empty $HOME #14012

Closed
silverwind opened this issue Sep 19, 2016 · 11 comments
Closed

npm cache clear can delete a empty $HOME #14012

silverwind opened this issue Sep 19, 2016 · 11 comments

Comments

@silverwind
Copy link

silverwind commented Sep 19, 2016

What's going wrong?

When $HOME is empty, npm cache clear will delete it after purging all caches. It should probably not navigate outside the cache directory.

How can the CLI team reproduce the problem?

Use this Dockerfile and run docker build --no-cache=true -t cacheclear .:

FROM mhart/alpine-node:latest
WORKDIR /
RUN npm i -g rimraf && stat /root && npm cache clear --loglevel silly && stat /root
output including `vacuum-fs removing /root`
npm info it worked if it ends with ok
npm verb cli [ '/usr/bin/node',
npm verb cli   '/usr/bin/npm',
npm verb cli   'cache',
npm verb cli   'clear',
npm verb cli   '--loglevel',
npm verb cli   'silly' ]
npm info using npm@3.10.7
npm info using node@v6.6.0
npm sill ls normalized .
npm sill gentlyRm /root/.npm/_locks is being purged
npm verb gentlyRm don't care about contents; nuking /root/.npm/_locks
npm sill gentlyRm /root/.npm/balanced-match is being purged
npm verb gentlyRm don't care about contents; nuking /root/.npm/balanced-match
npm sill gentlyRm /root/.npm/brace-expansion is being purged
npm verb gentlyRm don't care about contents; nuking /root/.npm/brace-expansion
npm sill gentlyRm /root/.npm/concat-map is being purged
npm verb gentlyRm don't care about contents; nuking /root/.npm/concat-map
npm sill gentlyRm /root/.npm/fs.realpath is being purged
npm verb gentlyRm don't care about contents; nuking /root/.npm/fs.realpath
npm sill gentlyRm /root/.npm/glob is being purged
npm verb gentlyRm don't care about contents; nuking /root/.npm/glob
npm sill gentlyRm /root/.npm/inflight is being purged
npm verb gentlyRm don't care about contents; nuking /root/.npm/inflight
npm sill gentlyRm /root/.npm/inherits is being purged
npm verb gentlyRm don't care about contents; nuking /root/.npm/inherits
npm sill gentlyRm /root/.npm/minimatch is being purged
npm verb gentlyRm don't care about contents; nuking /root/.npm/minimatch
npm sill gentlyRm /root/.npm/once is being purged
npm verb gentlyRm don't care about contents; nuking /root/.npm/once
npm sill gentlyRm /root/.npm/path-is-absolute is being purged
npm verb gentlyRm don't care about contents; nuking /root/.npm/path-is-absolute
npm sill gentlyRm /root/.npm/registry.npmjs.org is being purged
npm verb gentlyRm don't care about contents; nuking /root/.npm/registry.npmjs.org
npm sill gentlyRm /root/.npm/rimraf is being purged
npm verb gentlyRm don't care about contents; nuking /root/.npm/rimraf
npm sill gentlyRm /root/.npm/wrappy is being purged
npm verb gentlyRm don't care about contents; nuking /root/.npm/wrappy
npm sill vacuum-fs purging /root/.npm/_locks
npm sill vacuum-fs purging /root/.npm/balanced-match
npm sill vacuum-fs purging /root/.npm/brace-expansion
npm sill vacuum-fs purging /root/.npm/concat-map
npm sill vacuum-fs purging /root/.npm/fs.realpath
npm sill vacuum-fs purging /root/.npm/glob
npm sill vacuum-fs purging /root/.npm/inherits
npm sill vacuum-fs purging /root/.npm/inflight
npm sill vacuum-fs purging /root/.npm/minimatch
npm sill vacuum-fs purging /root/.npm/path-is-absolute
npm sill vacuum-fs purging /root/.npm/once
npm sill vacuum-fs purging /root/.npm/registry.npmjs.org
npm sill vacuum-fs purging /root/.npm/rimraf
npm sill vacuum-fs purging /root/.npm/wrappy
npm sill vacuum-fs quitting because other entries in /root/.npm
npm sill vacuum-fs quitting because other entries in /root/.npm
npm sill vacuum-fs quitting because other entries in /root/.npm
npm sill vacuum-fs quitting because other entries in /root/.npm
npm sill vacuum-fs quitting because other entries in /root/.npm
npm sill vacuum-fs removing /root/.npm
npm sill vacuum-fs removing /root/.npm
npm sill vacuum-fs removing /root/.npm
npm sill vacuum-fs removing /root/.npm
npm sill vacuum-fs removing /root/.npm
npm sill vacuum-fs removing /root/.npm
npm sill vacuum-fs removing /root/.npm
npm sill vacuum-fs removing /root/.npm
npm sill vacuum-fs removing /root/.npm
npm sill vacuum-fs quitting because lost the race to remove /root/.npm
npm sill vacuum-fs quitting because lost the race to remove /root/.npm
npm sill vacuum-fs quitting because lost the race to remove /root/.npm
npm sill vacuum-fs quitting because lost the race to remove /root/.npm
npm sill vacuum-fs quitting because lost the race to remove /root/.npm
npm sill vacuum-fs quitting because lost the race to remove /root/.npm
npm sill vacuum-fs quitting because lost the race to remove /root/.npm
npm sill vacuum-fs removing /root
npm sill vacuum-fs finished vacuuming up to /
npm verb exit [ 0, true ]
npm info ok
@othiym23
Copy link
Contributor

Thanks for filing this! We have logic in lib/utils/gently-rm.js specifically to prevent exactly this situation, but for whatever reason it's getting confused (which is kind of the story of gently-rm). This is a severe bug – user software should never be removing $HOME – but given its rarity and the other things we have in flight, it may be a little while until the team gets to it.

@lholmquist
Copy link
Contributor

@silverwind what is the version of npm that you were testing this with?

i did docker run -it mhart/alpine-node:latest /bin/sh then ran those commands from "RUN" part of the dockerfile manually. and this was at the end of the log(after the cache clearing):

npm sill vacuum-fs quitting because other entries in /root

npm version was 3.10.8 when i just tried

@silverwind
Copy link
Author

silverwind commented Oct 7, 2016

I think it was 3.10.7. You're not seeing it because when you enter the container, you will inevitably create dotfiles in $HOME and vacuum will only delete $HOME if it's totally empty. Try with my Dockerfile or cd to / and manually empty out $HOME by running rm -rf ~/. before npm cache clear.

@lholmquist
Copy link
Contributor

@silverwind ah, yea, got it now. that makes sense when i was running it "manually"

@legodude17
Copy link
Contributor

Can you provide your npm.prefix in that container? It would help with figuring this out.

@silverwind
Copy link
Author

$ docker run -it mhart/alpine-node:latest /bin/sh
/ # npm i -g rimraf > /dev/null && npm uninstall -g rimraf > /dev/null
/ # npm get prefix
/usr
/ # rm ~/.ash_history && npm cache clear
/ # ls /root
ls: /root: No such file or directory

@helio-frota
Copy link

helio-frota commented Nov 23, 2016

Yes, removes the directory of the root user.
And may remove home of normal users ( if given permissions ).

Running on virtualbox with ubuntu 16x:

as root:

root@npmbox:~# pwd
/root
root@npmbox:~# ls -a
.  ..
root@npmbox:~# cd /
root@npmbox:/# npm i -g rimraf && npm cache clear --loglevel silly
/usr/local/bin/rimraf -> /usr/local/lib/node_modules/rimraf/bin.js
/usr/local/lib
└── rimraf@2.5.4 

  File: '/root'
  Size: 4096      	Blocks: 8          IO Block: 4096   directory
Device: 801h/2049d	Inode: 270485      Links: 3
Access: (0755/drwxr-xr-x)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2016-11-23 15:38:59.002309573 -0300
Modify: 2016-11-23 15:39:26.278135753 -0300
Change: 2016-11-23 15:39:26.278135753 -0300
 Birth: -
npm info it worked if it ends with ok
npm verb cli [ '/usr/bin/nodejs',
npm verb cli   '/usr/bin/npm',
npm verb cli   'cache',
npm verb cli   'clear',
npm verb cli   '--loglevel',
npm verb cli   'silly' ]
npm info using npm@3.5.2
npm info using node@v4.2.6
npm sill ls normalized .
npm sill gentlyRm /root/.npm/_locks is being purged 
npm verb gentlyRm don't care about contents; nuking /root/.npm/_locks
npm sill gentlyRm /root/.npm/balanced-match is being purged 
npm verb gentlyRm don't care about contents; nuking /root/.npm/balanced-match
npm sill gentlyRm /root/.npm/brace-expansion is being purged 
npm verb gentlyRm don't care about contents; nuking /root/.npm/brace-expansion
npm sill gentlyRm /root/.npm/concat-map is being purged 
npm verb gentlyRm don't care about contents; nuking /root/.npm/concat-map
npm sill gentlyRm /root/.npm/fs.realpath is being purged 
npm verb gentlyRm don't care about contents; nuking /root/.npm/fs.realpath
npm sill gentlyRm /root/.npm/glob is being purged 
npm verb gentlyRm don't care about contents; nuking /root/.npm/glob
npm sill gentlyRm /root/.npm/inflight is being purged 
npm verb gentlyRm don't care about contents; nuking /root/.npm/inflight
npm sill gentlyRm /root/.npm/inherits is being purged 
npm verb gentlyRm don't care about contents; nuking /root/.npm/inherits
npm sill gentlyRm /root/.npm/minimatch is being purged 
npm verb gentlyRm don't care about contents; nuking /root/.npm/minimatch
npm sill gentlyRm /root/.npm/once is being purged 
npm verb gentlyRm don't care about contents; nuking /root/.npm/once
npm sill gentlyRm /root/.npm/path-is-absolute is being purged 
npm verb gentlyRm don't care about contents; nuking /root/.npm/path-is-absolute
npm sill gentlyRm /root/.npm/registry.npmjs.org is being purged 
npm verb gentlyRm don't care about contents; nuking /root/.npm/registry.npmjs.org
npm sill gentlyRm /root/.npm/rimraf is being purged 
npm verb gentlyRm don't care about contents; nuking /root/.npm/rimraf
npm sill gentlyRm /root/.npm/wrappy is being purged 
npm verb gentlyRm don't care about contents; nuking /root/.npm/wrappy
npm sill vacuum-fs purging /root/.npm/_locks
npm sill vacuum-fs purging /root/.npm/balanced-match
npm sill vacuum-fs purging /root/.npm/brace-expansion
npm sill vacuum-fs purging /root/.npm/concat-map
npm sill vacuum-fs purging /root/.npm/fs.realpath
npm sill vacuum-fs purging /root/.npm/glob
npm sill vacuum-fs purging /root/.npm/inflight
npm sill vacuum-fs purging /root/.npm/inherits
npm sill vacuum-fs purging /root/.npm/minimatch
npm sill vacuum-fs purging /root/.npm/once
npm sill vacuum-fs purging /root/.npm/path-is-absolute
npm sill vacuum-fs purging /root/.npm/registry.npmjs.org
npm sill vacuum-fs purging /root/.npm/rimraf
npm sill vacuum-fs purging /root/.npm/wrappy
npm sill vacuum-fs quitting because other entries in /root/.npm
npm sill vacuum-fs quitting because other entries in /root/.npm
npm sill vacuum-fs removing /root/.npm
npm sill vacuum-fs removing /root/.npm
npm sill vacuum-fs removing /root/.npm
npm sill vacuum-fs removing /root/.npm
npm sill vacuum-fs removing /root/.npm
npm sill vacuum-fs removing /root/.npm
npm sill vacuum-fs removing /root/.npm
npm sill vacuum-fs removing /root/.npm
npm sill vacuum-fs removing /root/.npm
npm sill vacuum-fs removing /root/.npm
npm sill vacuum-fs removing /root/.npm
npm sill vacuum-fs removing /root/.npm
npm sill vacuum-fs quitting because lost the race to remove /root/.npm
npm sill vacuum-fs quitting because lost the race to remove /root/.npm
npm sill vacuum-fs quitting because lost the race to remove /root/.npm
npm sill vacuum-fs quitting because lost the race to remove /root/.npm
npm sill vacuum-fs quitting because lost the race to remove /root/.npm
npm sill vacuum-fs quitting because lost the race to remove /root/.npm
npm sill vacuum-fs quitting because lost the race to remove /root/.npm
npm sill vacuum-fs quitting because lost the race to remove /root/.npm
npm sill vacuum-fs quitting because lost the race to remove /root/.npm
npm sill vacuum-fs quitting because lost the race to remove /root/.npm
npm sill vacuum-fs quitting because lost the race to remove /root/.npm
npm sill vacuum-fs removing /root
npm sill vacuum-fs finished vacuuming up to /
npm verb exit [ 0, true ]
npm info ok 
stat: cannot stat '/root': No such file or directory

as normal user:

one@npmbox:~$ npm i -g rimraf && npm cache clear --loglevel silly
/usr/local/bin/rimraf -> /usr/local/lib/node_modules/rimraf/bin.js
/usr/local/lib
└── rimraf@2.5.4 

npm info it worked if it ends with ok
npm verb cli [ '/usr/bin/nodejs',
npm verb cli   '/usr/bin/npm',
npm verb cli   'cache',
npm verb cli   'clear',
npm verb cli   '--loglevel',
npm verb cli   'silly' ]
npm info using npm@3.5.2
npm info using node@v4.2.6
npm verb config Skipping project config: /home/one/.npmrc. (matches userconfig)
npm sill ls normalized .
npm sill gentlyRm /home/one/.npm/_locks is being purged 
npm verb gentlyRm don't care about contents; nuking /home/one/.npm/_locks
npm sill gentlyRm /home/one/.npm/balanced-match is being purged 
npm verb gentlyRm don't care about contents; nuking /home/one/.npm/balanced-match
npm sill gentlyRm /home/one/.npm/brace-expansion is being purged 
npm verb gentlyRm don't care about contents; nuking /home/one/.npm/brace-expansion
npm sill gentlyRm /home/one/.npm/concat-map is being purged 
npm verb gentlyRm don't care about contents; nuking /home/one/.npm/concat-map
npm sill gentlyRm /home/one/.npm/fs.realpath is being purged 
npm verb gentlyRm don't care about contents; nuking /home/one/.npm/fs.realpath
npm sill gentlyRm /home/one/.npm/glob is being purged 
npm verb gentlyRm don't care about contents; nuking /home/one/.npm/glob
npm sill gentlyRm /home/one/.npm/inflight is being purged 
npm verb gentlyRm don't care about contents; nuking /home/one/.npm/inflight
npm sill gentlyRm /home/one/.npm/inherits is being purged 
npm verb gentlyRm don't care about contents; nuking /home/one/.npm/inherits
npm sill gentlyRm /home/one/.npm/minimatch is being purged 
npm verb gentlyRm don't care about contents; nuking /home/one/.npm/minimatch
npm sill gentlyRm /home/one/.npm/once is being purged 
npm verb gentlyRm don't care about contents; nuking /home/one/.npm/once
npm sill gentlyRm /home/one/.npm/path-is-absolute is being purged 
npm verb gentlyRm don't care about contents; nuking /home/one/.npm/path-is-absolute
npm sill gentlyRm /home/one/.npm/registry.npmjs.org is being purged 
npm verb gentlyRm don't care about contents; nuking /home/one/.npm/registry.npmjs.org
npm sill gentlyRm /home/one/.npm/rimraf is being purged 
npm verb gentlyRm don't care about contents; nuking /home/one/.npm/rimraf
npm sill gentlyRm /home/one/.npm/wrappy is being purged 
npm verb gentlyRm don't care about contents; nuking /home/one/.npm/wrappy
npm sill vacuum-fs purging /home/one/.npm/_locks
npm sill vacuum-fs purging /home/one/.npm/balanced-match
npm sill vacuum-fs purging /home/one/.npm/brace-expansion
npm sill vacuum-fs purging /home/one/.npm/concat-map
npm sill vacuum-fs purging /home/one/.npm/fs.realpath
npm sill vacuum-fs purging /home/one/.npm/glob
npm sill vacuum-fs purging /home/one/.npm/inflight
npm sill vacuum-fs purging /home/one/.npm/inherits
npm sill vacuum-fs purging /home/one/.npm/minimatch
npm sill vacuum-fs purging /home/one/.npm/once
npm sill vacuum-fs purging /home/one/.npm/path-is-absolute
npm sill vacuum-fs purging /home/one/.npm/registry.npmjs.org
npm sill vacuum-fs purging /home/one/.npm/rimraf
npm sill vacuum-fs purging /home/one/.npm/wrappy
npm sill vacuum-fs quitting because other entries in /home/one/.npm
npm sill vacuum-fs quitting because other entries in /home/one/.npm
npm sill vacuum-fs removing /home/one/.npm
npm sill vacuum-fs removing /home/one/.npm
npm sill vacuum-fs removing /home/one/.npm
npm sill vacuum-fs removing /home/one/.npm
npm sill vacuum-fs removing /home/one/.npm
npm sill vacuum-fs removing /home/one/.npm
npm sill vacuum-fs removing /home/one/.npm
npm sill vacuum-fs removing /home/one/.npm
npm sill vacuum-fs removing /home/one/.npm
npm sill vacuum-fs removing /home/one/.npm
npm sill vacuum-fs removing /home/one/.npm
npm sill vacuum-fs removing /home/one/.npm
npm sill vacuum-fs quitting because lost the race to remove /home/one/.npm
npm sill vacuum-fs quitting because lost the race to remove /home/one/.npm
npm sill vacuum-fs quitting because lost the race to remove /home/one/.npm
npm sill vacuum-fs quitting because lost the race to remove /home/one/.npm
npm sill vacuum-fs quitting because lost the race to remove /home/one/.npm
npm sill vacuum-fs quitting because lost the race to remove /home/one/.npm
npm sill vacuum-fs quitting because lost the race to remove /home/one/.npm
npm sill vacuum-fs quitting because lost the race to remove /home/one/.npm
npm sill vacuum-fs quitting because lost the race to remove /home/one/.npm
npm sill vacuum-fs quitting because lost the race to remove /home/one/.npm
npm sill vacuum-fs quitting because lost the race to remove /home/one/.npm
npm sill vacuum-fs removing /home/one
npm sill vacuum-fs unable to remove /home/one due to EACCES: permission denied, rmdir '/home/one'
npm verb stack Error: EACCES: permission denied, rmdir '/home/one'
npm verb stack     at Error (native)
npm verb cwd /home/one
npm ERR! Linux 4.4.0-31-generic
npm ERR! argv "/usr/bin/nodejs" "/usr/bin/npm" "cache" "clear" "--loglevel" "silly"
npm ERR! node v4.2.6
npm ERR! npm  v3.5.2
npm ERR! path /home/one
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall rmdir

npm ERR! Error: EACCES: permission denied, rmdir '/home/one'
npm ERR!     at Error (native)
npm ERR!  { [Error: EACCES: permission denied, rmdir '/home/one']
npm ERR!   errno: -13,
npm ERR!   code: 'EACCES',
npm ERR!   syscall: 'rmdir',
npm ERR!   path: '/home/one' }
npm ERR! 
npm ERR! Please try running this command again as root/Administrator.
npm verb exit [ -13, true ]

npm ERR! Please include the following file with any support request:
npm ERR!     /home/one/npm-debug.log

@helio-frota
Copy link

And I noticed that when the base is the same as the path (branch / directory)
fs-vacuum removes the base as well.
I can not say that this is the problem, it may be a feature of fs-vaccum.

small piece of code based on https://github.com/npm/fs-vacuum#usage :

var options = {
  base  : "/home/four",   <-----------
  purge : true,
  log   : logger.silly.bind(logger, "myCleanup")
};
vacuum("/home/four/", options, function (error) {

@legodude17
Copy link
Contributor

Due to this, it may be said that his issue should be moved to npm/fs-vacuum.

On Wed, Nov 23, 2016 at 11:25 AM, helio-frota notifications@github.com
wrote:

And I noticed that when the base is the same as the path (branch /
directory)
fs-vacuum removes the base as well.
I can not say that this is the problem, it may be a feature of fs-vaccum.

small piece of code based on https://github.com/npm/fs-vacuum#usage :

var options = {
base : "/home/four", <-----------
purge : true,
log : logger.silly.bind(logger, "myCleanup")
};
vacuum("/home/four/", options, function (error) {


You are receiving this because you commented.
Reply to this email directly, view it on GitHub
#14012 (comment), or mute
the thread
https://github.com/notifications/unsubscribe-auth/AKr56GGHTDwCfbgtF2SIJwkoQ49ZIUbaks5rBJNFgaJpZM4KA7TA
.

@helio-frota
Copy link

true, also I fixed 👍

...
npm sill vacuum-fs quitting because lost the race to remove /root/.npm
npm sill vacuum-fs quitting because lost the race to remove /root/.npm
npm sill vacuum-fs quitting because can't remove home directory /root
npm verb exit [ 0, true ]
npm info ok 
root@npmbox:/# cd root/
root@npmbox:~# 

I'm going to send a PR to vacuum.

@legodude17
Copy link
Contributor

legodude17 commented Nov 23, 2016 via email

t3easy added a commit to t3easy/docker-surf that referenced this issue Jan 27, 2017
zkat added a commit that referenced this issue Mar 11, 2017
Fixes: #14012

PR-URL: npm/fs-vacuum#6
Credit: @helio-frota
Reviewed-By: @zkat
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants