Skip to content

Commit

Permalink
fix: test
Browse files Browse the repository at this point in the history
  • Loading branch information
devhaozi committed Oct 27, 2024
1 parent aca2d51 commit e3ad36e
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions pkg/io/compress.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package io

import (
"errors"
"github.com/go-rat/utils/debug"
"os/exec"
"path/filepath"
"strings"
Expand Down Expand Up @@ -50,15 +49,12 @@ func Compress(dir string, src []string, dst string) error {
switch format {
case Zip:
cmd = exec.Command("zip", append([]string{"-qr", "-o", dst}, src...)...)
debug.Dump(append([]string{"-qr", "-o", dst}, src...))
case Gz:
case Gz, TarGz:
cmd = exec.Command("tar", append([]string{"-czf", dst}, src...)...)
case Bz2:
cmd = exec.Command("tar", append([]string{"-cjf", dst}, src...)...)
case Tar:
cmd = exec.Command("tar", append([]string{"-cf", dst}, src...)...)
case TarGz:
cmd = exec.Command("tar", append([]string{"-czf", dst}, src...)...)
case Xz:
cmd = exec.Command("tar", append([]string{"-cJf", dst}, src...)...)
case SevenZip:
Expand All @@ -67,25 +63,26 @@ func Compress(dir string, src []string, dst string) error {
return errors.New("unsupported format")
}

out, err := cmd.CombinedOutput()
debug.Dump(string(out))

return err
return cmd.Run()
}

// UnCompress 解压文件
func UnCompress(src string, dst string) error {
if !filepath.IsAbs(src) || !filepath.IsAbs(dst) {
return errors.New("src and dst must be absolute path")
}

var cmd *exec.Cmd
if !Exists(dst) {
if err := Mkdir(dst, 0755); err != nil {
return err
}
}

format, err := formatArchiveByPath(src)
if err != nil {
return err
}

var cmd *exec.Cmd
switch format {
case Zip:
cmd = exec.Command("unzip", "-qo", src, "-d", dst)
Expand Down

0 comments on commit e3ad36e

Please sign in to comment.