-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathprepare_manager.go
More file actions
executable file
·73 lines (65 loc) · 1.77 KB
/
prepare_manager.go
File metadata and controls
executable file
·73 lines (65 loc) · 1.77 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package main
import (
"log"
"os"
"path"
"path/filepath"
)
// TransferManager reacts on the channel done_files.
// If folder of file is ready to send it sends it via WebDAV (HTTP) to <CMD arg -dst>.
// It also initializes the zipping if <CMD arg -zip> is set.
type PrepareManager struct {
args *Args
done_files chan string
}
// doWork runs in a endless loop. It reacts on the channel done_files.
// If folder of file is ready to send it sends it via HWebDAV (HTTP) to <CMD arg -dst>.
// It also initializes the zipping if <CMD arg -zip> is set
// It terminates as soon as a value is pushed into quit. Run in extra goroutine.
func (m *PrepareManager) doWork(quit chan int) {
InfoLogger.Println("Started transfer process.")
for {
select {
case <-quit:
InfoLogger.Println("Quit transfer process.")
return
case to_send := <-m.done_files:
_, err := os.Stat(to_send)
if err != nil {
ErrorLogger.Println(err)
break
}
tempPath, err := CopyPreTempDirectory(to_send)
if m.args.sendType == "flat_tar" {
err := os.Remove(to_send)
if err != nil {
ErrorLogger.Println(err)
}
}
if err != nil {
ErrorLogger.Println(err)
}
RunPreScripts(tempPath)
if args.preconvert {
RunConverterScripts(tempPath)
filePath := tempPath + ".zip"
fileName := filepath.Base(filePath)
err := AddLinkToZip(filepath.Base(filePath), filePath)
if err != nil {
ErrorLogger.Println(err)
}
err = os.Rename(filePath, path.Join(TempConvertedPath, fileName))
if err != nil {
ErrorLogger.Println(err)
}
}
err = CopyTempDirectory()
if err != nil {
log.Fatal(err)
}
}
}
}
func newPrepareManager(args *Args, done_files chan string) PrepareManager {
return PrepareManager{args: args, done_files: done_files}
}