removeInstalledFile deletes the installed file only when CAM can prove it owns it: a symlink pointing at managedFile, or a copy whose content still matches.
(ins Install, managedFile string)
| 209 | // removeInstalledFile deletes the installed file only when CAM can prove it owns |
| 210 | // it: a symlink pointing at managedFile, or a copy whose content still matches. |
| 211 | func removeInstalledFile(ins Install, managedFile string) { |
| 212 | info, err := os.Lstat(ins.TargetPath) |
| 213 | if err != nil { |
| 214 | return |
| 215 | } |
| 216 | if info.Mode()&os.ModeSymlink != 0 { |
| 217 | if resolved, rerr := os.Readlink(ins.TargetPath); rerr == nil { |
| 218 | if filepath.Clean(resolved) == filepath.Clean(managedFile) { |
| 219 | os.Remove(ins.TargetPath) |
| 220 | } |
| 221 | } |
| 222 | return |
| 223 | } |
| 224 | if ins.LinkKind == "copy" { |
| 225 | if sameContent(ins.TargetPath, managedFile) { |
| 226 | os.Remove(ins.TargetPath) |
| 227 | } |
| 228 | } |
| 229 | } |
| 230 | |
| 231 | func sameContent(a, b string) bool { |
| 232 | da, err := os.ReadFile(a) |
no test coverage detected