habvi / 42_minishell

Re-implemented a simple shell.
4 stars 0 forks source link

update ft_cd path check #289

Closed habvi closed 1 year ago

habvi commented 1 year ago

ft_cd を見直し

ak0327 commented 1 year ago

permission denied -> error

$ pwd
/home/user42/42tokyo/minishell/testdir/A/B

$ chmod 000 ../
$ cd ../
bash: cd: ../: Permission denied

$ cd ../../
bash: cd: ../../: Permission denied

$ cd ../../../
bash: cd: ../../../: Permission denied

$ cd ../../../../
bash: cd: ../../../../: Permission denied


current removed -> PWD + arg

$ mkdir A A/B && cd A/B
rm -rf  ../../A
bash (new  or not)

$ cd ..
cd: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory

$ declare -p | grep PWD
declare -x OLDPWD="/home/user42/42tokyo/minishell/testdir/A/B"
declare -x PWD="/home/user42/42tokyo/minishell/testdir/A/B/.."

$ cd ..
$ declare -p | grep PWD
declare -x OLDPWD="/home/user42/42tokyo/minishell/testdir/A/B/.."
declare -x PWD="/home/user42/42tokyo/minishell/testdir"

$ cd -
bash: cd: /home/user42/42tokyo/minishell/testdir/A/B/..: No such file or directory
user42@armlinux bash4.4_2[1] $ ~/42tokyo/minishell/testdir (update-redirect-use-dev)
ak0327 commented 1 year ago

chdirは物理pathで解釈されていそう

<path>
minishell/ dir1/dir2/dir3/dir4
minishell/ link -> dir1/dir2/dir3
minishell/ srcs

<arg>
minishell/ link
cd ../srcs

minishell/ link/../srcs

getcwd: /home/user42/42tokyo/minishell/dir1/dir2/dir3

<link>
cd link
link
  chdir(../srcs) : failure
           .. -> minishell or dir2 ?
path
  chdir(../dir3) : success


cd posix or bash