shelljs icon indicating copy to clipboard operation
shelljs copied to clipboard

I can't cd after I removed a sub-folder!?

Open melroy89 opened this issue 4 years ago • 1 comments

Node version (or tell us if you're using electron or some other framework): 12.18

ShellJS version (the most recent version/Github branch you see the bug on): 0.8.4

Operating system: Linux

Description of the bug:

When I'm in the folder (via cd) that I want to remove and I executed the shell.rm() the folder. like /tmp/testfolder. I can't change the directory towards that root-folder, so in this case: shell.cd('/tmp') won't work anymore!?

Error I would get it:

cd: not a directory: /tmp
    at Object.error (/path_to_project/node_modules/shelljs/src/common.js:110:27)
    at Object._cd (/path_to_project/node_modules/shelljs/src/cd.js:35:21)
    at Object.cd (/path_to_project/node_modules/shelljs/src/common.js:384:25)

Yes, the /tmp folder still exists! So I'm 100% sure that folder is NOT removed.

Example ShellJS command to reproduce the error:

shell.cd('/tmp/a')
shell.rm('-rf', '/tmp/a')
shell.cd('/tmp')

Please, help!?

melroy89 avatar Oct 18 '21 20:10 melroy89

The root-cause was I was actually within the directory itself, that I was going to remove.

Causing very strange behavior.

Currently my solution is to cd out of the directory I'm gonna remove. Otherwise the sh*t hit the fan.

melroy89 avatar Oct 19 '21 14:10 melroy89