-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathuncompress.go
More file actions
75 lines (70 loc) · 1.72 KB
/
Copy pathuncompress.go
File metadata and controls
75 lines (70 loc) · 1.72 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
74
75
package main
import (
"os"
"path/filepath"
"github.com/mholt/archiver"
log "github.com/sirupsen/logrus"
)
func uncompressFile(file string) {
defer SWG.Done()
switch getFileExt(file) {
case "zip":
err := archiver.Zip.Open(file, Config.Path.Raw+"/"+FolderName)
if err != nil {
log.Error("Uncompress ZIP error: ", err.Error())
return
}
case "tar.gz":
err := archiver.TarGz.Open(file, Config.Path.Raw+"/"+FolderName)
if err != nil {
log.Error("Uncompress TARGZ error: ", err.Error())
return
}
case "tgz":
err := archiver.TarGz.Open(file, Config.Path.Raw+"/"+FolderName)
if err != nil {
log.Error("Uncompress TGZ error: ", err.Error())
return
}
case "tar":
err := archiver.Tar.Open(file, Config.Path.Raw+"/"+FolderName)
if err != nil {
log.Error("Uncompress TAR error: ", err.Error())
return
}
case "tar.bz2":
err := archiver.TarBz2.Open(file, Config.Path.Raw+"/"+FolderName)
if err != nil {
log.Error("Uncompress TARBZ2 error: ", err.Error())
return
}
case "tar.xz":
err := archiver.TarXZ.Open(file, Config.Path.Raw+"/"+FolderName)
if err != nil {
log.Error("Uncompress TARXZ error: ", err.Error())
return
}
case "rar":
err := archiver.Rar.Open(file, Config.Path.Raw+"/"+FolderName)
if err != nil {
log.Error("Uncompress RAR error: ", err.Error())
return
}
case "7z":
err := uncompress7Z(file)
if err != nil {
log.Error("Uncompress 7Z error: ", err.Error())
return
}
case "gz":
err := uncompressGZ(file)
if err != nil {
log.Error("Uncompress GZ error: ", err.Error())
return
}
}
err := os.Rename(file, Config.Path.Backup+"/"+FolderName+"/"+filepath.Base(file))
if err != nil {
log.Error("Error in backup operation: ", err.Error())
}
}