mirror of
https://github.com/versity/scoutfs-go.git
synced 2026-01-06 03:44:52 +00:00
query by metaseq and dataseq interface
This commit is contained in:
82
examples/count-changes/main.go
Normal file
82
examples/count-changes/main.go
Normal file
@@ -0,0 +1,82 @@
|
||||
// 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", `
|
||||
<HEAD><meta HTTP-EQUIV="REFRESH" content="1"></HEAD>
|
||||
<h1>SCOUTFS</h1></p>
|
||||
Files/Directories updated:`, s.lastcount)
|
||||
}
|
||||
|
||||
func main() {
|
||||
update := make(chan int, 1)
|
||||
s := &server{update: update}
|
||||
go queryPopulation(os.Args[1], update)
|
||||
log.Fatal(http.ListenAndServe(":8080", s))
|
||||
}
|
||||
Reference in New Issue
Block a user