summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Pointner <equinox@helsinki.at>2017-01-25 23:49:54 (GMT)
committerChristian Pointner <equinox@helsinki.at>2017-01-25 23:49:54 (GMT)
commit5624f3ac623ed2caa8c3c3933e66d63aafc09914 (patch)
tree7ee90a92df50e50a4d994001bb9d8751f1f88fa9
parent9d1b81e5997ee9ec8cc5bfd16f6c62a40044006a (diff)
file-hasher as seperate binary
-rw-r--r--Makefile14
-rw-r--r--src/file-hasher/dir-hasher.go (renamed from src/pool-import/dir-hasher.go)0
-rw-r--r--src/file-hasher/main.go81
-rw-r--r--src/pool-import/main.go20
4 files changed, 95 insertions, 20 deletions
diff --git a/Makefile b/Makefile
index 48e88d4..a6ea748 100644
--- a/Makefile
+++ b/Makefile
@@ -20,9 +20,14 @@
##
curdir:= $(shell pwd)
+ifndef GOROOT
GOCMD := GOPATH=$(curdir) go
+else
+GOCMD := GOPATH=$(curdir) $(GOROOT)/bin/go
+endif
EXECUTEABLE := pool-import
+EXECUTEABLE_HASHER := file-hasher
LIBS := "code.helsinki.at/rhrd-go/rhimport" \
"code.helsinki.at/rhrd-go/rddb" \
@@ -43,19 +48,26 @@ updatelibs:
vet:
@echo "vetting: $(EXECUTEABLE)"
@$(GOCMD) vet $(EXECUTEABLE)
+ @echo "vetting: $(EXECUTEABLE_HASHER)"
+ @$(GOCMD) vet $(EXECUTEABLE_HASHER)
format:
@echo "formating: $(EXECUTEABLE)"
@$(GOCMD) fmt $(EXECUTEABLE)
+ @echo "formating: $(EXECUTEABLE_HASHER)"
+ @$(GOCMD) format $(EXECUTEABLE_HASHER)
build: getlibs
@echo "installing: $(EXECUTEABLE)"
@$(GOCMD) install $(EXECUTEABLE)
+ @echo "installing: $(EXECUTEABLE_HASHER)"
+ @$(GOCMD) install $(EXECUTEABLE_HASHER)
clean:
rm -rf pkg/*/$(EXECUTEABLE)
+ rm -rf pkg/*/$(EXECUTEABLE_HASHER)
rm -rf bin
distclean: clean
- @$(foreach dir,$(shell ls src/),$(if $(subst $(EXECUTEABLE),,$(dir)),$(shell rm -rf src/$(dir))))
+ @$(foreach dir,$(shell ls src/),$(if $(and $(subst $(EXECUTEABLE),,$(dir)), $(subst $(EXECUTEABLE_HASHER),,$(dir))),$(shell rm -rf src/$(dir))))
rm -rf pkg
diff --git a/src/pool-import/dir-hasher.go b/src/file-hasher/dir-hasher.go
index aa204a0..aa204a0 100644
--- a/src/pool-import/dir-hasher.go
+++ b/src/file-hasher/dir-hasher.go
diff --git a/src/file-hasher/main.go b/src/file-hasher/main.go
new file mode 100644
index 0000000..c25f690
--- /dev/null
+++ b/src/file-hasher/main.go
@@ -0,0 +1,81 @@
+//
+// pool-import
+//
+// Copyright (C) 2016 Christian Pointner <equinox@helsinki.at>
+//
+// This file is part of pool-import.
+//
+// pool-import is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// any later version.
+//
+// pool-import is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with pool-import. If not, see <http://www.gnu.org/licenses/>.
+//
+
+package main
+
+import (
+ "log"
+ "os"
+ "os/signal"
+ "syscall"
+ "time"
+)
+
+const (
+ RD_CONF = "/etc/rd.conf"
+)
+
+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)
+
+ 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("********************************************")
+ allFiles := make(FileMap)
+ for _, root := range directories {
+ stdlog.Printf("*** hashing all the files in '%s'", root)
+ stdlog.Println("")
+ md := NewMusicDir(root, stdlog)
+ if err := md.ComputeHashes(); err != nil {
+ return
+ }
+ allFiles.Merge(md.Files)
+ stdlog.Println("")
+ stdlog.Println("******************************")
+ }
+ stdlog.Println("")
+ for hash, file := range allFiles {
+ stdlog.Printf("%s: %s", hash, file)
+ }
+ stdlog.Println("")
+ stdlog.Println("***************************************************************")
+ stdlog.Printf("*** hashed %d files in %v", len(allFiles), time.Since(starttime))
+ stdlog.Println("***************************************************************")
+ }()
+
+ <-C
+}
diff --git a/src/pool-import/main.go b/src/pool-import/main.go
index 10a59ec..0963ed0 100644
--- a/src/pool-import/main.go
+++ b/src/pool-import/main.go
@@ -96,25 +96,7 @@ func main() {
C <- syscall.SIGTERM
}()
- stdlog.Println("********************************************")
- allFiles := make(FileMap)
- for _, root := range directories {
- stdlog.Printf("*** hashing all the files in '%s'", root)
- stdlog.Println("")
- md := NewMusicDir(root, stdlog)
- if err := md.ComputeHashes(); err != nil {
- return
- }
- allFiles.Merge(md.Files)
- stdlog.Println("")
- stdlog.Println("******************************")
- }
- stdlog.Println("")
- for hash, file := range allFiles {
- stdlog.Printf("%s: %s", hash, file)
- }
- stdlog.Println("")
- stdlog.Println("********************************************")
+ // TODO: use file-hasher to get file hashes
}()
<-C