-
Notifications
You must be signed in to change notification settings - Fork 28
refactor!: use same paths representation for unix/windows #390
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
3706a32
af7037f
aff6924
a1f2a33
b8516d2
c71e783
377d52f
d3bb945
06b086a
d614f11
0803495
d127fce
04f2e0b
f4e27f2
3e421ae
219f56c
9401a4e
4655275
b6abc4e
0982644
f7bc8a5
4a34307
5db575d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,6 @@ | ||
| use std::{ffi::OsString, path::PathBuf}; | ||
| use crate::backend::node::{Metadata, Node, NodeType}; | ||
|
|
||
| use crate::{ | ||
| backend::node::{Metadata, Node, NodeType}, | ||
| blob::tree::comp_to_osstr, | ||
| }; | ||
| use typed_path::{Component, UnixPathBuf}; | ||
|
|
||
| /// `TreeIterator` turns an Iterator yielding items with paths and Nodes into an | ||
| /// Iterator which ensures that all subdirectories are visited and closed. | ||
|
|
@@ -18,7 +15,7 @@ pub(crate) struct TreeIterator<T, I> { | |
| /// The original Iterator. | ||
| iter: I, | ||
| /// The current path. | ||
| path: PathBuf, | ||
| path: UnixPathBuf, | ||
| /// The current item. | ||
| item: Option<T>, | ||
| } | ||
|
|
@@ -31,7 +28,7 @@ where | |
| let item = iter.next(); | ||
| Self { | ||
| iter, | ||
| path: PathBuf::new(), | ||
| path: UnixPathBuf::new(), | ||
| item, | ||
| } | ||
| } | ||
|
|
@@ -49,32 +46,25 @@ where | |
| #[derive(Debug)] | ||
| pub(crate) enum TreeType<T, U> { | ||
| /// New tree to be inserted. | ||
| NewTree((PathBuf, Node, U)), | ||
| NewTree((UnixPathBuf, Node, U)), | ||
| /// A pseudo item which indicates that a tree is finished. | ||
| EndTree, | ||
| /// Original item. | ||
| Other((PathBuf, Node, T)), | ||
| Other((UnixPathBuf, Node, T)), | ||
| } | ||
|
|
||
| impl<I, O> Iterator for TreeIterator<(PathBuf, Node, O), I> | ||
| impl<I, O> Iterator for TreeIterator<(UnixPathBuf, Node, O), I> | ||
| where | ||
| I: Iterator<Item = (PathBuf, Node, O)>, | ||
| I: Iterator<Item = (UnixPathBuf, Node, O)>, | ||
| { | ||
| type Item = TreeType<O, OsString>; | ||
| type Item = TreeType<O, Vec<u8>>; | ||
| fn next(&mut self) -> Option<Self::Item> { | ||
| match &self.item { | ||
| None => { | ||
| if self.path.pop() { | ||
| Some(TreeType::EndTree) | ||
| } else { | ||
| // Check if we still have a path prefix open... | ||
| match self.path.components().next() { | ||
| Some(std::path::Component::Prefix(..)) => { | ||
| self.path = PathBuf::new(); | ||
| Some(TreeType::EndTree) | ||
| } | ||
| _ => None, | ||
| } | ||
| None | ||
| } | ||
| } | ||
| Some((path, node, _)) => { | ||
|
|
@@ -84,24 +74,25 @@ where | |
| Some(TreeType::EndTree) | ||
| } | ||
| Ok(missing_dirs) => { | ||
| for comp in missing_dirs.components() { | ||
| self.path.push(comp); | ||
| // process next normal path component - other components are simply ignored | ||
| if let Some(p) = comp_to_osstr(comp).ok().flatten() { | ||
| if node.is_dir() && path == &self.path { | ||
| let (path, node, _) = self.item.take().unwrap(); | ||
| self.item = self.iter.next(); | ||
| let name = node.name(); | ||
| return Some(TreeType::NewTree((path, node, name))); | ||
| } | ||
| // Use mode 755 for missing dirs, so they can be accessed | ||
| let meta = Metadata { | ||
| mode: Some(0o755), | ||
| ..Default::default() | ||
| }; | ||
| let node = Node::new_node(&p, NodeType::Dir, meta); | ||
| return Some(TreeType::NewTree((self.path.clone(), node, p))); | ||
| if let Some(p) = missing_dirs.components().next() { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why remove the Both PS: after seeing the now deleted |
||
| self.path.push(p); | ||
| if node.is_dir() && path == &self.path { | ||
| let (path, node, _) = self.item.take().unwrap(); | ||
| self.item = self.iter.next(); | ||
| let name = node.name().to_vec(); | ||
| return Some(TreeType::NewTree((path, node, name))); | ||
| } | ||
| // Use mode 755 for missing dirs, so they can be accessed | ||
| let meta = Metadata { | ||
| mode: Some(0o755), | ||
| ..Default::default() | ||
| }; | ||
| let node = Node::new_node(p.as_bytes(), NodeType::Dir, meta); | ||
| return Some(TreeType::NewTree(( | ||
| self.path.clone(), | ||
| node, | ||
| p.as_bytes().to_vec(), | ||
| ))); | ||
aawsome marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| // there wasn't any normal path component to process - return current item | ||
| let item = self.item.take().unwrap(); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.