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

rimraf removes files not owned by the user #98

Closed
radare opened this issue Jan 19, 2016 · 2 comments
Closed

rimraf removes files not owned by the user #98

radare opened this issue Jan 19, 2016 · 2 comments

Comments

@radare
Copy link

radare commented Jan 19, 2016

Default behaviour in the unix rm is not to remove files that are not owned by the user or doesn't have permissions for it by default. rimraf removes them without reporting this which can be dangerous or maybe undesired in some situations.

This is the test case, which i wrote for the rmdir npm module:

dreamerslab/node.rmdir#11

But using this index.js:

require('rimraf')('foo', console.log);
@yoshuawuyts
Copy link

rimraf is like unix rm -rf; does appending the -f flag also report errors?

Only have a single user on all my machines; would've verified it directly otherwise.

@isaacs
Copy link
Owner

isaacs commented Jan 20, 2016

If you don't have permission to remove the dir, then it'll error.

If you don't own it, but you do have permission to remove it, then it will just silently remove it, like rm -rf. That's what the f says.

This is 100% working exactly as designed.

$ mkdir -p foo/bar/baz

$ sudo chown nobody foo

$ node -p 'require("rimraf").sync("foo")'
/Users/isaacs/dev/js/rimraf/rimraf.js:304
        throw er
        ^

Error: ENOTEMPTY: directory not empty, rmdir 'foo'
    at Error (native)
    at Object.fs.rmdirSync (fs.js:763:18)
    at rmkidsSync (/Users/isaacs/dev/js/rimraf/rimraf.js:334:11)
    at rmdirSync (/Users/isaacs/dev/js/rimraf/rimraf.js:324:7)
    at Function.rimrafSync [as sync] (/Users/isaacs/dev/js/rimraf/rimraf.js:295:9)
    at [eval]:1:19
    at Object.exports.runInThisContext (vm.js:54:17)
    at Object.<anonymous> ([eval]-wrapper:6:22)
    at Module._compile (module.js:434:26)
    at node.js:566:27

$ sudo node -p 'require("rimraf").sync("foo")'
undefined

$ ls -laF foo
ls: foo: No such file or directory

@isaacs isaacs closed this as completed Jan 20, 2016
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

3 participants