@@ -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+
6068func 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 }
0 commit comments