shelljs / shelljs/shelljs

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

Open
#1,050 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bash compat fix
Dominant language
JavaScript
Stars
14.4k
Forks
756
PR merge metrics
No merged PRs in 30d

Description

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!?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Inspect src/cd.js and src/common.js, especially the paths shown in the stack trace. Run the supplied reproduction on Linux to observe the behavior after removing the current directory. Done means the final shell.cd('/tmp') behaves correctly, with a regression test covering the sequence.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js
Domain
cli
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.