Skip to content

Commit f4a74bc

Browse files
committed
Revert "Utilize internal/archiver package only."
This reverts commit 8d602ad.
1 parent 8d602ad commit f4a74bc

3 files changed

Lines changed: 22 additions & 37 deletions

File tree

internal/archiver/archiver.go

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,17 @@ type FileMap struct {
1515
Target string // Note: Target paths should always be relative to the archive root, do not use absolute paths
1616
}
1717

18-
func CreateArchive(archive archiver.Writer, archivePath string, workDir string, fileMaps []FileMap) error {
18+
func CreateTgz(archivePath string, workDir string, fileMaps []FileMap) error {
1919
f, err := os.OpenFile(archivePath, os.O_CREATE|os.O_WRONLY, 0644)
2020
if err != nil {
2121
return errs.Wrap(err, "Could not create temp file")
2222
}
2323
defer f.Close()
24-
if err := archive.Create(f); err != nil {
24+
tgz := archiver.NewTarGz()
25+
if err := tgz.Create(f); err != nil {
2526
return errs.Wrap(err, "Could not create tar.gz")
2627
}
27-
defer archive.Close()
28+
defer tgz.Close()
2829

2930
for _, fileMap := range fileMaps {
3031
source := fileMap.Source
@@ -44,7 +45,7 @@ func CreateArchive(archive archiver.Writer, archivePath string, workDir string,
4445
}
4546

4647
// write it to the archive
47-
err = archive.Write(archiver.File{
48+
err = tgz.Write(archiver.File{
4849
FileInfo: archiver.FileInfo{
4950
FileInfo: fileInfo,
5051
CustomName: fileMap.Target,
@@ -60,14 +61,6 @@ func CreateArchive(archive archiver.Writer, archivePath string, workDir string,
6061
return nil
6162
}
6263

63-
func CreateTgz(archivePath string, workDir string, fileMaps []FileMap) error {
64-
return CreateArchive(archiver.NewTarGz(), archivePath, workDir, fileMaps)
65-
}
66-
67-
func CreateZip(archivePath string, workDir string, fileMaps []FileMap) error {
68-
return CreateArchive(archiver.NewZip(), archivePath, workDir, fileMaps)
69-
}
70-
7164
func FilesWithCommonParent(filepaths ...string) []FileMap {
7265
var fileMaps []FileMap
7366
common := fileutils.CommonParentPath(filepaths)

scripts/ci/update-generator/main.go

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ import (
1111
"path/filepath"
1212
"runtime"
1313

14-
"github.com/ActiveState/cli/internal/archiver"
14+
"github.com/mholt/archiver/v3"
15+
1516
"github.com/ActiveState/cli/internal/condition"
1617
"github.com/ActiveState/cli/internal/constants"
1718
"github.com/ActiveState/cli/internal/environment"
@@ -57,28 +58,28 @@ func generateSha256(path string) string {
5758
return hex.EncodeToString(hasher.Sum(nil))
5859
}
5960

61+
func archiveMeta() (archiveMethod archiver.Archiver, ext string) {
62+
if runtime.GOOS == "windows" {
63+
return archiver.NewZip(), ".zip"
64+
}
65+
return archiver.NewTarGz(), ".tar.gz"
66+
}
67+
6068
func createUpdate(outputPath, channel, version, versionNumber, platform, target string) error {
6169
relChannelPath := filepath.Join(channel, platform)
6270
relVersionedPath := filepath.Join(channel, versionNumber, platform)
6371
_ = os.MkdirAll(filepath.Join(outputPath, relChannelPath), 0o755)
6472
_ = os.MkdirAll(filepath.Join(outputPath, relVersionedPath), 0o755)
6573

66-
archiveExt := ".tar.gz"
67-
if runtime.GOOS == "windows" {
68-
archiveExt = ".zip"
69-
}
74+
archive, archiveExt := archiveMeta()
7075
relArchivePath := filepath.Join(relVersionedPath, fmt.Sprintf("state-%s-%s%s", platform, version, archiveExt))
7176
archivePath := filepath.Join(outputPath, relArchivePath)
7277

7378
// Remove archive path if it already exists
7479
_ = os.Remove(archivePath)
7580
// Create main archive
7681
fmt.Printf("Creating %s\n", archivePath)
77-
archive := archiver.CreateTgz
78-
if runtime.GOOS == "windows" {
79-
archive = archiver.CreateZip
80-
}
81-
if err := archive(archivePath, "", []archiver.FileMap{{Source: target, Target: filepath.Base(target)}}); err != nil {
82+
if err := archive.Archive([]string{target}, archivePath); err != nil {
8283
return errs.Wrap(err, "Archiving failed")
8384
}
8485

@@ -109,22 +110,15 @@ func createInstaller(buildPath, outputPath, channel, platform string) error {
109110
return errs.New("state-installer does not exist in build dir")
110111
}
111112

112-
archiveExt := ".tar.gz"
113-
if runtime.GOOS == "windows" {
114-
archiveExt = ".zip"
115-
}
113+
archive, archiveExt := archiveMeta()
116114
relArchivePath := filepath.Join(channel, platform, "state-installer"+archiveExt)
117115
archivePath := filepath.Join(outputPath, relArchivePath)
118116

119117
// Remove archive path if it already exists
120118
_ = os.Remove(archivePath)
121119
// Create main archive
122120
fmt.Printf("Creating %s\n", archivePath)
123-
archive := archiver.CreateTgz
124-
if runtime.GOOS == "windows" {
125-
archive = archiver.CreateZip
126-
}
127-
err := archive(archivePath, "", []archiver.FileMap{{Source: installer, Target: filepath.Base(installer)}})
121+
err := archive.Archive([]string{installer}, archivePath)
128122
if err != nil {
129123
return errs.Wrap(err, "Archiving failed")
130124
}

test/integration/checkout_int_test.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ import (
99
"strings"
1010
"testing"
1111

12-
"github.com/ActiveState/cli/internal/archiver"
12+
"github.com/mholt/archiver/v3"
13+
1314
"github.com/ActiveState/cli/internal/constants"
1415
"github.com/ActiveState/cli/internal/environment"
1516
"github.com/ActiveState/cli/internal/fileutils"
@@ -375,11 +376,8 @@ func (suite *CheckoutIntegrationTestSuite) TestCheckoutFromArchive() {
375376
tgz := fileutils.TempFilePath("", runtime.GOOS+".tar.gz")
376377
files, err := fileutils.ListDirSimple(dir, false)
377378
suite.Require().NoError(err)
378-
fileMaps := make([]archiver.FileMap, len(files))
379-
for i, file := range files {
380-
fileMaps[i] = archiver.FileMap{Source: file, Target: filepath.Base(file)} // strip all leading dirs
381-
}
382-
suite.Require().NoError(archiver.CreateTgz(tgz, "", fileMaps))
379+
gz := archiver.TarGz{Tar: &archiver.Tar{StripComponents: 1000}} // use a big number to strip all leading dirs
380+
suite.Require().NoError(gz.Archive(files, tgz))
383381
defer os.Remove(tgz)
384382

385383
cp := ts.SpawnWithOpts(

0 commit comments

Comments
 (0)