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

Function install_or_refresh_dispatcher

atomic-cli/src/commands/git/hooks.rs:385–410  ·  view source on GitHub ↗
(path: &Path, script: &str)

Source from the content-addressed store, hash-verified

383}
384
385fn install_or_refresh_dispatcher(path: &Path, script: &str) -> io::Result<DispatcherInstall> {
386 let metadata = match fs::symlink_metadata(path) {
387 Ok(metadata) => Some(metadata),
388 Err(error) if error.kind() == ErrorKind::NotFound => None,
389 Err(error) => return Err(error),
390 };
391
392 match metadata {
393 None => {
394 write_new_executable(path, script.as_bytes())?;
395 Ok(DispatcherInstall::Installed)
396 }
397 Some(metadata) if metadata.file_type().is_symlink() || !metadata.file_type().is_file() => {
398 Ok(DispatcherInstall::Unmanaged)
399 }
400 Some(_) => {
401 let existing = fs::read(path)?;
402 if is_owned_dispatcher(&existing) || is_legacy_atomic_only(&existing) {
403 replace_owned_executable(path, script.as_bytes())?;
404 Ok(DispatcherInstall::Refreshed)
405 } else {
406 Ok(DispatcherInstall::Unmanaged)
407 }
408 }
409 }
410}
411
412pub(super) fn is_owned_dispatcher(content: &[u8]) -> bool {
413 let expected = format!("#!/bin/sh\n{DISPATCHER_MARKER}\n");

Callers 2

enable_shimFunction · 0.85

Calls 8

write_new_executableFunction · 0.85
is_owned_dispatcherFunction · 0.85
is_legacy_atomic_onlyFunction · 0.85
replace_owned_executableFunction · 0.85
readFunction · 0.50
kindMethod · 0.45
as_bytesMethod · 0.45
is_fileMethod · 0.45

Tested by 1