-
Notifications
You must be signed in to change notification settings - Fork 0
/
file-mover.go
41 lines (34 loc) · 882 Bytes
/
file-mover.go
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
// move the file to queued directory and hands over to encryption task
package main
import (
"fmt"
"io/ioutil"
"log"
"os"
"path"
)
// FileMover move files to directory encrypt
func FileMover(platform, rsyncPID, basePath string) error {
pathQueued := path.Join(basePath, "queued")
pathEncrypt := path.Join(basePath, "encrypt")
log.Printf("searching for files inside %s", pathQueued)
queuedFiles, err := ioutil.ReadDir(pathQueued)
if err != nil {
return err
}
for _, f := range queuedFiles {
srcFile := path.Join(pathQueued, f.Name())
dstFile := path.Join(pathEncrypt, f.Name())
log.Printf("moving %s to %s", srcFile, dstFile)
err := os.Rename(srcFile, dstFile)
if err != nil {
return err
}
keyFile := fmt.Sprintf("%s.aes", dstFile)
if err := WriteAESKey(keyFile); err != nil {
return err
}
// TODO(ma): encrypt dstFile
}
return nil
}