Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Run cargo clippy --fix
  • Loading branch information
sosthene-nitrokey committed Mar 10, 2023
commit 72a977be6c7aefbf0da3b9b397bdfe53a8a82183
16 changes: 8 additions & 8 deletions src/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -506,9 +506,9 @@ impl<Storage: driver::Storage> Filesystem<'_, Storage> {
extern "C" fn lfs_config_erase(c: *const ll::lfs_config, block: ll::lfs_block_t) -> cty::c_int {
// println!("in lfs_config_erase");
let storage = unsafe { &mut *((*c).context as *mut Storage) };
let off = block as usize * Storage::BLOCK_SIZE as usize;
let off = block as usize * Storage::BLOCK_SIZE;

io::error_code_from(storage.erase(off, Storage::BLOCK_SIZE as usize))
io::error_code_from(storage.erase(off, Storage::BLOCK_SIZE))
}

/// C callback interface used by LittleFS to sync data with the lower level interface below the
Expand Down Expand Up @@ -673,7 +673,7 @@ impl<'a, 'b, Storage: driver::Storage> File<'a, 'b, Storage> {

// Safety-hatch to experiment with missing parts of API
pub unsafe fn borrow_filesystem<'c>(&'c mut self) -> &'c Filesystem<'a, Storage> {
&self.fs
self.fs
}

/// Sync the file and drop it from the internal linked list.
Expand Down Expand Up @@ -1052,7 +1052,7 @@ impl<'a, 'b, S: driver::Storage> Iterator for ReadDir<'a, 'b, S> {
impl<'a, 'b, S: driver::Storage> ReadDir<'a, 'b, S> {
// Safety-hatch to experiment with missing parts of API
pub unsafe fn borrow_filesystem<'c>(&'c mut self) -> &'c Filesystem<'a, S> {
&self.fs
self.fs
}
}

Expand Down Expand Up @@ -1367,7 +1367,7 @@ mod tests {
let mut alloc = Allocation::new();
let fs = Filesystem::mount(&mut alloc, &mut test_storage).unwrap();
// fs.write(b"/z.txt\0".try_into().unwrap(), &jackson5).unwrap();
fs.write(&PathBuf::from("z.txt"), &jackson5).unwrap();
fs.write(&PathBuf::from("z.txt"), jackson5).unwrap();
}

#[cfg(feature = "dir-entry-path")]
Expand Down Expand Up @@ -1446,7 +1446,7 @@ mod tests {
// One usecase is to read data from the files iterated over.
//
if entry.metadata.is_file() {
fs.write(&entry.file_name(), b"wowee zowie")?;
fs.write(entry.file_name(), b"wowee zowie")?;
}
}
Ok(())
Expand Down Expand Up @@ -1477,11 +1477,11 @@ mod tests {
})?;

let mut a1 = File::allocate();
let f1 = unsafe { File::open(&fs, &mut a1, b"a.txt\0".try_into().unwrap())? };
let f1 = unsafe { File::open(fs, &mut a1, b"a.txt\0".try_into().unwrap())? };
f1.write(b"some text")?;

let mut a2 = File::allocate();
let f2 = unsafe { File::open(&fs, &mut a2, b"b.txt\0".try_into().unwrap())? };
let f2 = unsafe { File::open(fs, &mut a2, b"b.txt\0".try_into().unwrap())? };
f2.write(b"more text")?;

unsafe { f1.close()? }; // program hangs here
Expand Down
2 changes: 1 addition & 1 deletion src/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ impl From<&[u8]> for PathBuf {
} else {
bytes
};
let has_no_embedded_nul = bytes.iter().find(|&&byte| byte == b'\0').is_none();
let has_no_embedded_nul = !bytes.iter().any(|&byte| byte == b'\0');
assert!(has_no_embedded_nul);

let mut buf = [0; consts::PATH_MAX_PLUS_ONE];
Expand Down
8 changes: 4 additions & 4 deletions src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,20 +197,20 @@ fn test_create() {
assert_eq!(fs.available_blocks().unwrap(), 512 - 2);
assert_eq!(fs.available_space().unwrap(), 130_560);

assert!(!crate::path::PathBuf::from(b"/test_open.txt").exists(&fs));
assert!(!crate::path::PathBuf::from(b"/test_open.txt").exists(fs));
assert_eq!(
File::open_and_then(fs, b"/test_open.txt\0".try_into().unwrap(), |_| { Ok(()) })
.map(drop)
.unwrap_err(), // "real" contains_err is experimental
Error::NoSuchEntry
);
assert!(!crate::path::PathBuf::from(b"/test_open.txt").exists(&fs));
assert!(!crate::path::PathBuf::from(b"/test_open.txt").exists(fs));

fs.create_dir(b"/tmp\0".try_into().unwrap()).unwrap();
assert_eq!(fs.available_blocks().unwrap(), 512 - 2 - 2);

// can create new files
assert!(!crate::path::PathBuf::from(b"/tmp/test_open.txt").exists(&fs));
assert!(!crate::path::PathBuf::from(b"/tmp/test_open.txt").exists(fs));
fs.create_file_and_then(b"/tmp/test_open.txt\0".try_into().unwrap(), |file| {
// can write to files
assert!(file.write(&[0u8, 1, 2]).unwrap() == 3);
Expand All @@ -221,7 +221,7 @@ fn test_create() {
// file.close()?;
Ok(())
})?;
assert!(crate::path::PathBuf::from(b"/tmp/test_open.txt").exists(&fs));
assert!(crate::path::PathBuf::from(b"/tmp/test_open.txt").exists(fs));

// // cannot remove non-empty directories
assert_eq!(
Expand Down