// Copyright (c) 2018 Versity Software, Inc. // // Use of this source code is governed by a BSD-3-Clause license // that can be found in the LICENSE file in the root of the source // tree. package main import ( "fmt" "log" "net/http" "os" "time" scoutfs "github.com/versity/scoutfs-go" ) const ( max32 = 0xffffffff max64 = 0xffffffffffffffff ) type server struct { update <-chan int lastcount int } func queryPopulation(basedir string, update chan<- int) error { h, err := scoutfs.NewQuery(basedir, scoutfs.ByMSeq(scoutfs.InodesEntry{}, scoutfs.InodesEntry{Major: max64, Minor: max32, Ino: max64})) if err != nil { return fmt.Errorf("scoutfs new handle: %v", err) } defer h.Close() count := 0 for { for { qents, err := h.Next() if err != nil { return fmt.Errorf("scoutfs next: %v", err) } if len(qents) == 0 { break } for _, qent := range qents { fmt.Printf("%#v\n", qent) count++ } } update <- count time.Sleep(500 * time.Millisecond) } } func (s *server) ServeHTTP(w http.ResponseWriter, r *http.Request) { select { case x, ok := <-s.update: if ok { s.lastcount = x } else { fmt.Println("Channel closed!") os.Exit(1) } default: } fmt.Fprintf(w, "%s %d", `