summaryrefslogtreecommitdiff
path: root/src/pool-import/file-hasher.go
diff options
context:
space:
mode:
authorChristian Pointner <equinox@helsinki.at>2017-01-28 00:29:29 (GMT)
committerChristian Pointner <equinox@helsinki.at>2017-01-28 00:29:29 (GMT)
commit025ccb8054087c664acc6f78d9cf51f563326a80 (patch)
tree8aacb50d0c1f28adc1953e7c1645545d8ad3d451 /src/pool-import/file-hasher.go
parent7d4d6741cb6cc11c88754b52e6f711e9ba1af4af (diff)
loading of file hasher config and writing log files works now
Diffstat (limited to 'src/pool-import/file-hasher.go')
-rw-r--r--src/pool-import/file-hasher.go30
1 files changed, 25 insertions, 5 deletions
diff --git a/src/pool-import/file-hasher.go b/src/pool-import/file-hasher.go
index 43dc6d9..df58a8e 100644
--- a/src/pool-import/file-hasher.go
+++ b/src/pool-import/file-hasher.go
@@ -26,22 +26,42 @@ import (
"encoding/json"
"os"
"os/exec"
+ "path/filepath"
+ "time"
)
type FileMap map[string]string
-// TODO: actually call this via ssh
-func callFileHasher() (files FileMap, err error) {
+func openGroupConfig(group string) (*os.File, error) {
+ cwd, err := filepath.Abs(".")
+ if err != nil {
+ return nil, err
+ }
+ fileName := filepath.Join(cwd, filepath.Clean("/"+group+"/config.json"))
+ return os.Open(fileName)
+}
+
+func createLogFile(group string) (log *os.File, err error) {
+ cwd, err := filepath.Abs(".")
+ if err != nil {
+ return nil, err
+ }
+ fileName := filepath.Join(cwd, filepath.Clean("/"+group), "logs", time.Now().Format(time.RFC3339)+".json")
+ return os.OpenFile(fileName, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0640)
+}
+
+func callFileHasher(group string) (files FileMap, err error) {
var stdin, log *os.File
- if stdin, err = os.Open("sample/file-hasher-requst.json"); err != nil {
+ if stdin, err = openGroupConfig(group); err != nil {
return
}
- if log, err = os.OpenFile("file-hasher.log", os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0640); err != nil {
+ if log, err = createLogFile(group); err != nil {
return
}
+ var stdout bytes.Buffer
+ // TODO: actually call this via ssh
cmd := exec.Command("bin/file-hasher")
- var stdout bytes.Buffer
cmd.Stdin = stdin
cmd.Stdout = &stdout
cmd.Stderr = log