Permalink
Browse files

Fix crash when cd-ing away from a directory that's been removed.

Tickled by Aboriginal Linux.

Addresses issue #58.
  • Loading branch information...
Andy Chu
Andy Chu committed Jan 1, 2018
1 parent 0573fd4 commit 71036130986d61c19508c8b1adeca386ee0d3c40
Showing with 19 additions and 2 deletions.
  1. +6 −2 core/builtin.py
  2. +13 −0 spec/builtins.test.sh
View
@@ -589,8 +589,12 @@ def Cd(argv, mem, dir_stack):
# can't even set it at all.)
raise AssertionError('Invalid OLDPWD')
# Save OLDPWD.
state.SetGlobalString(mem, 'OLDPWD', os.getcwd())
# NOTE: We can't call os.getcwd() because it can raise OSError if the
# directory was removed (ENOENT.)
pwd = mem.GetVar('PWD')
assert pwd.tag == value_e.Str, pwd # TODO: Need a general scheme to avoid
state.SetGlobalString(mem, 'OLDPWD', pwd.s)
try:
os.chdir(dest_dir)
except OSError as e:
View
@@ -41,6 +41,19 @@ echo status=$?
# stdout: status=1
# OK dash/mksh stdout: status=2
### cd away from dir that was deleted
dir=$TMP/cd-nonexistent
mkdir -p $dir
cd $dir
rmdir $dir
cd $TMP
echo $(basename $OLDPWD)
echo status=$?
## STDOUT:
cd-nonexistent
status=0
## END
### pushd/popd
set -o errexit
cd /

0 comments on commit 7103613

Please sign in to comment.