improve logging at startup (#51)
This bit me hard in the begining. While I was trying to figure out why tube I didn't show any files, it was silently creating directories all over the place. 😆 Reviewed-on: https://git.mills.io/prologic/tube/pulls/51 Co-authored-by: Heinrich 'Henrik' Langos <gumbo2000@noreply@mills.io> Co-committed-by: Heinrich 'Henrik' Langos <gumbo2000@noreply@mills.io>
This commit is contained in:
parent
dc5cceec37
commit
9952cc533a
3 changed files with 18 additions and 11 deletions
14
app/app.go
14
app/app.go
|
@ -161,11 +161,15 @@ func (a *App) Run() error {
|
||||||
}
|
}
|
||||||
a.Watcher.Add(p.Path)
|
a.Watcher.Add(p.Path)
|
||||||
}
|
}
|
||||||
if err := os.MkdirAll(a.Config.Server.UploadPath, 0o755); err != nil {
|
if _, err := os.Stat(a.Config.Server.UploadPath) ; err != nil && os.IsNotExist(err) {
|
||||||
return fmt.Errorf(
|
log.Warn(
|
||||||
"error creating upload path %s: %w",
|
fmt.Sprintf("app: upload path '%s' does not exist. Creating it now.",
|
||||||
a.Config.Server.UploadPath, err,
|
a.Config.Server.UploadPath))
|
||||||
)
|
if err := os.MkdirAll(a.Config.Server.UploadPath, 0o755); err != nil {
|
||||||
|
return fmt.Errorf(
|
||||||
|
"error creating upload path %s: %w",
|
||||||
|
a.Config.Server.UploadPath, err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
buildFeed(a)
|
buildFeed(a)
|
||||||
go startWatcher(a)
|
go startWatcher(a)
|
||||||
|
|
|
@ -4,7 +4,7 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
log "github.com/sirupsen/logrus"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
@ -41,8 +41,11 @@ func (lib *Library) AddPath(p *Path) error {
|
||||||
return errors.New(fmt.Sprintf("media: duplicate library prefix '%s'", p.Prefix))
|
return errors.New(fmt.Sprintf("media: duplicate library prefix '%s'", p.Prefix))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if err := os.MkdirAll(p.Path, 0755); err != nil {
|
if _, err := os.Stat(p.Path) ; err != nil && os.IsNotExist(err) {
|
||||||
return fmt.Errorf("error creating library path %s: %w", p.Path, err)
|
log.Warn(fmt.Sprintf("media: library path '%s' does not exist. Creating it now.", p.Path))
|
||||||
|
if err := os.MkdirAll(p.Path, 0o755); err != nil {
|
||||||
|
return fmt.Errorf("error creating library path %s: %w", p.Path, err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
lib.Paths[p.Path] = p
|
lib.Paths[p.Path] = p
|
||||||
return nil
|
return nil
|
||||||
|
@ -84,7 +87,7 @@ func (lib *Library) Add(fp string) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
lib.Videos[v.ID] = v
|
lib.Videos[v.ID] = v
|
||||||
log.Println("Added:", v.Path)
|
log.Debug("Added:", v.Path)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -111,7 +114,7 @@ func (lib *Library) Remove(fp string) {
|
||||||
v, ok := lib.Videos[id]
|
v, ok := lib.Videos[id]
|
||||||
if ok {
|
if ok {
|
||||||
delete(lib.Videos, id)
|
delete(lib.Videos, id)
|
||||||
log.Println("Removed:", v.Path)
|
log.Debug("Removed:", v.Path)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -32,7 +32,7 @@ func Download(url, filename string) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := ioutil.WriteFile(filename, data, 0644); err != nil {
|
if err := ioutil.WriteFile(filename, data, 0o644); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue