Skip to content

Commit

Permalink
Basic walk_directories implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaReiser committed Jul 13, 2024
1 parent a71bc3f commit 9f4350a
Show file tree
Hide file tree
Showing 6 changed files with 1,011 additions and 61 deletions.
2 changes: 1 addition & 1 deletion crates/ruff_db/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ insta = { workspace = true }
tempfile = { workspace = true }

[features]
os = []
os = ["ignore"]
24 changes: 12 additions & 12 deletions crates/ruff_db/src/system.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
use std::fmt::Debug;

pub use memory_fs::MemoryFileSystem;
#[cfg(feature = "os")]
pub use os::OsSystem;
use std::fmt::Debug;
pub use test::{DbWithTestSystem, TestSystem};
use walk_directory::WalkDirectoryBuilder;

use crate::file_revision::FileRevision;

Expand All @@ -13,6 +15,7 @@ mod memory_fs;
mod os;
mod path;
mod test;
pub mod walk_directory;

pub type Result<T> = std::io::Result<T>;

Expand Down Expand Up @@ -85,6 +88,9 @@ pub trait System: Debug {
path: &SystemPath,
) -> Result<Box<dyn Iterator<Item = Result<DirectoryEntry>> + 'a>>;

/// Recursively walks the content of `path`.
fn walk_directory(&self, path: &SystemPath) -> WalkDirectoryBuilder;

fn as_any(&self) -> &dyn std::any::Any;
}

Expand Down Expand Up @@ -130,28 +136,22 @@ impl FileType {
}
}

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

impl DirectoryEntry {
pub fn new(path: SystemPathBuf, file_type: Result<FileType>) -> Self {
pub fn new(path: SystemPathBuf, file_type: FileType) -> Self {
Self { path, file_type }
}

pub fn path(&self) -> &SystemPath {
&self.path
}

pub fn file_type(&self) -> &Result<FileType> {
&self.file_type
}
}

impl PartialEq for DirectoryEntry {
fn eq(&self, other: &Self) -> bool {
self.path == other.path
pub fn file_type(&self) -> FileType {
self.file_type
}
}
Loading

0 comments on commit 9f4350a

Please sign in to comment.