Files
1Panel/agent/utils/files/tar.go

40 lines
837 B
Go

package files
import (
"context"
"github.com/1Panel-dev/1Panel/agent/utils/cmd"
)
type TarArchiver struct {
Cmd string
CompressType CompressType
}
func NewTarArchiver(compressType CompressType) ShellArchiver {
return &TarArchiver{
Cmd: "tar",
CompressType: compressType,
}
}
func (t TarArchiver) Extract(ctx context.Context, FilePath string, dstDir string, secret string) error {
return cmd.NewCommandMgr(cmd.WithContext(ctx)).Run(t.Cmd, t.getOptionStr("extract"), FilePath, "-C", dstDir)
}
func (t TarArchiver) Compress(ctx context.Context, sourcePaths []string, dstFile string, secret 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 ""
}