danielpclark / rutie

“The Tie Between Ruby and Rust.”
MIT License
942 stars 62 forks source link

check if libruby symlink exists before attempting to create one in build script #85

Closed ekump closed 5 years ago

ekump commented 5 years ago

I've noticed on Linux that if the symlink for libruby already exists in the ~/.cargo/registry/src/.../rutie/target/release/deps folder and you rebuild a project with rutie as a dependency you will get the following error:

thread 'main' panicked at 'symlink fail: Os { code: 17, kind: AlreadyExists, message: "File exists" }', src/libcore/result.rs:997:5

Steps to reproduce: 1) cargo build a project with Rutie as a dependency 2) Perform either cargo clean && cargo build or update your version of Rust via rustup.

Unfortunately cargo clean doesn't clean the contents of ~/.cargo/registry/src. As a workaround you can just delete the symlink present in the deps folder. However, this isn't easily achievable when deploying to Heroku. I primarily see this error when a new version of Rust is released and the Heroku buildpack updates its version of Rust, which triggers a rebuild of the project, but doesn't update the contents of ~./cargo/registry/src.

According to the documentation for .exists() it should only return false on a broken symlink, but it is definitely returning false on Ubuntu 19.04 with Rust 1.34.1, and on Heroku's stack which is also running Ubuntu.

This change will explicitly check for a symlink in target location. As I understand the documentation read_link should only return Ok if the path is a symlink. Otherwise, it's an error.

danielpclark commented 5 years ago

Thanks for this. Have you tried the fix in your environment?

ekump commented 5 years ago

Yes, I created a simple project with Rutie as a dependency and I was able to recreate the error. With the changes the error went away.