github.com/cloud-foundations/dominator@v0.0.0-20221004181915-6e4fee580046/imageserver/httpd/listComputedInodes.go (about) 1 package httpd 2 3 import ( 4 "bufio" 5 "fmt" 6 "net/http" 7 "path" 8 9 "github.com/Cloud-Foundations/Dominator/lib/filesystem" 10 "github.com/Cloud-Foundations/Dominator/lib/html" 11 ) 12 13 func (s state) listComputedInodesHandler(w http.ResponseWriter, 14 req *http.Request) { 15 writer := bufio.NewWriter(w) 16 defer writer.Flush() 17 imageName := req.URL.RawQuery 18 fmt.Fprintf(writer, "<title>image %s computed inodes</title>\n", imageName) 19 fmt.Fprintln(writer, `<style> 20 table, th, td { 21 border-collapse: collapse; 22 } 23 </style>`) 24 fmt.Fprintln(writer, "<body>") 25 fmt.Fprintln(writer, "<h3>") 26 if image := s.imageDataBase.GetImage(imageName); image == nil { 27 fmt.Fprintf(writer, "Image: %s UNKNOWN!\n", imageName) 28 } else { 29 fmt.Fprintf(writer, "Computed files for image: %s\n", imageName) 30 fmt.Fprintln(writer, "</h3>") 31 fmt.Fprintln(writer, `<table border="1" style="width:100%">`) 32 tw, _ := html.NewTableWriter(writer, true, "Filename", "Data Source") 33 // Walk the file-system to leverage stable and friendly sort order. 34 listComputedInodes(tw, &image.FileSystem.DirectoryInode, "/") 35 fmt.Fprintln(writer, "</table>") 36 } 37 fmt.Fprintln(writer, "</body>") 38 } 39 40 func listComputedInodes(tw *html.TableWriter, 41 directoryInode *filesystem.DirectoryInode, name string) { 42 for _, dirent := range directoryInode.EntryList { 43 if inode, ok := dirent.Inode().(*filesystem.ComputedRegularInode); ok { 44 tw.WriteRow("", "", 45 path.Join(name, dirent.Name), 46 inode.Source, 47 ) 48 } else if inode, ok := dirent.Inode().(*filesystem.DirectoryInode); ok { 49 listComputedInodes(tw, inode, path.Join(name, dirent.Name)) 50 } 51 } 52 }