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

Asset IO read_directory No Longer Panics on Absolute Path #9478

Conversation

bushrat011899
Copy link
Contributor

Objective

Solution

  • Used pathdiff::diff_paths to explicitly create the desired path, which handles the edge case where a provided path is actually an absolute path already, and thus cannot be stripped of a prefix of the general root path for the Asset IO.
  • Based on my previous comment

Changelog

  • Added pathdiff crate to bevy_asset to allow for the creation of relative paths in a platform agnostic manner.
  • Fixed read_directory incorrectly assuming a.join(b).strip_prefix(a) == Ok(b)

@github-actions
Copy link
Contributor

Example alien_cake_addict failed to run, please try running it locally and check the result.

@rlidwka
Copy link
Contributor

rlidwka commented Aug 18, 2023

Can this be done without adding another dependency crate?

@mockersf mockersf added the A-Assets Load files from disk to use for things like images, models, and sounds label Aug 18, 2023
@mockersf
Copy link
Member

Will probably hold on this until #8624 is merged

@bushrat011899
Copy link
Contributor Author

Can this be done without adding another dependency crate?

Absolutely! But you'd end up just copying the contents of pathdiff into Bevy, which is antithetical to good open source software composition. Constructing a relative path between two arbitrary Paths isn't particularly trivial, and I would be doubtful that a custom solution for Bevy would actually give much value.

@rlidwka
Copy link
Contributor

rlidwka commented Aug 19, 2023

Constructing a relative path between two arbitrary Paths isn't particularly trivial

If it takes 43 lines of code, I'd call that very much trivial.

which is antithetical to good open source software composition

So instead of small file with custom implementation somewhere inside the bevy repo, you'll have:

  1. one more dependency declared (there are a LOT more people reading Cargo.toml than source files)
  2. one more crate to download and compile (each package represents many files on disk - manifest, readme, license - which take more space and processing time than a single file in existing repo)
  3. one more license to check and include in all applications (for those companies that like to include all licenses for everything they use)
  4. add some risk that a dependency package will be released with incompatible api, and everything breaks
  5. (*) including all the issues arising when an end user includes different versions of the same package, where things just straight up don't compile
  6. (*) including a risk of new api feature that wipes your hard drive, as with famous node-ipc npm package

I'm not buying into "good open source software composition" idea. But I don't know bevy policies about introducing new dependencies, that's up to maintainers here.

Also, here's a funny read on the subject I just found, contents of which you can probably guess by the title:
https://www.davidhaney.io/npm-left-pad-have-we-forgotten-how-to-program/

@bushrat011899
Copy link
Contributor Author

If it takes 43 lines of code, I'd call that very much trivial.

Short is not the same as simple.

So instead of small file with custom implementation somewhere inside the bevy repo, you'll have:

  1. one more dependency declared (there are a LOT more people reading Cargo.toml than source files)

Bevy currently builds with just shy of 1,000 crates as dependencies depending on your project, a single addition (which itself has 0 dependencies) will make zero difference to anyone who truly believes more dependencies equals bad.

  1. one more crate to download and compile (each package represents many files on disk - manifest, readme, license - which take more space and processing time than a single file in existing repo)

Again, Bevy is already including hundreds of dependencies each with anywhere from one to thousands of files, one dependency is not going to meaningfully change that.

  1. one more license to check and include in all applications (for those companies that like to include all licenses for everything they use)

See response to points one and two.

  1. add some risk that a dependency package will be released with incompatible api, and everything breaks

That's just not how open source dependency management works. You can't say "I'll just make my own solution and put in all the work to maintain it" and "Putting in the work to maintain someone else's version is too hard" at the same time. For this crate in particular I think that's a poor critique, since it has well over 15 million downloads and only 3 versions in its entire lifetime.

  1. (*) including all the issues arising when an end user includes different versions of the same package, where things just straight up don't compile

That's only an issue if you expose types from a third party library as your own, which is not happening in this case. And even then, you can still manage this.

  1. (*) including a risk of new api feature that wipes your hard drive, as with famous node-ipc npm package

See response to points 1.

I'm not buying into "good open source software composition" idea. But I don't know bevy policies about introducing new dependencies, that's up to maintainers here.

The idea is to minimize double work. This pull request "implements 43 lines of code in 1" thanks to the generous work of the maintainers of pathdiff.

Also, here's a funny read on the subject I just found, contents of which you can probably guess by the title:
https://www.davidhaney.io/npm-left-pad-have-we-forgotten-how-to-program/

This is not comparable. The leftpad controversy largely stems from the fact that there is a native solution to that problem already. There is no std implementation of diff_paths.

I appreciate the criticism, and I'm also new to contributing to Bevy, so I am absolutely open to being told this is a bad fit for Bevy. In my opinion, this is the best solution to this problem, which is why I wrote it an submitted it. If you believe you have a better solution, please make a PR and submit it. Either way, Bevy and its community wins.

@rlidwka
Copy link
Contributor

rlidwka commented Aug 19, 2023

If you believe you have a better solution, please make a PR and submit it.

okay, sure, here we go: #9490

bushrat011899 and others added 2 commits August 19, 2023 17:12
Co-authored-by: Félix Lescaudey de Maneville <felix.maneville@gmail.com>
The closure in `unwrap_or_else` must not accept arguments, and the panic message can't include the paths due to movement into `diff_paths`
@github-actions
Copy link
Contributor

Example alien_cake_addict failed to run, please try running it locally and check the result.

@alice-i-cecile alice-i-cecile added C-Bug An unexpected or incorrect behavior P-Crash A sudden unexpected crash labels Sep 7, 2023
@alice-i-cecile
Copy link
Member

The linked bug is now fixed: should I close this out?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Assets Load files from disk to use for things like images, models, and sounds C-Bug An unexpected or incorrect behavior P-Crash A sudden unexpected crash
Projects
None yet
Development

Successfully merging this pull request may close these issues.

load_folder() panics when given an absolute path but load() does not
6 participants