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

Function copy_entry

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

Source from the content-addressed store, hash-verified

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

Callers 2

replace_directoryFunction · 0.85

Calls 14

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
openFunction · 0.50
is_fileMethod · 0.45
openMethod · 0.45
writeMethod · 0.45
cmpMethod · 0.45

Tested by

no test coverage detected