(
&self,
working_copy: WorkingCopyId,
entries: &[MaterializedEntry],
only_paths: Option<&std::collections::HashSet<String>>,
prefix: Option<&str>,
mut e
| 794 | } |
| 795 | |
| 796 | fn remove_absent_entries( |
| 797 | &self, |
| 798 | working_copy: WorkingCopyId, |
| 799 | entries: &[MaterializedEntry], |
| 800 | only_paths: Option<&std::collections::HashSet<String>>, |
| 801 | prefix: Option<&str>, |
| 802 | mut effect_executor: Option<&mut dyn MaterializationEffectExecutor>, |
| 803 | ) -> Result<usize, RepositoryError> { |
| 804 | let selected = |path: &str| { |
| 805 | only_paths.is_none_or(|paths| paths.contains(path)) |
| 806 | && prefix.is_none_or(|prefix| path.starts_with(prefix)) |
| 807 | }; |
| 808 | let mut removed_files = 0; |
| 809 | |
| 810 | for entry in entries |
| 811 | .iter() |
| 812 | .filter(|entry| !entry.is_directory() && selected(entry.path())) |
| 813 | { |
| 814 | if let Some(executor) = effect_executor.as_deref_mut() { |
| 815 | if executor.remove_path(entry.path())? { |
| 816 | removed_files += 1; |
| 817 | } |
| 818 | } else { |
| 819 | let absolute = self.root.join(entry.path()); |
| 820 | match std::fs::symlink_metadata(&absolute) { |
| 821 | Ok(metadata) |
| 822 | if metadata.file_type().is_file() || metadata.file_type().is_symlink() => |
| 823 | { |
| 824 | std::fs::remove_file(&absolute).map_err(|error| { |
| 825 | RepositoryError::Output(format!( |
| 826 | "failed to remove absent materialized path '{}': {}", |
| 827 | entry.path(), |
| 828 | error |
| 829 | )) |
| 830 | })?; |
| 831 | removed_files += 1; |
| 832 | } |
| 833 | Ok(_) => { |
| 834 | return Err(RepositoryError::InvalidOperation { |
| 835 | message: format!( |
| 836 | "cannot materialize absent file '{}': working-copy path is not a file", |
| 837 | entry.path() |
| 838 | ), |
| 839 | }); |
| 840 | } |
| 841 | Err(error) if error.kind() == std::io::ErrorKind::NotFound => {} |
| 842 | Err(error) => return Err(RepositoryError::Io(error)), |
| 843 | } |
| 844 | } |
| 845 | self.delete_working_copy_file_index(working_copy, entry.path())?; |
| 846 | } |
| 847 | |
| 848 | let mut directories: Vec<_> = entries |
| 849 | .iter() |
| 850 | .filter(|entry| entry.is_directory() && selected(entry.path())) |
| 851 | .collect(); |
| 852 | directories.sort_by_key(|entry| std::cmp::Reverse(entry.path().matches('/').count())); |
| 853 | for entry in directories { |
no test coverage detected