kurtbuilds / ormlite

An ORM in Rust for developers that love SQL.
https://crates.io/crates/ormlite
MIT License
216 stars 11 forks source link

use `current_dir()` instead of `$PWD` in `schema_from_filepaths()` #41

Closed nitn3lav closed 6 months ago

nitn3lav commented 6 months ago

When I use rust-analyzer in VS Code on macOS I get this error:

proc-macro derive panicked
message: called `Result::unwrap()` on an `Err` value: WithPath { path: "/./usr/sbin/authserver", err: Io(Custom { kind: PermissionDenied, error: Error { depth: 3, inner: Io { path: Some("/./usr/sbin/authserver"), err: Os { code: 13, kind: PermissionDenied, message: "Permission denied" } } } }) }

This occurs because $PWD is not set which leads to ormlite scanning the entire filesystem in order to generate a schema. IMHO it is reasonable to use $CARGO_MANIFEST_DIR instead of $PWD

kurtbuilds commented 6 months ago

Hey, thanks for submitting this. You're right that it env::var("PWD") is probably wrong, but I think CARGO_MANIFEST_DIR will be blank in cases when it's not called by a cargo command, e.g. anytime you run an ormlite command.

I think it should be using current_dir instead. Does that work for your situation?

It might make sense to have a cascade for exactly the Rust-analyzer situation you're encountering. CARGO_MANIFEST_DIR if it's set, otherwise fall back to current_dir().

nitn3lav commented 6 months ago

current_dir() seems to work, thanks!

kurtbuilds commented 6 months ago

Thank you!