Ticket #4190 (new defect)
mc-wrapper.sh.in should not (test "$MC_PWD" != "$PWD")
Reported by: | mr700 | Owned by: | |
---|---|---|---|
Priority: | minor | Milestone: | Future Releases |
Component: | mc-core | Version: | master |
Keywords: | Cc: | ||
Blocked By: | Blocking: | ||
Branch state: | no branch | Votes for changeset: |
Description
I am getting
shell-init: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
error in the following situation:
- mkdir recreated
- cd recreated
- mc
- navigate to the parent directory
- F8 to remove the "recreated" directory
- F7 to recreate the "recreated" directory
- enter the "recreated" directory
- F10 exit Midnight Commander
I think that the check
if test -n "$MC_PWD" && test "$MC_PWD" != "$PWD" && test -d "$MC_PWD"; then
should simply be
if test -n "$MC_PWD" && test -d "$MC_PWD"; then
there is no harm in "cd $PWD" if the directory is really the old one and not recreated IMHO. The only behavioral change compared the the previous script is to "cd -" will stay in the current directory if it did not change.
Test environment: bash-5.0.17-2.fc33.x86_64 (Fedora 33).
Change History
comment:2 Changed 4 years ago by mr700
Created pull request https://github.com/MidnightCommander/mc/pull/161
comment:3 Changed 4 years ago by ossi
so it should compare the inode numbers of pwd prior to starting mc and the returned dir.
the inode can be obtained for example with ls -d -i "$thedir" | cut -d' ' -f1 or stat -c '%i' "$thedir" (not sure about the portability of either).
comment:4 Changed 4 years ago by mr700
IMHO this functionality can not be implemented reliably in a script because the inode will be reused.
Unless there is a way to open the directory in the script (https://linux.die.net/man/2/openat), keep the FD open till MC exits and then compare inodes (can't be reused while something has it open even if deleted IIRC) it is not solvable via a script. The fix would require MC checking for this and leaving the -P file empty or something like that.
Unless someone has a better idea I think it is just too much work for a "cd -" or rare CWD error. Maybe something like
bash -c 'pwd' > /dev/null 2>&1 || echo "PWD is gone"
this works with bash and fish, but not with csh.
See #3355.