Skip to content

Commit

Permalink
Rename DirEntry to DirectoryEntry
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexWaygood committed Jul 12, 2024
1 parent 93d3c50 commit 2018f9a
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 22 deletions.
8 changes: 4 additions & 4 deletions crates/ruff_db/src/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ pub trait System {
fn read_directory<'a>(
&'a self,
path: &SystemPath,
) -> Result<Box<dyn Iterator<Item = Result<DirEntry>> + 'a>>;
) -> Result<Box<dyn Iterator<Item = Result<DirectoryEntry>> + 'a>>;

fn as_any(&self) -> &dyn std::any::Any;
}
Expand Down Expand Up @@ -105,12 +105,12 @@ impl FileType {
}

#[derive(Debug)]
pub struct DirEntry {
pub struct DirectoryEntry {
path: SystemPathBuf,
file_type: Result<FileType>,
}

impl DirEntry {
impl DirectoryEntry {
pub fn new(path: SystemPathBuf, file_type: Result<FileType>) -> Self {
Self { path, file_type }
}
Expand All @@ -124,7 +124,7 @@ impl DirEntry {
}
}

impl PartialEq for DirEntry {
impl PartialEq for DirectoryEntry {
fn eq(&self, other: &Self) -> bool {
self.path == other.path
}
Expand Down
18 changes: 10 additions & 8 deletions crates/ruff_db/src/system/memory_fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::sync::{Arc, RwLock, RwLockWriteGuard};
use camino::{Utf8Path, Utf8PathBuf};
use filetime::FileTime;

use crate::system::{DirEntry, FileType, Metadata, Result, SystemPath, SystemPathBuf};
use crate::system::{DirectoryEntry, FileType, Metadata, Result, SystemPath, SystemPathBuf};

/// File system that stores all content in memory.
///
Expand Down Expand Up @@ -241,7 +241,7 @@ impl MemoryFileSystem {
pub(crate) fn read_directory(
&self,
path: impl AsRef<SystemPath>,
) -> Result<impl Iterator<Item = Result<DirEntry>> + '_> {
) -> Result<impl Iterator<Item = Result<DirectoryEntry>> + '_> {
let by_path = self.inner.by_path.read().unwrap();
let normalized = self.normalize_path(path.as_ref());
let entry = by_path.get(&normalized).ok_or_else(not_found)?;
Expand All @@ -254,7 +254,7 @@ impl MemoryFileSystem {
.take_while(|(path, _)| path.starts_with(&normalized))
.filter_map(|(path, entry)| {
if path.parent()? == normalized {
Some(Ok(DirEntry {
Some(Ok(DirectoryEntry {
path: SystemPathBuf::from_utf8_path_buf(path.to_owned()),
file_type: Ok(entry.file_type()),
}))
Expand Down Expand Up @@ -384,7 +384,9 @@ mod tests {
use std::io::ErrorKind;
use std::time::Duration;

use crate::system::{DirEntry, FileType, MemoryFileSystem, Result, SystemPath, SystemPathBuf};
use crate::system::{
DirectoryEntry, FileType, MemoryFileSystem, Result, SystemPath, SystemPathBuf,
};

/// Creates a file system with the given files.
///
Expand Down Expand Up @@ -651,15 +653,15 @@ mod tests {
#[test]
fn read_directory() {
let fs = with_files(["b.ts", "a/bar.py", "d.rs", "a/foo/bar.py", "a/baz.pyi"]);
let contents: Vec<DirEntry> = fs
let contents: Vec<DirectoryEntry> = fs
.read_directory("a")
.unwrap()
.map(Result::unwrap)
.collect();
let expected_contents = vec![
DirEntry::new(SystemPathBuf::from("/a/bar.py"), Ok(FileType::File)),
DirEntry::new(SystemPathBuf::from("/a/baz.pyi"), Ok(FileType::File)),
DirEntry::new(SystemPathBuf::from("/a/foo"), Ok(FileType::Directory)),
DirectoryEntry::new(SystemPathBuf::from("/a/bar.py"), Ok(FileType::File)),
DirectoryEntry::new(SystemPathBuf::from("/a/baz.pyi"), Ok(FileType::File)),
DirectoryEntry::new(SystemPathBuf::from("/a/foo"), Ok(FileType::Directory)),
];
assert_eq!(contents, expected_contents)
}
Expand Down
18 changes: 10 additions & 8 deletions crates/ruff_db/src/system/os.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use crate::system::{DirEntry, FileType, Metadata, Result, System, SystemPath, SystemPathBuf};
use crate::system::{
DirectoryEntry, FileType, Metadata, Result, System, SystemPath, SystemPathBuf,
};
use filetime::FileTime;
use std::any::Any;
use std::sync::Arc;
Expand Down Expand Up @@ -72,11 +74,11 @@ impl System for OsSystem {
fn read_directory(
&self,
path: &SystemPath,
) -> Result<Box<dyn Iterator<Item = Result<DirEntry>>>> {
) -> Result<Box<dyn Iterator<Item = Result<DirectoryEntry>>>> {
Ok(Box::new(
path.as_camino_path()
.read_dir_utf8()?
.map(|res| res.map(DirEntry::from)),
.map(|res| res.map(DirectoryEntry::from)),
))
}
}
Expand All @@ -93,7 +95,7 @@ impl From<std::fs::FileType> for FileType {
}
}

impl From<camino::Utf8DirEntry> for DirEntry {
impl From<camino::Utf8DirEntry> for DirectoryEntry {
fn from(value: camino::Utf8DirEntry) -> Self {
let file_type = value.file_type().map(FileType::from);
Self {
Expand Down Expand Up @@ -122,17 +124,17 @@ mod tests {
let tempdir_path = SystemPath::from_std_path(tempdir_path).unwrap();
let fs = OsSystem::new(tempdir_path);

let mut sorted_contents: Vec<DirEntry> = fs
let mut sorted_contents: Vec<DirectoryEntry> = fs
.read_directory(&tempdir_path.join("a"))
.unwrap()
.map(Result::unwrap)
.collect();
sorted_contents.sort_by(|a, b| a.path.cmp(&b.path));

let expected_contents = vec![
DirEntry::new(tempdir_path.join("a/bar.py"), Ok(FileType::File)),
DirEntry::new(tempdir_path.join("a/baz.pyi"), Ok(FileType::File)),
DirEntry::new(tempdir_path.join("a/foo"), Ok(FileType::Directory)),
DirectoryEntry::new(tempdir_path.join("a/bar.py"), Ok(FileType::File)),
DirectoryEntry::new(tempdir_path.join("a/baz.pyi"), Ok(FileType::File)),
DirectoryEntry::new(tempdir_path.join("a/foo"), Ok(FileType::Directory)),
];
assert_eq!(sorted_contents, expected_contents)
}
Expand Down
6 changes: 4 additions & 2 deletions crates/ruff_db/src/system/test.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use crate::files::File;
use crate::system::{DirEntry, MemoryFileSystem, Metadata, OsSystem, Result, System, SystemPath};
use crate::system::{
DirectoryEntry, MemoryFileSystem, Metadata, OsSystem, Result, System, SystemPath,
};
use crate::Db;
use std::any::Any;

Expand Down Expand Up @@ -89,7 +91,7 @@ impl System for TestSystem {
fn read_directory<'a>(
&'a self,
path: &SystemPath,
) -> Result<Box<dyn Iterator<Item = Result<DirEntry>> + 'a>> {
) -> Result<Box<dyn Iterator<Item = Result<DirectoryEntry>> + 'a>> {
match &self.inner {
TestFileSystem::Os(fs) => fs.read_directory(path),
TestFileSystem::Stub(fs) => Ok(Box::new(fs.read_directory(path)?)),
Expand Down

0 comments on commit 2018f9a

Please sign in to comment.