Ticket #4190 (new defect)

Opened 8 months ago

Last modified 8 months ago

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:

  1. mkdir recreated
  2. cd recreated
  3. mc
  4. navigate to the parent directory
  5. F8 to remove the "recreated" directory
  6. F7 to recreate the "recreated" directory
  7. enter the "recreated" directory
  8. 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:1 Changed 8 months ago by andrew_b

See #3355.

comment:2 Changed 8 months ago by mr700

comment:3 Changed 8 months 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 8 months 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.

Last edited 8 months ago by mr700 (previous) (diff)
Note: See TracTickets for help on using tickets.