-
Notifications
You must be signed in to change notification settings - Fork 24
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
9d26ab2
0ac8b2b
9aac279
8203cce
c9b1c66
68705ff
e7225f8
eb14d64
bc1eb8b
51898b9
a3d8e28
0f8deff
43e4081
45fdc8b
18ee311
123ba2f
bf428f0
a8486dc
60fc357
e424290
6fc111d
4fcd32f
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.
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 @@ | |
/// The original Iterator. | ||
iter: I, | ||
/// The current path. | ||
path: PathBuf, | ||
path: UnixPathBuf, | ||
/// The current item. | ||
item: Option<T>, | ||
} | ||
|
@@ -31,7 +28,7 @@ | |
let item = iter.next(); | ||
Self { | ||
iter, | ||
path: PathBuf::new(), | ||
path: UnixPathBuf::new(), | ||
item, | ||
} | ||
} | ||
|
@@ -49,32 +46,25 @@ | |
#[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 @@ | |
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() { | ||
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.