-
Notifications
You must be signed in to change notification settings - Fork 481
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: download failure when remote file is missing and add support for…
… tar.gz archives (#1195) * fix: download failure when remote file is missing If the .tar.xz download fails, it will try again with the .tar.gz file. Fixes #1088 * Update changeset * Update changeset * fix clippy warnings and add test * add snapshot * fix types * skip on windows * don't have obsolete snapshots --------- Co-authored-by: Gal Schlezinger <[email protected]>
- Loading branch information
1 parent
d0ed740
commit 74d7c33
Showing
12 changed files
with
209 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"fnm": patch | ||
--- | ||
|
||
When downloading from node-dist, Fallback to .tar.gz download when the .tar.xz download fails |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Bash download old Node.js 0.10.x: Bash 1`] = ` | ||
"set -e | ||
eval "$(fnm env)" | ||
fnm install v0.10.36 | ||
fnm use v0.10.36 | ||
if [ "$(node --version)" != "v0.10.36" ]; then | ||
echo "Expected node version to be v0.10.36. Got $(node --version)" | ||
exit 1 | ||
fi" | ||
`; | ||
|
||
exports[`Fish download old Node.js 0.10.x: Fish 1`] = ` | ||
"fnm env | source | ||
fnm install v0.10.36 | ||
fnm use v0.10.36 | ||
set ____test____ (node --version) | ||
if test "$____test____" != "v0.10.36" | ||
echo "Expected node version to be v0.10.36. Got $____test____" | ||
exit 1 | ||
end" | ||
`; | ||
|
||
exports[`PowerShell download old Node.js 0.10.x: PowerShell 1`] = ` | ||
"$ErrorActionPreference = "Stop" | ||
fnm env | Out-String | Invoke-Expression | ||
fnm install v0.10.36 | ||
fnm use v0.10.36 | ||
if ( "$(node --version)" -ne "v0.10.36" ) { echo "Expected node version to be v0.10.36. Got $(node --version)"; exit 1 }" | ||
`; | ||
|
||
exports[`Zsh download old Node.js 0.10.x: Zsh 1`] = ` | ||
"set -e | ||
eval "$(fnm env)" | ||
fnm install v0.10.36 | ||
fnm use v0.10.36 | ||
if [ "$(node --version)" != "v0.10.36" ]; then | ||
echo "Expected node version to be v0.10.36. Got $(node --version)" | ||
exit 1 | ||
fi" | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { script } from "./shellcode/script.js" | ||
import { Bash, Fish, PowerShell, WinCmd, Zsh } from "./shellcode/shells.js" | ||
import testNodeVersion from "./shellcode/test-node-version.js" | ||
import describe from "./describe.js" | ||
import os from "node:os" | ||
|
||
for (const shell of [Bash, Zsh, Fish, PowerShell, WinCmd]) { | ||
describe(shell, () => { | ||
test(`download old Node.js 0.10.x`, async () => { | ||
const testCase = script(shell) | ||
.then(shell.env({})) | ||
.then(shell.call("fnm", ["install", "v0.10.36"])) | ||
.then(shell.call("fnm", ["use", "v0.10.36"])) | ||
.then(testNodeVersion(shell, "v0.10.36")) | ||
.takeSnapshot(shell) | ||
|
||
if (os.platform() === "win32") { | ||
console.warn(`test skipped as 0.10.x isn't prebuilt for windows`) | ||
} else { | ||
await testCase.execute(shell) | ||
} | ||
}) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,58 @@ | ||
pub mod extract; | ||
pub mod tar_xz; | ||
pub mod tar; | ||
pub mod zip; | ||
|
||
pub use self::extract::{Error, Extract}; | ||
use std::io::Read; | ||
use std::path::Path; | ||
|
||
pub use self::extract::{Error, Extract}; | ||
#[cfg(unix)] | ||
pub use self::tar_xz::TarXz; | ||
use self::tar::Tar; | ||
|
||
#[cfg(windows)] | ||
pub use self::zip::Zip; | ||
use self::zip::Zip; | ||
|
||
pub enum Archive { | ||
#[cfg(windows)] | ||
Zip, | ||
#[cfg(unix)] | ||
TarXz, | ||
#[cfg(unix)] | ||
TarGz, | ||
} | ||
|
||
impl Archive { | ||
pub fn extract_archive_into(&self, path: &Path, response: impl Read) -> Result<(), Error> { | ||
let extractor: Box<dyn Extract> = match self { | ||
#[cfg(windows)] | ||
Self::Zip => Box::new(Zip::new(response)), | ||
#[cfg(unix)] | ||
Self::TarXz => Box::new(Tar::Xz(response)), | ||
#[cfg(unix)] | ||
Self::TarGz => Box::new(Tar::Gz(response)), | ||
}; | ||
extractor.extract_into(path)?; | ||
Ok(()) | ||
} | ||
|
||
pub fn file_extension(&self) -> &'static str { | ||
match self { | ||
#[cfg(windows)] | ||
Self::Zip => "zip", | ||
#[cfg(unix)] | ||
Self::TarXz => "tar.xz", | ||
#[cfg(unix)] | ||
Self::TarGz => "tar.gz", | ||
} | ||
} | ||
|
||
#[cfg(windows)] | ||
pub fn supported() -> &'static [Self] { | ||
&[Self::Zip] | ||
} | ||
|
||
#[cfg(unix)] | ||
pub fn supported() -> &'static [Self] { | ||
&[Self::TarXz, Self::TarGz] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
use super::{extract::Error, Extract}; | ||
use std::{io::Read, path::Path}; | ||
|
||
pub enum Tar<R: Read> { | ||
/// Tar archive with XZ compression | ||
Xz(R), | ||
Check warning on line 6 in src/archive/tar.rs GitHub Actions / Release build for Windows
|
||
/// Tar archive with Gzip compression | ||
Gz(R), | ||
} | ||
|
||
impl<R: Read> Tar<R> { | ||
fn extract_into_impl<P: AsRef<Path>>(self, path: P) -> Result<(), Error> { | ||
let stream: Box<dyn Read> = match self { | ||
Self::Xz(response) => Box::new(xz2::read::XzDecoder::new(response)), | ||
Self::Gz(response) => Box::new(flate2::read::GzDecoder::new(response)), | ||
}; | ||
let mut tar_archive = tar::Archive::new(stream); | ||
tar_archive.unpack(&path)?; | ||
Ok(()) | ||
} | ||
} | ||
|
||
impl<R: Read> Extract for Tar<R> { | ||
fn extract_into(self: Box<Self>, path: &Path) -> Result<(), Error> { | ||
self.extract_into_impl(path) | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.