summaryrefslogtreecommitdiff
path: root/src/file-hasher/main.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/file-hasher/main.go')
-rw-r--r--src/file-hasher/main.go47
1 files changed, 29 insertions, 18 deletions
diff --git a/src/file-hasher/main.go b/src/file-hasher/main.go
index 3e32b63..f360705 100644
--- a/src/file-hasher/main.go
+++ b/src/file-hasher/main.go
@@ -30,45 +30,56 @@ import (
"time"
)
-const (
- RD_CONF = "/etc/rd.conf"
-)
+type Request struct {
+ NumThreads uint `json:"threads"`
+ Directories []string `json:"dir"`
+ M3UPlaylists []string `json:"m3u"`
+}
func main() {
- if len(os.Args) < 2 {
- log.Fatal("Usage: file-hasher <directory> [ <directory [ .. ] ]")
- }
- directories := os.Args[1:]
-
stdlog := log.New(os.Stderr, "[std] ", log.LstdFlags)
+ var req Request
+ if err := json.NewDecoder(os.Stdin).Decode(&req); err != nil {
+ stdlog.Fatalf("Error decoding request: %v", err)
+ }
+
C := make(chan os.Signal, 1)
signal.Notify(C, os.Interrupt, syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGTERM)
- stdlog.Println("***************************************************************")
- stdlog.Printf("*** will hash files' from %d directories", len(directories))
- stdlog.Println("***************************************************************")
-
starttime := time.Now()
go func() {
defer func() {
C <- syscall.SIGTERM
}()
+ stdlog.Println("***************************************************************")
+ h := NewHasher(req.NumThreads, stdlog)
+ stdlog.Println("")
+ stdlog.Println("******************************")
- stdlog.Println("********************************************")
- h := NewHasher(4, stdlog) // TODO: make number of threads configurable
- for _, root := range directories {
+ for _, root := range req.Directories {
src := NewDir(root, stdlog)
stdlog.Printf("*** hashing all the files in '%s'", root)
stdlog.Println("")
if err := h.ComputeHashes(src); err != nil {
stdlog.Println("")
- stdlog.Printf("ERROR: %v", err)
- return
+ stdlog.Fatalf("ERROR: %v", err)
}
stdlog.Println("")
stdlog.Println("******************************")
}
+ for _, list := range req.M3UPlaylists {
+ src := NewM3u(list, stdlog)
+ stdlog.Printf("*** hashing all the files from '%s'", list)
+ stdlog.Println("")
+ if err := h.ComputeHashes(src); err != nil {
+ stdlog.Println("")
+ stdlog.Fatalf("ERROR: %v", err)
+ }
+ stdlog.Println("")
+ stdlog.Println("******************************")
+ }
+
stdlog.Println("")
stdlog.Println("***************************************************************")
stdlog.Printf("*** hashed %d files in %v", len(h.Files), time.Since(starttime))
@@ -76,7 +87,7 @@ func main() {
enc := json.NewEncoder(os.Stdout)
if err := enc.Encode(h.Files); err != nil {
- stdlog.Printf("Error encoding JSON: %v", err)
+ stdlog.Fatalf("Error encoding Result: %v", err)
}
}()