ignore files starting with . when loading folders (#11214)

# Objective

- When loading a folder with dot files inside, Bevy crashes:
```
thread 'IO Task Pool (1)' panicked at crates/bevy_asset/src/io/mod.rs:260:10:
asset paths must have extensions
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
```
- those files are common for other tools to store their
settings/metadata

## Solution

- Ignore files starting with a dot when loading folders
This commit is contained in:
François Mockers 2025-05-06 00:42:01 +02:00 committed by GitHub
parent 235257ff62
commit 31c2dc591d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 19 additions and 0 deletions

View File

@ -74,6 +74,15 @@ impl AssetReader for FileAssetReader {
return None;
}
}
// filter out hidden files. they are not listed by default but are directly targetable
if path
.file_name()
.and_then(|file_name| file_name.to_str())
.map(|file_name| file_name.starts_with('.'))
.unwrap_or_default()
{
return None;
}
let relative_path = path.strip_prefix(&root_path).unwrap();
Some(relative_path.to_owned())
})

View File

@ -145,6 +145,16 @@ impl AssetReader for FileAssetReader {
return None;
}
}
// filter out hidden files. they are not listed by default but are directly targetable
if path
.file_name()
.and_then(|file_name| file_name.to_str())
.map(|file_name| file_name.starts_with('.'))
.unwrap_or_default()
{
return None;
}
let relative_path = path.strip_prefix(&root_path).unwrap();
Some(relative_path.to_owned())
})