Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
### Changed

- Documented the MSRV 1.74
- PathBuf::push: clear the original path whenever the pushed path is absolute

## [v0.1.2](https://github.com/trussed-dev/littlefs2/releases/tag/core-0.1.2) - 2025-10-16

Expand Down
3 changes: 3 additions & 0 deletions core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
//!
//! [`littlefs2`]: https://docs.rs/littlefs2

#[cfg(test)]
extern crate std;

mod fs;
mod io;
mod object_safe;
Expand Down
38 changes: 24 additions & 14 deletions core/src/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -528,20 +528,14 @@ impl PathBuf {

/// Extends `self` with `path`
pub fn push(&mut self, path: &Path) {
match path.as_ref() {
// no-operation
"" => return,

// `self` becomes `/` (root), to match `std::Path` implementation
// NOTE(allow) cast is necessary on some architectures (e.g. x86)
#[allow(clippy::unnecessary_cast)]
"/" => {
self.buf[0] = b'/' as c_char;
self.buf[1] = 0;
self.len = 2;
return;
}
_ => {}
if path.is_empty() {
return;
}

if path.as_ref().starts_with("/") {
// Following the standard library, if the path being pushed is absolute
// then we make it replace the current path
self.clear();
}

let src = path.as_ref().as_bytes();
Expand Down Expand Up @@ -900,4 +894,20 @@ mod tests {
let path = path!("/some/path/.././file.extension/");
assert_eq!(path.file_name(), None);
}

#[test]
fn matching_std() {
for test_case in ["/", "/other", "eaiu"] {
let mut path_littlefs2 = PathBuf::from_path(path!("/root"));
let mut path_std = std::path::PathBuf::from("/root");

path_littlefs2.push(&PathBuf::try_from(test_case).unwrap());
path_std.push(test_case);

assert_eq!(
path_littlefs2.as_str(),
path_std.as_path().to_str().unwrap()
);
}
}
}
Loading