diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5da57ee5..e81c98f5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -34,7 +34,6 @@ jobs: cargo check --workspace --all-targets --all-features cargo check --workspace --all-targets --no-default-features cargo check --workspace --all-targets --no-default-features --features serde - cargo check --workspace --all-targets --no-default-features --features dir-entry-path - name: Build run: cargo build --workspace --release --verbose diff --git a/CHANGELOG.md b/CHANGELOG.md index 7c12109a..e41928e2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -45,6 +45,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - Removed `From for littlefs2::io::Error`. - Removed `object_safe::OpenOptionsCallback`. - Removed `consts::ATTRBYTES_MAX_TYPE`. +- Removed `dir-entry-path` feature (now always enabled). [#47]: https://github.com/trussed-dev/littlefs2/pull/47 [#57]: https://github.com/trussed-dev/littlefs2/pull/57 diff --git a/Cargo.toml b/Cargo.toml index 4b2cd256..b077aa3a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -32,9 +32,7 @@ serde = { version = "1.0", default-features = false, features = ["derive"] } # trybuild = "1" [features] -default = ["dir-entry-path", "serde"] -# use experimental closure-based API -dir-entry-path = ["littlefs2-core/dir-entry-path"] +default = ["serde"] serde = ["littlefs2-core/serde"] # enable assertions in backend C code ll-assertions = ["littlefs2-sys/assertions"] diff --git a/core/Cargo.toml b/core/Cargo.toml index cf30dae9..544df429 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -14,5 +14,4 @@ heapless = "0.7" serde = { version = "1", default-features = false, features = ["derive"], optional = true } [features] -dir-entry-path = [] serde = ["dep:serde"] diff --git a/core/src/fs.rs b/core/src/fs.rs index 7b72eb05..550ababb 100644 --- a/core/src/fs.rs +++ b/core/src/fs.rs @@ -115,20 +115,14 @@ impl<'a> Attribute<'a> { pub struct DirEntry { file_name: PathBuf, metadata: Metadata, - #[cfg(feature = "dir-entry-path")] path: PathBuf, } impl DirEntry { - pub fn new( - file_name: PathBuf, - metadata: Metadata, - #[cfg(feature = "dir-entry-path")] path: PathBuf, - ) -> Self { + pub fn new(file_name: PathBuf, metadata: Metadata, path: PathBuf) -> Self { Self { file_name, metadata, - #[cfg(feature = "dir-entry-path")] path, } } @@ -151,12 +145,10 @@ impl DirEntry { /// Returns the full path to the file that this entry represents. /// /// The full path is created by joining the original path to read_dir with the filename of this entry. - #[cfg(feature = "dir-entry-path")] pub fn path(&self) -> &Path { &self.path } - #[cfg(feature = "dir-entry-path")] #[doc(hidden)] // This is used in `crypto-service` to "namespace" paths // by mutating a DirEntry in-place. diff --git a/core/src/object_safe.rs b/core/src/object_safe.rs index 613a51ab..42abfbb9 100644 --- a/core/src/object_safe.rs +++ b/core/src/object_safe.rs @@ -58,9 +58,7 @@ pub trait DynFilesystem { fn available_space(&self) -> Result; fn remove(&self, path: &Path) -> Result<()>; fn remove_dir(&self, path: &Path) -> Result<()>; - #[cfg(feature = "dir-entry-path")] fn remove_dir_all(&self, path: &Path) -> Result<()>; - #[cfg(feature = "dir-entry-path")] fn remove_dir_all_where(&self, path: &Path, predicate: Predicate<'_>) -> Result; fn rename(&self, from: &Path, to: &Path) -> Result<()>; fn exists(&self, path: &Path) -> bool; diff --git a/src/fs.rs b/src/fs.rs index e853ae76..5be952d3 100644 --- a/src/fs.rs +++ b/src/fs.rs @@ -185,7 +185,6 @@ fn metadata(info: ll::lfs_info) -> Metadata { Metadata::new(file_type, info.size as usize) } -#[cfg(feature = "dir-entry-path")] struct RemoveDirAllProgress { files_removed: usize, skipped_any: bool, @@ -274,13 +273,11 @@ impl Filesystem<'_, Storage> { /// TODO: This method fails if some `println!` calls are removed. /// Whyy? - #[cfg(feature = "dir-entry-path")] pub fn remove_dir_all(&self, path: &Path) -> Result<()> { self.remove_dir_all_where(path, &|_| true).map(|_| ()) } /// Returns number of deleted files + whether the directory was fully deleted or not - #[cfg(feature = "dir-entry-path")] fn remove_dir_all_where_inner

( &self, path: &Path, @@ -338,7 +335,6 @@ impl Filesystem<'_, Storage> { }) } - #[cfg(feature = "dir-entry-path")] pub fn remove_dir_all_where

(&self, path: &Path, predicate: &P) -> Result where P: Fn(&DirEntry) -> bool, @@ -927,8 +923,7 @@ pub struct ReadDir<'a, 'b, S: driver::Storage> { // to the field alloc.state, so we cannot assert unique mutable access. alloc: RefCell<*mut ReadDirAllocation>, fs: &'b Filesystem<'a, S>, - #[cfg(feature = "dir-entry-path")] - path: PathBuf, + path: &'b Path, } impl<'a, 'b, S: driver::Storage> Iterator for ReadDir<'a, 'b, S> { @@ -953,15 +948,9 @@ impl<'a, 'b, S: driver::Storage> Iterator for ReadDir<'a, 'b, S> { let file_name = unsafe { PathBuf::from_buffer_unchecked(info.name) }; let metadata = metadata(info); - #[cfg(feature = "dir-entry-path")] let path = self.path.join(&file_name); - let dir_entry = DirEntry::new( - file_name, - metadata, - #[cfg(feature = "dir-entry-path")] - path, - ); + let dir_entry = DirEntry::new(file_name, metadata, path); return Some(Ok(dir_entry)); } @@ -1023,7 +1012,7 @@ impl<'a, Storage: driver::Storage> Filesystem<'a, Storage> { pub unsafe fn read_dir<'b>( &'b self, alloc: &'b mut ReadDirAllocation, - path: &Path, + path: &'b Path, ) -> Result> { // ll::lfs_dir_open stores a copy of the pointer to alloc.state, so // we must use addr_of_mut! here, since &mut alloc.state asserts unique @@ -1037,8 +1026,7 @@ impl<'a, Storage: driver::Storage> Filesystem<'a, Storage> { let read_dir = ReadDir { alloc: RefCell::new(alloc), fs: self, - #[cfg(feature = "dir-entry-path")] - path: PathBuf::from(path), + path, }; result_from(read_dir, return_code) @@ -1254,7 +1242,6 @@ mod tests { // unsafe { file.close() } // }).unwrap(); - #[cfg(feature = "dir-entry-path")] fs.read_dir_and_then(b"/\0".try_into().unwrap(), |read_dir| { for entry in read_dir { let entry = entry?; @@ -1274,24 +1261,20 @@ mod tests { for entry in read_dir { let entry = entry?; println!("entry: {:?}", entry.file_name()); - #[cfg(feature = "dir-entry-path")] - { - println!("path: {:?}", entry.path()); - - let attribute: &[u8] = if entry.file_type().is_dir() { - b"directory alarm" - } else { - // not 100% sure this is allowed, but if seems to work :) - fs.write(entry.path(), b"Alles neu macht n\xc3\xa4chstens der Mai")?; - b"ceci n'est pas une pipe" - }; - fs.set_attribute(entry.path(), 37, attribute)?; - } + println!("path: {:?}", entry.path()); + + let attribute: &[u8] = if entry.file_type().is_dir() { + b"directory alarm" + } else { + // not 100% sure this is allowed, but if seems to work :) + fs.write(entry.path(), b"Alles neu macht n\xc3\xa4chstens der Mai")?; + b"ceci n'est pas une pipe" + }; + fs.set_attribute(entry.path(), 37, attribute)?; } Ok(()) })?; - #[cfg(feature = "dir-entry-path")] fs.read_dir_and_then(b"/tmp/test\0".try_into().unwrap(), |read_dir| { for (i, entry) in read_dir.enumerate() { let entry = entry?; @@ -1334,17 +1317,14 @@ mod tests { Ok(()) })?; - #[cfg(feature = "dir-entry-path")] - { - println!("\nDELETION SPREE\n"); - // behaves veeryweirldy - // (...) - // entry = DirEntry { file_name: "test", metadata: Metadata { file_type: Dir, size: 0 }, path: "/tmp\u{0}/test" } - // (...) - // fs.remove_dir_all(&PathBuf::from(b"/tmp\0"))?; - // fs.remove_dir_all(&PathBuf::from(b"/tmp"))?; - fs.remove_dir_all(path!("/tmp"))?; - } + println!("\nDELETION SPREE\n"); + // behaves veeryweirldy + // (...) + // entry = DirEntry { file_name: "test", metadata: Metadata { file_type: Dir, size: 0 }, path: "/tmp\u{0}/test" } + // (...) + // fs.remove_dir_all(&PathBuf::from(b"/tmp\0"))?; + // fs.remove_dir_all(&PathBuf::from(b"/tmp"))?; + fs.remove_dir_all(path!("/tmp"))?; Ok(()) }) @@ -1356,7 +1336,6 @@ mod tests { fs.write(path!("z.txt"), jackson5).unwrap(); } - #[cfg(feature = "dir-entry-path")] #[test] fn remove_dir_all() { let mut test_storage = TestStorage::new(); diff --git a/src/object_safe.rs b/src/object_safe.rs index 15fe2f4d..f5e6688c 100644 --- a/src/object_safe.rs +++ b/src/object_safe.rs @@ -59,12 +59,10 @@ impl DynFilesystem for Filesystem<'_, S> { Filesystem::remove_dir(self, path) } - #[cfg(feature = "dir-entry-path")] fn remove_dir_all(&self, path: &Path) -> Result<()> { Filesystem::remove_dir_all(self, path) } - #[cfg(feature = "dir-entry-path")] fn remove_dir_all_where(&self, path: &Path, predicate: Predicate<'_>) -> Result { Filesystem::remove_dir_all_where(self, path, &|entry| predicate(entry)) } diff --git a/src/tests.rs b/src/tests.rs index 2497089e..cee385e5 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -396,7 +396,6 @@ fn test_fancy_open() { } #[test] -#[cfg(feature = "dir-entry-path")] fn remove_dir_all_where() { let mut backend = Ram::default(); let mut storage = RamStorage::new(&mut backend);