implement mTimeFor

master
nate smith 2019-09-06 17:41:54 -05:00
parent 32ac65672d
commit 70ab5b10d9
1 changed files with 31 additions and 15 deletions

46
main.go
View File

@ -17,6 +17,8 @@ import (
"log" "log"
"os" "os"
"os/exec" "os/exec"
"path"
"path/filepath"
"strings" "strings"
"time" "time"
) )
@ -36,7 +38,7 @@ type NewsEntry struct {
type User struct { type User struct {
Username string `json:"username"` // Username of user Username string `json:"username"` // Username of user
PageTitle string `json:"title"` // Title of user's HTML page, if they have one PageTitle string `json:"title"` // Title of user's HTML page, if they have one
Mtime int `json:"mtime"` // Timestamp representing the last time a user's index.html was modified Mtime int64 `json:"mtime"` // Timestamp representing the last time a user's index.html was modified
// Town additions // Town additions
DefaultPage bool `json:"default"` // Whether or not user has updated their default index.html DefaultPage bool `json:"default"` // Whether or not user has updated their default index.html
Favicon string `json:"favicon"` // URL to a small image representing the user Favicon string `json:"favicon"` // URL to a small image representing the user
@ -60,16 +62,20 @@ type TildeData struct {
News []NewsEntry // Collection of town news entries News []NewsEntry // Collection of town news entries
} }
func homesDir() string {
hDir := os.Getenv("HOMES_DIR")
if hDir == "" {
hDir = "/home"
}
return hDir
}
func news() []NewsEntry { func news() []NewsEntry {
// TODO // TODO
return []NewsEntry{} return []NewsEntry{}
} }
func userCount(users []User) int {
// TODO
return 0
}
func pageTitleFor(username string) string { func pageTitleFor(username string) string {
// TODO // TODO
return "TODO" return "TODO"
@ -91,9 +97,24 @@ func systemUsers() map[string]bool {
return systemUsers return systemUsers
} }
func mtimeFor(username string) int { func mtimeFor(username string) int64 {
// TODO path := path.Join(homesDir(), username, "public_html")
return 0 var maxMtime int64 = 0
err := filepath.Walk(path, func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}
if maxMtime < info.ModTime().Unix() {
maxMtime = info.ModTime().Unix()
}
return nil
})
if err != nil {
fmt.Fprintf(os.Stderr, "error walking %q: %v\n", path, err)
}
return maxMtime
} }
func detectDefaultPageFor(username string) bool { func detectDefaultPageFor(username string) bool {
@ -114,12 +135,7 @@ func getUsers() (users []User) {
// not opposed to going back to that; going back to parsing /home is mainly to // not opposed to going back to that; going back to parsing /home is mainly to
// get this new version going. // get this new version going.
homeDir := os.Getenv("HOMES_DIR") out, err := exec.Command("ls", homesDir()).Output()
if homeDir == "" {
homeDir = "/home"
}
out, err := exec.Command("ls", homeDir).Output()
scanner := bufio.NewScanner(bytes.NewReader(out)) scanner := bufio.NewScanner(bytes.NewReader(out))
if err != nil { if err != nil {