Compare commits

...

3 Commits
trunk ... foo

Author SHA1 Message Date
vilmibm 17e95105c8 foo 2021-11-12 18:43:43 +00:00
vilmibm 890e8e71be muffle some more errors 2021-04-27 17:44:04 +00:00
vilmibm 34574c0713 do not bother printing index read errors 2021-04-27 17:27:59 +00:00
2 changed files with 5 additions and 10 deletions

View File

@ -1,3 +1,4 @@
Junk commit
# townstats # townstats
This program dumps information about tilde.town in the [Tilde Data Protocol](http://protocol.club/~datagrok/beta-wiki/tdp.html). This program dumps information about tilde.town in the [Tilde Data Protocol](http://protocol.club/~datagrok/beta-wiki/tdp.html).

12
main.go
View File

@ -107,7 +107,7 @@ func getNews() (entries []newsEntry, err error) {
} else if kv[0] == "title" { } else if kv[0] == "title" {
current.Title = strings.TrimSpace(kv[1]) current.Title = strings.TrimSpace(kv[1])
} else { } else {
log.Printf("Ignoring unknown metadata in news entry: %v\n", newsLine) log.Printf("ignoring unknown metadata in news entry: %v\n", newsLine)
} }
if current.Pubdate != "" && current.Title != "" { if current.Pubdate != "" && current.Title != "" {
inMeta = false inMeta = false
@ -138,7 +138,7 @@ func indexPathFor(username string) (string, error) {
} }
if indexPath == "" { if indexPath == "" {
return "", fmt.Errorf("Failed to locate index file for %v; tried %v; encountered errors: %v", username, potentialPaths, errs) return "", fmt.Errorf("failed to locate index file for %v; tried %v; encountered errors: %v", username, potentialPaths, errs)
} }
return indexPath, nil return indexPath, nil
@ -148,12 +148,10 @@ func pageTitleFor(username string) string {
pageTitleRe := regexp.MustCompile(`<title[^>]*>(.*)</title>`) pageTitleRe := regexp.MustCompile(`<title[^>]*>(.*)</title>`)
indexPath, err := indexPathFor(username) indexPath, err := indexPathFor(username)
if err != nil { if err != nil {
log.Print(err)
return "" return ""
} }
content, err := ioutil.ReadFile(indexPath) content, err := ioutil.ReadFile(indexPath)
if err != nil { if err != nil {
log.Printf("failed to read %q: %v\n", indexPath, err)
return "" return ""
} }
titleMatch := pageTitleRe.FindStringSubmatch(string(content)) titleMatch := pageTitleRe.FindStringSubmatch(string(content))
@ -182,7 +180,7 @@ func systemUsers() map[string]bool {
func mtimeFor(username string) int64 { func mtimeFor(username string) int64 {
path := path.Join(homesDir(), username, "public_html") path := path.Join(homesDir(), username, "public_html")
var maxMtime int64 = 0 var maxMtime int64 = 0
err := filepath.Walk(path, func(path string, info os.FileInfo, err error) error { _ = filepath.Walk(path, func(path string, info os.FileInfo, err error) error {
if err != nil { if err != nil {
return err return err
} }
@ -191,9 +189,6 @@ func mtimeFor(username string) int64 {
} }
return nil return nil
}) })
if err != nil {
log.Printf("error walking %q: %v\n", path, err)
}
return maxMtime return maxMtime
} }
@ -201,7 +196,6 @@ func mtimeFor(username string) int64 {
func detectDefaultPageFor(username string, defaultHTML []byte) bool { func detectDefaultPageFor(username string, defaultHTML []byte) bool {
indexPath, err := indexPathFor(username) indexPath, err := indexPathFor(username)
if err != nil { if err != nil {
log.Print(err)
return false return false
} }
indexFile, err := os.Open(indexPath) indexFile, err := os.Open(indexPath)