Source

devsrvr / src / compilation.go

Full commit
package main

import (
    "os"
    "path/filepath"
)

type modTimeVisitor struct {
    mostRecentModTime int64
}

func (v *modTimeVisitor) VisitDir(path string, f *os.FileInfo) bool {
    // println("visiting dir", path)
    ext := filepath.Ext(f.Name)
    if ((ext == ".go" || ext == ".html") && f.Mtime_ns > v.mostRecentModTime) {
        v.mostRecentModTime = f.Mtime_ns
    }
    return true
}

func (v *modTimeVisitor) VisitFile(path string, f *os.FileInfo) {
    // println("visiting file", path)
    ext := filepath.Ext(f.Name)
    if ((ext == ".go" || ext == ".html") && f.Mtime_ns > v.mostRecentModTime) {
        v.mostRecentModTime = f.Mtime_ns
    }
}

// return the most recent modified time for any file
// in the given directory hierarchy
func LastModifiedTime(root string) int64 {
    visitor := &modTimeVisitor{ mostRecentModTime: 0 }
    filepath.Walk(root, visitor, nil)
    return visitor.mostRecentModTime
}