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

Function remove_owned_hook

atomic-cli/src/commands/git/hook_dispatchers.rs:120–145  ·  view source on GitHub ↗

Remove `path` only when it is a regular file whose content Atomic owns.

(path: &Path)

Source from the content-addressed store, hash-verified

118
119/// Remove `path` only when it is a regular file whose content Atomic owns.
120fn remove_owned_hook(path: &Path) -> CliResult<HookRemoval> {
121 let metadata = match fs::symlink_metadata(path) {
122 Ok(metadata) => metadata,
123 Err(error) if error.kind() == ErrorKind::NotFound => return Ok(HookRemoval::Absent),
124 Err(error) => {
125 return Err(git_error(format!(
126 "cannot inspect hook '{}': {error}",
127 path.display()
128 )))
129 }
130 };
131 if metadata.file_type().is_symlink() {
132 return Ok(HookRemoval::Kept("an unmanaged symlink"));
133 }
134 if !metadata.file_type().is_file() {
135 return Ok(HookRemoval::Kept("not a regular file"));
136 }
137 let content = fs::read(path)
138 .map_err(|error| git_error(format!("cannot read hook '{}': {error}", path.display())))?;
139 if !(is_owned_dispatcher(&content) || is_legacy_atomic_only(&content)) {
140 return Ok(HookRemoval::Kept("not Atomic-owned"));
141 }
142 fs::remove_file(path)
143 .map_err(|error| git_error(format!("cannot remove hook '{}': {error}", path.display())))?;
144 Ok(HookRemoval::Removed)
145}
146
147/// Report the state of every advisory dispatcher.
148pub(crate) fn show_status(root: &Path) -> CliResult<()> {

Callers 2

report_legacy_removalFunction · 0.85

Calls 6

is_owned_dispatcherFunction · 0.85
is_legacy_atomic_onlyFunction · 0.85
git_errorFunction · 0.70
readFunction · 0.50
kindMethod · 0.45
is_fileMethod · 0.45

Tested by

no test coverage detected