mirror of
				https://github.com/1Panel-dev/1Panel.git
				synced 2025-10-31 03:07:34 +08:00 
			
		
		
		
	
		
			
				
	
	
		
			37 lines
		
	
	
	
		
			780 B
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			37 lines
		
	
	
	
		
			780 B
		
	
	
	
		
			Go
		
	
	
	
	
	
| package files
 | |
| 
 | |
| import (
 | |
| 	"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(FilePath string, dstDir string, secret string) error {
 | |
| 	return cmd.RunDefaultBashCf("%s %s \"%s\" -C \"%s\"", t.Cmd, t.getOptionStr("extract"), FilePath, dstDir)
 | |
| }
 | |
| 
 | |
| func (t TarArchiver) Compress(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 ""
 | |
| }
 |