mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2024-12-15 17:29:00 +08:00
c880caa770
Refs https://github.com/1Panel-dev/1Panel/issues/1245 Refs https://github.com/1Panel-dev/1Panel/issues/263
39 lines
755 B
Go
39 lines
755 B
Go
package files
|
|
|
|
import (
|
|
"fmt"
|
|
"github.com/1Panel-dev/1Panel/backend/utils/cmd"
|
|
)
|
|
|
|
type TarArchiver struct {
|
|
Cmd string
|
|
CompressType CompressType
|
|
}
|
|
|
|
func NewTarArchiver(compressType CompressType) ShellArchiver {
|
|
return &TarArchiver{
|
|
Cmd: "tar",
|
|
CompressType: compressType,
|
|
}
|
|
}
|
|
|
|
func (t TarArchiver) Extract(FilePath string, dstDir string) error {
|
|
return cmd.ExecCmd(fmt.Sprintf("%s %s %s -C %s", t.Cmd, t.getOptionStr("extract"), FilePath, dstDir))
|
|
}
|
|
|
|
func (t TarArchiver) Compress(sourcePaths []string, dstFile string) error {
|
|
return nil
|
|
}
|
|
|
|
func (t TarArchiver) getOptionStr(Option string) string {
|
|
switch t.CompressType {
|
|
case Tar:
|
|
if Option == "compress" {
|
|
return "cvf"
|
|
} else {
|
|
return "xf"
|
|
}
|
|
}
|
|
return ""
|
|
}
|