Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
//
// tank
//
// Import and Playlist Daemon for autoradio project
//
//
// Copyright (C) 2017-2019 Christian Pointner <equinox@helsinki.at>
//
// This file is part of tank.
//
// tank is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// any later version.
//
// tank is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with tank. If not, see <http://www.gnu.org/licenses/>.
//
package store
import (
"errors"
"os"
"path/filepath"
)
func (st *Store) getShowPath(show string) string {
return filepath.Join(st.basePath, show)
}
// this will not fail if the show already exists
func (st *Store) CreateShow(name string) (show *Show, err error) {
showDirPath := filepath.Join(st.basePath, name)
if err := os.Mkdir(showDirPath, 0755); err != nil {
if !os.IsExist(err) {
return nil, errors.New("unable to create directory for show '" + name + "': " + err.Error())
}
if stat, err := os.Stat(showDirPath); err != nil {
return nil, errors.New("unable to create directory for show '" + name + "': " + err.Error())
} else if !stat.IsDir() {
return nil, errors.New("unable to create directory for show '" + name + "': path exists and is not a directory")
}
}
show = &Show{Name: name}
err = st.db.FirstOrCreate(show).Error
return
}
func (st *Store) CloneShow(name, from string) error {
// TODO:
// within transaction: {
// check if show already exists -> error
// st.CreateShow(name)
// for file in files_of_show {
// create file in show <name> -> <dest-id>
// create hardlink for /store/base/path/<from>/<src-id> -> /store/base/path/<name>/<dest-id>
// }
// }
return ErrNotImplemented
}
// this will also remove all files and playlists belonging to the show!
func (st *Store) DeleteShow(name string) error {
if err := st.db.Delete(&Show{Name: name}).Error; err != nil {
return err
}
return os.RemoveAll(st.getShowPath(name))
}
func (st *Store) ListShows() (shows Shows, err error) {
err = st.db.Find(&shows).Error
return
}