Delete uninstalls every install, removes the managed file, and deletes rows.
(ctx context.Context, id int64)
| 360 | |
| 361 | // Delete uninstalls every install, removes the managed file, and deletes rows. |
| 362 | func (s *Store) Delete(ctx context.Context, id int64) error { |
| 363 | if err := s.Init(ctx); err != nil { |
| 364 | return err |
| 365 | } |
| 366 | db, err := s.open() |
| 367 | if err != nil { |
| 368 | return err |
| 369 | } |
| 370 | defer db.Close() |
| 371 | |
| 372 | current, err := getTx(ctx, db, id) |
| 373 | if err != nil { |
| 374 | return err |
| 375 | } |
| 376 | |
| 377 | for _, ins := range current.Installs { |
| 378 | removeInstalledFile(ins, managedFilePath(current.Name)) |
| 379 | } |
| 380 | if _, err := db.ExecContext(ctx, `DELETE FROM instruction_installs WHERE instruction_id = ?`, id); err != nil { |
| 381 | return fmt.Errorf("instructions: delete installs: %w", err) |
| 382 | } |
| 383 | if _, err := db.ExecContext(ctx, `DELETE FROM instructions WHERE id = ?`, id); err != nil { |
| 384 | return fmt.Errorf("instructions: delete: %w", err) |
| 385 | } |
| 386 | os.Remove(managedFilePath(current.Name)) |
| 387 | return nil |
| 388 | } |
| 389 | |
| 390 | // retargetSymlink replaces the symlink at target so it points at newSrc. |
| 391 | func retargetSymlink(target, newSrc string) { |