(source: &Path, destination: &Path)
| 4970 | } |
| 4971 | |
| 4972 | fn copy_entry(source: &Path, destination: &Path) -> Result<(), RepositoryError> { |
| 4973 | let metadata = fs::symlink_metadata(source)?; |
| 4974 | if metadata.file_type().is_symlink() { |
| 4975 | if let Some(parent) = destination.parent() { |
| 4976 | fs::create_dir_all(parent)?; |
| 4977 | } |
| 4978 | create_symlink(&fs::read_link(source)?, destination, source)?; |
| 4979 | } else if metadata.is_file() { |
| 4980 | if let Some(parent) = destination.parent() { |
| 4981 | fs::create_dir_all(parent)?; |
| 4982 | } |
| 4983 | let mut input = File::open(source)?; |
| 4984 | let mut output = OpenOptions::new() |
| 4985 | .write(true) |
| 4986 | .create_new(true) |
| 4987 | .open(destination)?; |
| 4988 | std::io::copy(&mut input, &mut output)?; |
| 4989 | set_mode(destination, metadata_mode(&metadata))?; |
| 4990 | output.sync_all()?; |
| 4991 | } else if metadata.is_dir() { |
| 4992 | fs::create_dir(destination)?; |
| 4993 | let mut entries = fs::read_dir(source)?.collect::<Result<Vec<_>, _>>()?; |
| 4994 | entries.sort_by(|left, right| { |
| 4995 | os_str_bytes(left.file_name().as_os_str()) |
| 4996 | .cmp(&os_str_bytes(right.file_name().as_os_str())) |
| 4997 | }); |
| 4998 | for entry in entries { |
| 4999 | copy_entry(&entry.path(), &destination.join(entry.file_name()))?; |
| 5000 | } |
| 5001 | set_mode(destination, metadata_mode(&metadata))?; |
| 5002 | sync_directory(destination)?; |
| 5003 | } else { |
| 5004 | return Err(RepositoryError::InvalidOperation { |
| 5005 | message: format!( |
| 5006 | "operation cannot back up special filesystem entry '{}'", |
| 5007 | source.display() |
| 5008 | ), |
| 5009 | }); |
| 5010 | } |
| 5011 | Ok(()) |
| 5012 | } |
| 5013 | |
| 5014 | pub(super) fn write_new_synced(path: &Path, bytes: &[u8]) -> Result<(), RepositoryError> { |
| 5015 | let mut file = OpenOptions::new().write(true).create_new(true).open(path)?; |
no test coverage detected