Remove `path` only when it is a regular file whose content Atomic owns.
(path: &Path)
| 118 | |
| 119 | /// Remove `path` only when it is a regular file whose content Atomic owns. |
| 120 | fn 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. |
| 148 | pub(crate) fn show_status(root: &Path) -> CliResult<()> { |
no test coverage detected