Przeglądaj źródła

Catch and output directory walking errors

Previously, app would panic and admins would see unhelpful errors.

This closes #620
pull/621/head
Matt Baer 1 rok temu
rodzic
commit
99d72881cf
2 zmienionych plików z 23 dodań i 3 usunięć
  1. +9
    -1
      author/author.go
  2. +14
    -2
      templates.go

+ 9
- 1
author/author.go Wyświetl plik

@@ -11,6 +11,7 @@
package author package author


import ( import (
"github.com/writeas/web-core/log"
"github.com/writefreely/writefreely/config" "github.com/writefreely/writefreely/config"
"os" "os"
"path/filepath" "path/filepath"
@@ -113,10 +114,17 @@ func IsValidUsername(cfg *config.Config, username string) bool {
// Username is invalid if page with the same name exists. So traverse // Username is invalid if page with the same name exists. So traverse
// available pages, adding them to reservedUsernames map that'll be checked // available pages, adding them to reservedUsernames map that'll be checked
// later. // later.
filepath.Walk(filepath.Join(cfg.Server.PagesParentDir, "pages"), func(path string, i os.FileInfo, err error) error {
err := filepath.Walk(filepath.Join(cfg.Server.PagesParentDir, "pages"), func(path string, i os.FileInfo, err error) error {
if err != nil {
return err
}
reservedUsernames[i.Name()] = true reservedUsernames[i.Name()] = true
return nil return nil
}) })
if err != nil {
log.Error("[IMPORTANT WARNING]: Could not determine IsValidUsername! %s", err)
return false
}


// Username is invalid if it is reserved! // Username is invalid if it is reserved!
if _, reserved := reservedUsernames[username]; reserved { if _, reserved := reservedUsernames[username]; reserved {


+ 14
- 2
templates.go Wyświetl plik

@@ -135,7 +135,10 @@ func InitTemplates(cfg *config.Config) error {


log.Info("Loading pages...") log.Info("Loading pages...")
// Initialize all static pages that use the base template // Initialize all static pages that use the base template
filepath.Walk(filepath.Join(cfg.Server.PagesParentDir, pagesDir), func(path string, i os.FileInfo, err error) error {
err = filepath.Walk(filepath.Join(cfg.Server.PagesParentDir, pagesDir), func(path string, i os.FileInfo, err error) error {
if err != nil {
return err
}
if !i.IsDir() && !strings.HasPrefix(i.Name(), ".") { if !i.IsDir() && !strings.HasPrefix(i.Name(), ".") {
key := i.Name() key := i.Name()
initPage(cfg.Server.PagesParentDir, path, key) initPage(cfg.Server.PagesParentDir, path, key)
@@ -143,10 +146,16 @@ func InitTemplates(cfg *config.Config) error {


return nil return nil
}) })
if err != nil {
return err
}


log.Info("Loading user pages...") log.Info("Loading user pages...")
// Initialize all user pages that use base templates // Initialize all user pages that use base templates
filepath.Walk(filepath.Join(cfg.Server.TemplatesParentDir, templatesDir, "user"), func(path string, f os.FileInfo, err error) error {
err = filepath.Walk(filepath.Join(cfg.Server.TemplatesParentDir, templatesDir, "user"), func(path string, f os.FileInfo, err error) error {
if err != nil {
return err
}
if !f.IsDir() && !strings.HasPrefix(f.Name(), ".") { if !f.IsDir() && !strings.HasPrefix(f.Name(), ".") {
corePath := path corePath := path
if cfg.Server.TemplatesParentDir != "" { if cfg.Server.TemplatesParentDir != "" {
@@ -162,6 +171,9 @@ func InitTemplates(cfg *config.Config) error {


return nil return nil
}) })
if err != nil {
return err
}


return nil return nil
} }


Ładowanie…
Anuluj
Zapisz