Skip to content

Getting an error "cd: '/Users/x/Downloads/' is a rotten symlink" #8264

Closed

Description

@elimist3

Today I logged onto my machine and tried to cd ~/Downloads, but to my surprise fish returned an error cd: '/Users/x/Downloads/' is a rotten symlink.

It seems to originate from the builtin_cd function call here, however I can't tell what the reason is since my Downloads directory is not a symlink.

I'm able to cd into any other directory just fine and I'm able to access ~/Downloads through MacOS's file explorer (Finder) so I don't think the directory is corrupt.

When I chsh -s /bin/bash, I'm able to cd ~/Downloads just fine!

My config.fish is just the default config, and I've already tried reinstalling Fish from my package manager (homebrew), to no avail.

System info
Fish version: 3.3.1
Operating system: MacOS 11.5.2, arm64
Terminal: Alacritty
Affected by third-party customizations: no, output is the same

I have a feeling this may be difficult to reproduce but I thought I'd put this out there just in case there is an easy solution to be found.

Activity

  1. changed the title [-]Getting an error "cd: '/Users/x/Downloads/' is a rotten symlink" in Fish shell[/-] [+]Getting an error "cd: '/Users/x/Downloads/' is a rotten symlink"[/+] on Sep 1, 2021
  2. krobelus commented on Sep 2, 2021

    @krobelus
    Contributor

    The error message is misleading because EROTTEN is a fish invention that was removed in 7ac5932 ("Remove a bunch of dead code identified by cppcheck"). It is defined as 1, which matches EPERM.
    I'm not sure how you're getting a permissions error; fchdir should never set EPERM.
    Maybe you've allowed bash to access files but not fish? I'm not sure.

    diff --git a/src/builtin_cd.cpp b/src/builtin_cd.cpp
    index 9d0fa6e58..1b1910fe2 100644
    --- a/src/builtin_cd.cpp
    +++ b/src/builtin_cd.cpp
    @@ -108,9 +108,7 @@ maybe_t<int> builtin_cd(parser_t &parser, io_streams_t &streams, const wchar_t *
         } else if (best_errno == ENOENT) {
             streams.err.append_format(_(L"%ls: The directory '%ls' does not exist\n"), cmd,
                                       dir_in.c_str());
    -    } else if (best_errno == EROTTEN) {
    -        streams.err.append_format(_(L"%ls: '%ls' is a rotten symlink\n"), cmd, dir_in.c_str());
    -    } else if (best_errno == EACCES) {
    +    } else if (best_errno == EACCES || best_errno == EPERM) {
             streams.err.append_format(_(L"%ls: Permission denied: '%ls'\n"), cmd, dir_in.c_str());
         } else {
             errno = best_errno;
    diff --git a/src/path.h b/src/path.h
    index 852714b15..d7e1a0a5e 100644
    --- a/src/path.h
    +++ b/src/path.h
    @@ -9,9 +9,6 @@
     #include "common.h"
     #include "env.h"
     
    -/// Return value for path_cdpath_get when locatied a rotten symlink.
    -#define EROTTEN 1
    -
     /// Returns the user configuration directory for fish. If the directory or one of its parents
     /// doesn't exist, they are first created.
     ///
  3. kopischke commented on Sep 2, 2021

    @kopischke

    @krobelus

    EROTTEN is a fish invention that was removed in 7ac5932

    Not sure what happened after that commit 7 years ago, but EROTTEN is very much alive and well in the current codebase.

  4. faho commented on Sep 2, 2021

    @faho
    Member

    Not sure what happened after that commit 7 years ago, but EROTTEN is very much alive and well in the current codebase.

    It isn't set anymore since 7ac5932, and never returned since even before that (the code that set it was already dead).

    That's why @krobelus included the patch that removes it entirely - which should be merged (except it should also be removed from the comment below).

  5. faho commented on Sep 2, 2021

    @faho
    Member

    I'm not sure how you're getting a permissions error; fchdir should never set EPERM.

    @krobelus The errno comes either from fchdir, or the wopen_cloexec (i.e. open) before. open(2) is also not documented to set EPERM (on macOS, on Linux it can - but then the docs might just be wrong).

    Either way, I don't see a way for us to avoid it - we need to open the directory and then chdir to it. If either of those fails, then it fails.

  6. elimist3 commented on Sep 2, 2021

    @elimist3
    Author

    Solved. It seems to have been a simple permissions error, though I'm baffled as I've never fiddled with the access permissions of my terminal (Alacritty) and before, when I tried to debug the issue by cd'ing from MacOS's built-in Terminal.app, it also threw the same "rotten symlink" error.

    The solution on MacOS was just to go to System Preferences -> Privacy -> Files and Folders and allow Alacritty (or whichever terminal you're using) to access the Downloads folder.

    Thanks everyone!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions