Skip to content
Snippets Groups Projects
Verified Commit 9ebc5f4c authored by Ernesto Rico Schmidt's avatar Ernesto Rico Schmidt
Browse files

feat: add ResetState method and DeleteCounter type

parent a92a0094
No related branches found
No related tags found
No related merge requests found
......@@ -28,6 +28,14 @@ import (
"github.com/jinzhu/gorm"
)
type DeleteCounter struct {
Files int64 `json:"files"`
ImportLogs int64 `json:"importLogs"`
PlaylistEntries int64 `json:"playlistEntries"`
Playlists int64 `json:"playlists"`
Shows int64 `json:"shows"`
}
func (st *Store) getShowPath(showID uint64) string {
return filepath.Join(st.basePath, strconv.FormatUint(showID, 10))
}
......@@ -215,3 +223,33 @@ func (st *Store) ListShows() (shows []Show, err error) {
err = st.db.Find(&shows).Error
return
}
func removeDirectories(path string) (err error) {
dirs, err := filepath.Glob(path)
if err != nil {
return
}
for _, dir := range dirs {
err = os.RemoveAll(dir)
if err != nil {
return
}
}
return
}
func (st *Store) ResetState() (deleteCounter DeleteCounter, err error) {
importLogs := st.db.Exec("DELETE FROM import_logs").RowsAffected
playlistEntries := st.db.Exec("DELETE FROM playlist_entries").RowsAffected
playlists := st.db.Exec("DELETE FROM playlists").RowsAffected
files := st.db.Exec("DELETE FROM files").RowsAffected
shows := st.db.Exec("DELETE FROM shows").RowsAffected
err = removeDirectories(filepath.Join(st.basePath, "*"))
return DeleteCounter{Files: files, ImportLogs: importLogs, PlaylistEntries: playlistEntries, Playlists: playlists, Shows: shows}, err
}
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