Uninstall removes the link/copy CAM placed (when safe) and deletes the row.
(ctx context.Context, installID int64)
| 176 | |
| 177 | // Uninstall removes the link/copy CAM placed (when safe) and deletes the row. |
| 178 | func (s *Store) Uninstall(ctx context.Context, installID int64) error { |
| 179 | if err := s.Init(ctx); err != nil { |
| 180 | return err |
| 181 | } |
| 182 | db, err := s.open() |
| 183 | if err != nil { |
| 184 | return err |
| 185 | } |
| 186 | defer db.Close() |
| 187 | |
| 188 | var ins Install |
| 189 | var instructionID int64 |
| 190 | var created string |
| 191 | err = db.QueryRowContext(ctx, `SELECT id, instruction_id, app, level, project_dir, target_path, link_kind, created_at FROM instruction_installs WHERE id = ?`, installID). |
| 192 | Scan(&ins.ID, &instructionID, &ins.App, &ins.Level, &ins.ProjectDir, &ins.TargetPath, &ins.LinkKind, &created) |
| 193 | if err != nil { |
| 194 | // Idempotent: nothing to remove. |
| 195 | return nil |
| 196 | } |
| 197 | |
| 198 | var name string |
| 199 | if nerr := db.QueryRowContext(ctx, `SELECT name FROM instructions WHERE id = ?`, instructionID).Scan(&name); nerr == nil { |
| 200 | removeInstalledFile(ins, managedFilePath(name)) |
| 201 | } |
| 202 | |
| 203 | if _, err := db.ExecContext(ctx, `DELETE FROM instruction_installs WHERE id = ?`, installID); err != nil { |
| 204 | return fmt.Errorf("instructions: delete install: %w", err) |
| 205 | } |
| 206 | return nil |
| 207 | } |
| 208 | |
| 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. |