mirror of
https://github.com/trussed-dev/littlefs2.git
synced 2026-06-20 04:16:32 -07:00
Remove dir-entry-path feature
The dir-entry-path feature has been enabled by default and only adds a very small overhead. To decrease complexity, this patch removes the feature and always enables the previously feature-gated code. Fixes: https://github.com/trussed-dev/littlefs2/issues/76
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -45,6 +45,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
|
||||
- Removed `From<littlefs2::path::Error> 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
|
||||
|
||||
+1
-3
@@ -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"]
|
||||
|
||||
@@ -14,5 +14,4 @@ heapless = "0.7"
|
||||
serde = { version = "1", default-features = false, features = ["derive"], optional = true }
|
||||
|
||||
[features]
|
||||
dir-entry-path = []
|
||||
serde = ["dep:serde"]
|
||||
|
||||
+1
-9
@@ -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.
|
||||
|
||||
@@ -58,9 +58,7 @@ pub trait DynFilesystem {
|
||||
fn available_space(&self) -> Result<usize>;
|
||||
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<usize>;
|
||||
fn rename(&self, from: &Path, to: &Path) -> Result<()>;
|
||||
fn exists(&self, path: &Path) -> bool;
|
||||
|
||||
@@ -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<Storage: driver::Storage> 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<P>(
|
||||
&self,
|
||||
path: &Path,
|
||||
@@ -338,7 +335,6 @@ impl<Storage: driver::Storage> Filesystem<'_, Storage> {
|
||||
})
|
||||
}
|
||||
|
||||
#[cfg(feature = "dir-entry-path")]
|
||||
pub fn remove_dir_all_where<P>(&self, path: &Path, predicate: &P) -> Result<usize>
|
||||
where
|
||||
P: Fn(&DirEntry) -> bool,
|
||||
@@ -927,7 +923,6 @@ 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,
|
||||
}
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
@@ -1037,7 +1026,6 @@ 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),
|
||||
};
|
||||
|
||||
@@ -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());
|
||||
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)?;
|
||||
}
|
||||
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();
|
||||
|
||||
@@ -59,12 +59,10 @@ impl<S: Storage> 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<usize> {
|
||||
Filesystem::remove_dir_all_where(self, path, &|entry| predicate(entry))
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user