diff --git a/handler/projects/projects.go b/handler/projects/projects.go index 639819d..9c0f0ee 100644 --- a/handler/projects/projects.go +++ b/handler/projects/projects.go @@ -4,6 +4,8 @@ import ( "io/ioutil" "log" "net/http" + "os" + "path/filepath" "strings" "github.com/unders/docit/template" @@ -15,6 +17,32 @@ const notFoundMsg = "
Projects dir could not be read
" +func isProject(root string, f os.FileInfo) bool { + if f.IsDir() { + return true + } + + if f.Mode()&os.ModeSymlink == 0 { + return false + } + + dir, err := os.Readlink(root + "/" + f.Name()) + if err != nil { + return false + } + + if !filepath.IsAbs(dir) { + dir = root + "/" + dir + } + + fileInfo, err := os.Stat(dir) + if err != nil { + return false + } + + return fileInfo.IsDir() +} + // Handle renders projects in root directory. func Handle(root string) func(http.ResponseWriter, *http.Request) { return func(w http.ResponseWriter, req *http.Request) { @@ -37,7 +65,7 @@ func Handle(root string) func(http.ResponseWriter, *http.Request) { projects := make([]template.Project, length) for i, file := range dir { - if file.IsDir() { + if isProject(root, file) { name := file.Name() proj := template.Project{