mirror of
https://github.com/velopack/velopack.git
synced 2025-10-25 15:19:22 +00:00
Fix tests and add size validation to rust
This commit is contained in:
@@ -236,19 +236,13 @@ namespace Velopack
|
||||
var completeFile = Locator.GetLocalPackagePath(targetRelease);
|
||||
var incompleteFile = completeFile + ".partial";
|
||||
|
||||
try {
|
||||
// if the package already exists on disk, we can skip the download.
|
||||
if (File.Exists(completeFile)) {
|
||||
Log.Info($"Package already exists on disk: '{completeFile}', verifying checksum...");
|
||||
try {
|
||||
VerifyPackageChecksum(targetRelease, completeFile);
|
||||
Log.Info("Package checksum verified, skipping download.");
|
||||
return;
|
||||
} catch (ChecksumFailedException ex) {
|
||||
Log.Warn(ex, $"Checksum failed for file '{completeFile}'. Deleting and starting over.");
|
||||
}
|
||||
}
|
||||
// if the package already exists on disk, we can skip the download.
|
||||
if (File.Exists(completeFile)) {
|
||||
Log.Info($"Package already exists on disk: '{completeFile}', nothing to do.");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
var deltasSize = updates.DeltasToTarget.Sum(x => x.Size);
|
||||
var deltasCount = updates.DeltasToTarget.Count();
|
||||
|
||||
|
||||
@@ -127,8 +127,10 @@ pub enum Error
|
||||
FileNotFound(String),
|
||||
#[error("IO error: {0}")]
|
||||
Io(#[from] std::io::Error),
|
||||
#[error("Checusum did not match for {0} (expected {1}, actual {2})")]
|
||||
Checksum(String, String, String),
|
||||
#[error("Checksum did not match for {0} (expected {1}, actual {2})")]
|
||||
ChecksumInvalid(String, String, String),
|
||||
#[error("Size did not match for {0} (expected {1}, actual {2})")]
|
||||
SizeInvalid(String, u64, u64),
|
||||
#[error("Zip error: {0}")]
|
||||
Zip(#[from] zip::result::ZipError),
|
||||
#[error("Network error: {0}")]
|
||||
|
||||
@@ -519,10 +519,16 @@ impl UpdateManager {
|
||||
}
|
||||
|
||||
fn verify_package_checksum(&self, file: &PathBuf, asset: &VelopackAsset) -> Result<(), Error> {
|
||||
let file_size = file.metadata()?.len();
|
||||
if file_size != asset.Size {
|
||||
error!("File size mismatch for file '{}': expected {}, got {}", file.to_string_lossy(), asset.Size, file_size);
|
||||
return Err(Error::SizeInvalid(file.to_string_lossy().to_string(), asset.Size, file_size));
|
||||
}
|
||||
|
||||
let sha1 = util::calculate_file_sha1(file)?;
|
||||
if !sha1.eq_ignore_ascii_case(&asset.SHA1) {
|
||||
error!("SHA1 checksum mismatch for file '{}': expected '{}', got '{}'", file.to_string_lossy(), asset.SHA1, sha1);
|
||||
return Err(Error::Checksum(file.to_string_lossy().to_string(), asset.SHA1.clone(), sha1));
|
||||
return Err(Error::ChecksumInvalid(file.to_string_lossy().to_string(), asset.SHA1.clone(), sha1));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -144,6 +144,31 @@ public class UpdateManagerTests
|
||||
Assert.Equal("https://mysite.com/releases/AvaloniaCrossPlat$-1.1.0.nupkg", dl.LastUrl);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void DownlaodFullUpdateFromFixtures()
|
||||
{
|
||||
using var logger = _output.BuildLoggerFor<UpdateManagerTests>();
|
||||
using var _1 = TempUtil.GetTempDirectory(out var packagesPath);
|
||||
using var _2 = TempUtil.GetTempDirectory(out var feedPath);
|
||||
|
||||
var locator = new TestVelopackLocator("MyCoolApp", "1.0.0", packagesPath, logger.ToVelopackLogger());
|
||||
|
||||
File.Copy(PathHelper.GetFixture("testfeed.json"), Path.Combine(feedPath, "releases.beta.json"), true);
|
||||
File.Copy(PathHelper.GetFixture("AvaloniaCrossPlat-1.0.11-win-full.nupkg"), Path.Combine(feedPath, "AvaloniaCrossPlat-1.0.11-full.nupkg"), true);
|
||||
|
||||
var options = new UpdateOptions() {
|
||||
ExplicitChannel = "beta",
|
||||
AllowVersionDowngrade = false,
|
||||
MaximumDeltasBeforeFallback = 10,
|
||||
};
|
||||
|
||||
var um = new UpdateManager(feedPath, options, locator);
|
||||
var updateInfo = um.CheckForUpdates();
|
||||
Assert.NotNull(updateInfo);
|
||||
um.DownloadUpdates(updateInfo);
|
||||
Assert.True(File.Exists(Path.Combine(packagesPath, "AvaloniaCrossPlat-1.0.11-full.nupkg")));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CheckFromLocal()
|
||||
{
|
||||
|
||||
4
test/fixtures/testfeed.json
vendored
4
test/fixtures/testfeed.json
vendored
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user