Show More
@@ -60,7 +60,23 b' impl Node {' | |||
|
60 | 60 | // Are we're modifying the current file ? Is the the end of the path ? |
|
61 | 61 | let is_current_file = tail.is_empty() && head.is_empty(); |
|
62 | 62 | |
|
63 | // Potentially Replace the current file with a directory if it's marked | |
|
64 | // as `Removed` | |
|
65 | if !is_current_file { | |
|
63 | 66 | if let NodeKind::File(file) = &mut self.kind { |
|
67 | if file.entry.state == EntryState::Removed { | |
|
68 | self.kind = NodeKind::Directory(Directory { | |
|
69 | was_file: Some(Box::from(file.clone())), | |
|
70 | children: Default::default(), | |
|
71 | }) | |
|
72 | } | |
|
73 | } | |
|
74 | } | |
|
75 | match &mut self.kind { | |
|
76 | NodeKind::Directory(directory) => { | |
|
77 | Node::insert_in_directory(directory, new_entry, head, tail) | |
|
78 | } | |
|
79 | NodeKind::File(file) => { | |
|
64 | 80 | if is_current_file { |
|
65 | 81 | let new = Self { |
|
66 | 82 | kind: NodeKind::File(File { |
@@ -68,36 +84,23 b' impl Node {' | |||
|
68 | 84 | ..file.clone() |
|
69 | 85 | }), |
|
70 | 86 | }; |
|
71 |
|
|
|
87 | InsertResult { | |
|
72 | 88 | did_insert: false, |
|
73 | 89 | old_entry: Some(std::mem::replace(self, new)), |
|
74 |
} |
|
|
90 | } | |
|
75 | 91 | } else { |
|
76 | 92 | match file.entry.state { |
|
77 | // Only replace the current file with a directory if it's | |
|
78 | // marked as `Removed` | |
|
79 | 93 | EntryState::Removed => { |
|
80 | self.kind = NodeKind::Directory(Directory { | |
|
81 | was_file: Some(Box::from(file.clone())), | |
|
82 | children: Default::default(), | |
|
83 | }) | |
|
94 | unreachable!("Removed file turning into a directory was dealt with earlier") | |
|
84 | 95 | } |
|
85 | 96 | _ => { |
|
86 |
|
|
|
97 | Node::insert_in_file( | |
|
87 | 98 | file, new_entry, head, tail, |
|
88 | 99 | ) |
|
89 | 100 | } |
|
90 | 101 | } |
|
91 | 102 | } |
|
92 | 103 | } |
|
93 | ||
|
94 | match &mut self.kind { | |
|
95 | NodeKind::Directory(directory) => { | |
|
96 | Node::insert_in_directory(directory, new_entry, head, tail) | |
|
97 | } | |
|
98 | NodeKind::File(_) => { | |
|
99 | unreachable!("The file case has already been handled") | |
|
100 | } | |
|
101 | 104 | } |
|
102 | 105 | } |
|
103 | 106 |
General Comments 0
You need to be logged in to leave comments.
Login now