Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problems with File.real_path on macOS catalina #8431

Closed
jaydorsey opened this issue Nov 4, 2019 · 9 comments · Fixed by #9296
Closed

Problems with File.real_path on macOS catalina #8431

jaydorsey opened this issue Nov 4, 2019 · 9 comments · Fixed by #9296

Comments

@jaydorsey
Copy link

jaydorsey commented Nov 4, 2019

I have a little toy crystal app I've been building that just reads a list of files/folders from a path and spits out the files & folders with some terminal codes to colorize stuff.

I recently upgraded to macOS catalina and it appears that File.real_path on macOS Catalina is broken

I can reproduce the error with the steps below.

  • mkdir -p foo/bar && cd foo
  • echo "puts File.real_path(\"bar\")" > foo.cr
  • crystal build foo.cr
  • ./foo

An error message occurs:

Unhandled exception: Error resolving real path of 'bar': No such file or directory (Errno)
  from /Users/jay/.asdf/installs/crystal/0.31.1/src/crystal/system/unix/file.cr:92:5 in 'real_path'
  from /Users/jay/.asdf/installs/crystal/0.31.1/src/file.cr:554:5 in 'real_path'
  from foo.cr:1:1 in '__crystal_main'
  from /Users/jay/.asdf/installs/crystal/0.31.1/src/crystal/main.cr:97:5 in 'main_user_code'
  from /Users/jay/.asdf/installs/crystal/0.31.1/src/crystal/main.cr:86:7 in 'main'
  from /Users/jay/.asdf/installs/crystal/0.31.1/src/crystal/main.cr:106:3 in 'main'

The executable will work OK, intermittently, without making any changes to anything.

What I've tried to resolve:

  • In Security & Privacy > Privacy > Full Disk Access, grant the foo executable full disk access
    • This doesn't actually seem to matter; I also disabled access and could run the executable a half dozen times and it would run once or twice
  • Tried other Crystal versions (0.30.0, 0.31.0, 0.31.1)

I made zero code changes, didn't regenerate the binary, or make system preference changes in the example below, and note that it jus randomly worked once (and failed again after that):

image

I got the idea to run it a couple times from here; Julia users are seeing similar behavior with their implementation (not a Julia user, found that link via a Google search after I didn't see any results in the Github Issues here)

Tested on macOS Catalina (10.15) with a couple Crystal versions, but I'm trying to get it working in latest (using asdf for version management to download the latest compiled binaries)

Crystal 0.31.1 (2019-09-30)

LLVM: 6.0.1
Default target: x86_64-apple-macosx
@jaydorsey
Copy link
Author

Here's another example: I ran the command one time, made zero changes to code, used the same binary, made zero changes to any settings, configuration, etc. anywhere and it just died

image

I can run the executable a dozen times and it runs fine twice, fails the other 10 with a mixture of failing on different file paths. It could 100% be my poorly written code (https://github.com/jaydorsey/colorls-cr) but it worked fine until the Catalina upgrade

@jaydorsey
Copy link
Author

jaydorsey commented Nov 9, 2019

So, I found a workaround for this issue, but I think this might still be a bug?

In my code, I'm capturing both the relative path to the file/folder and the absolute path. I'm calling File.real_path on the relative path, and that's what's breaking intermittently.

Calling it against the absolute path every time seems to work OK

This may or may not even be a Catalina-related bug, but I know this wasn't an issue on 0.30.0 before I upgraded, and now it doesn't work on 0.30.0. I don't have another macOS machine to test this out on.

jaydorsey added a commit to jaydorsey/colorls-cr that referenced this issue Nov 9, 2019
Per this bug: crystal-lang/crystal#8431

This stopped working after Catalina, this makes things work again
@rdp
Copy link
Contributor

rdp commented Nov 19, 2019

Works OK in /tmp ? Something doesn't feel right here...

@RX14
Copy link
Contributor

RX14 commented Nov 19, 2019

If it's an OS bug there's not much we can do...

@jhass
Copy link
Member

jhass commented Nov 19, 2019

Well if it only affects relative paths we could consider running File.expand_path first...

@jaydorsey
Copy link
Author

If it's an OS bug there's not much we can do...

I haven't tested in anything but macOS High Sierra & Catalina. Seems like it could be an OS bug but there's other factors that could come into play so I was hoping others could jump in as well.

@vtjnash
Copy link

vtjnash commented Dec 23, 2019

If related, I've discovered over on the linked Julia issue that the name of the DARWIN_BETTER_REALPATH function is actually "realpath$DARWIN_EXTSN". This renaming is done automatically when parsing C header files, but I suspect that crystal (like julia) just embeds the name at

fun realpath(x0 : Char*, x1 : Char*) : Char*
and avoids trying to parse the header files to define it. (also, fwiw, there also appears to be a "realpath$UNIX2003" variant).

@jaydorsey
Copy link
Author

jaydorsey commented May 12, 2020

I'm closing this for now; there's a sufficient workaround as I noted above in addition to the workaround noted in the linked comment issue about the FFI function behavior.

With the workaround, I've had no issues

@waj
Copy link
Member

waj commented May 13, 2020

@vtjnash apparently using that symbol is all we needed to fix this issue!

@waj waj reopened this May 13, 2020
@waj waj linked a pull request May 13, 2020 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants