Skip to content
Snippets Groups Projects
Commit a820fdc6 authored by Christian Pointner's avatar Christian Pointner
Browse files

fix deletion of shows

parent edfe76bb
No related branches found
No related tags found
No related merge requests found
......@@ -178,13 +178,37 @@ func (st *Store) CloneShow(name, from string) (show *Show, err error) {
}
// this will also remove all files and playlists belonging to the show!
// TODO: fix cascading errors (deletion of files is tried before deletion of playlists
// which does not work when files are still refrenced by playlists...
func (st *Store) DeleteShow(name string) error {
if err := st.db.Delete(&Show{Name: name}).Error; err != nil {
return err
func (st *Store) DeleteShow(name string) (err error) {
tx := st.db.Begin()
defer func() {
if r := recover(); r != nil {
tx.Rollback()
if err == nil {
err = fmt.Errorf("runtime panic: %+v", r)
}
}
}()
// We have to delete the playlists first since by default files are deleted before
// playlists which does not work as long as there are playlists that reference the files
// to be deleted.
// As soon as playlists are gone, deleting the show will cascade to delete
// the files as well.
if err = tx.Where("show_name = ?", name).Delete(&Playlist{}).Error; err != nil {
tx.Rollback()
return
}
if err = tx.Delete(&Show{Name: name}).Error; err != nil {
tx.Rollback()
return
}
return os.RemoveAll(st.getShowPath(name))
if err = os.RemoveAll(st.getShowPath(name)); err != nil {
tx.Rollback()
return
}
err = tx.Commit().Error
return
}
func (st *Store) ListShows() (shows Shows, err error) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment