summaryrefslogtreecommitdiff
path: root/gocryptfs-xray/paths_ctlsock.go
blob: 3c69ec3a6168af8af26927ff2f86ff76eb4af6d2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package main

import (
	"bufio"
	"fmt"
	"os"

	"github.com/rfjakob/gocryptfs/ctlsock"
)

func decryptPaths(socketPath string) {
	var req ctlsock.RequestStruct
	transformPaths(socketPath, &req, &req.DecryptPath)
}

func encryptPaths(socketPath string) {
	var req ctlsock.RequestStruct
	transformPaths(socketPath, &req, &req.EncryptPath)
}

func transformPaths(socketPath string, req *ctlsock.RequestStruct, in *string) {
	c, err := ctlsock.New(socketPath)
	if err != nil {
		fmt.Printf("fatal: %v\n", err)
		os.Exit(1)
	}
	line := 0
	scanner := bufio.NewScanner(os.Stdin)
	for scanner.Scan() {
		line++
		*in = scanner.Text()
		resp, err := c.Query(req)
		if err != nil {
			fmt.Fprintf(os.Stderr, "error at input line %d %q: %v\n", line, *in, err)
			continue
		}
		if resp.WarnText != "" {
			fmt.Fprintf(os.Stderr, "warning at input line %d %q: %v\n", line, *in, resp.WarnText)
		}
		fmt.Println(resp.Result)
	}
	os.Exit(0)
}