Skip to content

Commit

Permalink
fix: Correctly strip root folder from downloaded archives
Browse files Browse the repository at this point in the history
  • Loading branch information
danez committed Nov 20, 2020
1 parent eea9cfc commit f3fc441
Show file tree
Hide file tree
Showing 11 changed files with 55 additions and 28 deletions.
18 changes: 17 additions & 1 deletion nsd/cmd/download.go
Expand Up @@ -70,7 +70,23 @@ var (
return
}

err = archiver.Unarchive(nodeFilePath, downloadPath)
switch NodeJs.CurrentExtension {
case NodeJs.Zip:
zip := archiver.NewZip()
zip.StripComponents = 1
err = zip.Unarchive(nodeFilePath, downloadPath)
case NodeJs.TarXz:
tar := archiver.NewTarXz()
tar.StripComponents = 1
err = tar.Unarchive(nodeFilePath, downloadPath)
case NodeJs.TarGz:
tar := archiver.NewTarGz()
tar.StripComponents = 1
err = tar.Unarchive(nodeFilePath, downloadPath)
default:
return errors.New("Invalid archive format. Aborting")
}

if err != nil {
return
}
Expand Down
6 changes: 3 additions & 3 deletions nsd/nodejs/arch_aix_ppc64.go
Expand Up @@ -2,7 +2,7 @@ package nodejs

// CurrentArch and CurrentURL describe how the URL of the nodejs download will look like
const (
CurrentArch string = "aix-ppc64"
CurrentURL DownloadURL = Stable
CurrentExtension string = "tar.gz"
CurrentArch string = "aix-ppc64"
CurrentURL DownloadURL = Stable
CurrentExtension FileExtension = TarGz
)
6 changes: 3 additions & 3 deletions nsd/nodejs/arch_darwin_amd64.go
Expand Up @@ -2,7 +2,7 @@ package nodejs

// CurrentArch and CurrentURL describe how the URL of the nodejs download will look like
const (
CurrentArch string = "darwin-x64"
CurrentURL DownloadURL = Stable
CurrentExtension string = "tar.gz"
CurrentArch string = "darwin-x64"
CurrentURL DownloadURL = Stable
CurrentExtension FileExtension = TarXz
)
6 changes: 3 additions & 3 deletions nsd/nodejs/arch_linux_amd64.go
Expand Up @@ -2,7 +2,7 @@ package nodejs

// CurrentArch and CurrentURL describe how the URL of the nodejs download will look like
const (
CurrentArch string = "linux-x64"
CurrentURL DownloadURL = Stable
CurrentExtension string = "tar.gz"
CurrentArch string = "linux-x64"
CurrentURL DownloadURL = Stable
CurrentExtension FileExtension = TarXz
)
6 changes: 3 additions & 3 deletions nsd/nodejs/arch_linux_arm64.go
Expand Up @@ -2,7 +2,7 @@ package nodejs

// CurrentArch and CurrentURL describe how the URL of the nodejs download will look like
const (
CurrentArch string = "linux-arm64"
CurrentURL DownloadURL = Stable
CurrentExtension string = "tar.gz"
CurrentArch string = "linux-arm64"
CurrentURL DownloadURL = Stable
CurrentExtension FileExtension = TarXz
)
6 changes: 3 additions & 3 deletions nsd/nodejs/arch_linux_ppc64le.go
Expand Up @@ -2,7 +2,7 @@ package nodejs

// CurrentArch and CurrentURL describe how the URL of the nodejs download will look like
const (
CurrentArch string = "linux-ppc64le"
CurrentURL DownloadURL = Stable
CurrentExtension string = "tar.gz"
CurrentArch string = "linux-ppc64le"
CurrentURL DownloadURL = Stable
CurrentExtension FileExtension = TarXz
)
6 changes: 3 additions & 3 deletions nsd/nodejs/arch_linux_s390x.go
Expand Up @@ -2,7 +2,7 @@ package nodejs

// CurrentArch and CurrentURL describe how the URL of the nodejs download will look like
const (
CurrentArch string = "linux-s390x"
CurrentURL DownloadURL = Stable
CurrentExtension string = "tar.gz"
CurrentArch string = "linux-s390x"
CurrentURL DownloadURL = Stable
CurrentExtension FileExtension = TarXz
)
6 changes: 3 additions & 3 deletions nsd/nodejs/arch_solaris_amd64.go
Expand Up @@ -2,7 +2,7 @@ package nodejs

// CurrentArch and CurrentURL describe how the URL of the nodejs download will look like
const (
CurrentArch string = "sunos-x64"
CurrentURL DownloadURL = Stable
CurrentExtension string = "tar.gz"
CurrentArch string = "sunos-x64"
CurrentURL DownloadURL = Stable
CurrentExtension FileExtension = TarXz
)
6 changes: 3 additions & 3 deletions nsd/nodejs/arch_windows_386.go
Expand Up @@ -2,7 +2,7 @@ package nodejs

// CurrentArch and CurrentURL describe how the URL of the nodejs download will look like
const (
CurrentArch string = "win-x86"
CurrentURL DownloadURL = Stable
CurrentExtension string = "zip"
CurrentArch string = "win-x86"
CurrentURL DownloadURL = Stable
CurrentExtension FileExtension = Zip
)
6 changes: 3 additions & 3 deletions nsd/nodejs/arch_windows_amd64.go
Expand Up @@ -2,7 +2,7 @@ package nodejs

// CurrentArch and CurrentURL describe how the URL of the nodejs download will look like
const (
CurrentArch string = "win-x64"
CurrentURL DownloadURL = Stable
CurrentExtension string = "zip"
CurrentArch string = "win-x64"
CurrentURL DownloadURL = Stable
CurrentExtension FileExtension = Zip
)
11 changes: 11 additions & 0 deletions nsd/nodejs/extension.go
@@ -0,0 +1,11 @@
package nodejs

// FileExtension defines all possible file extensions for nodejs downloads
type FileExtension string

// Stable and Unofficial are the two values for DownloadURL
const (
TarGz FileExtension = "tar.gz"
TarXz FileExtension = "tar.xz"
Zip FileExtension = "zip"
)

0 comments on commit f3fc441

Please sign in to comment.