MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / copy_entry

Function copy_entry

atomic-repository/src/repository/operation.rs:4972–5012  ·  view source on GitHub ↗
(source: &Path, destination: &Path)

Source from the content-addressed store, hash-verified

4970}
4971
4972fn 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
5014pub(super) fn write_new_synced(path: &Path, bytes: &[u8]) -> Result<(), RepositoryError> {
5015 let mut file = OpenOptions::new().write(true).create_new(true).open(path)?;

Callers 2

replace_directoryFunction · 0.85

Calls 14

openFunction · 0.85
metadata_modeFunction · 0.85
os_str_bytesFunction · 0.85
sync_directoryFunction · 0.85
parentMethod · 0.80
is_dirMethod · 0.80
create_symlinkFunction · 0.70
set_modeFunction · 0.70
is_fileMethod · 0.45
openMethod · 0.45
writeMethod · 0.45
cmpMethod · 0.45

Tested by

no test coverage detected