Richterrettich / rpm-rs

A pure rust library for building and parsing RPM's
Other
39 stars 18 forks source link

Avoid calling mode() on Windows #30

Closed indygreg closed 3 years ago

indygreg commented 3 years ago

I would like to use this crate on a project that runs on Windows: there's no good reason to prevent Rust code running on Windows from parsing and even creating valid RPM files after all.

Before this commit, this crate failed to build on Windows because .mode() only exists on std::os::unix::fs::PermissionsExt. Even with the function call protected by a cfg!(unix), the code calling into .mode() is still compiled. The only way to work around this general problem is to have multiple versions of the implementation and conditionally compile a working one. You can do this via multiple functions or macros. I decided to go with the former as it is simpler.

The Windows implementation always returns 0. I'm not too keen about this and it is possible to use std::os::windows::fs::MetadataExt.file_attributes() to get at similar data. However, this would complicate the Rust code and I highly doubt many people will miss the functionality. For those that do, they can pass in a pre-populated RPMFileOptionsBuilder to override the default behavior.

It's worth noting that cargo test passes on Windows after this change.

Richterrettich commented 3 years ago

Hi!

Thanks for the PR, I have some free time next week, then I will have a look.