Skip to content

Commit

Permalink
Installer and manifest
Browse files Browse the repository at this point in the history
  • Loading branch information
msftrubengu committed Oct 3, 2023
1 parent cb77351 commit 4c352ff
Show file tree
Hide file tree
Showing 10 changed files with 52 additions and 27 deletions.
24 changes: 23 additions & 1 deletion src/AppInstallerCLICore/Workflows/DownloadFlow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,8 @@ namespace AppInstaller::CLI::Workflow

std::optional<std::vector<BYTE>> hash;

const int MaxRetryCount = 2;
constexpr int MaxRetryCount = 2;
constexpr std::chrono::seconds maximumWaitTimeAllowed = 60s;
for (int retryCount = 0; retryCount < MaxRetryCount; ++retryCount)
{
bool success = false;
Expand All @@ -323,6 +324,27 @@ namespace AppInstaller::CLI::Workflow

success = true;
}
catch (const ServiceUnavailableException& sue)
{
if (retryCount < MaxRetryCount - 1)
{
auto waitSecondsForRetry = sue.RetryAfter();
if (waitSecondsForRetry > maximumWaitTimeAllowed)
{
throw;
}

bool waitCompleted = context.Reporter.ExecuteWithProgress([&waitSecondsForRetry](IProgressCallback& progress)
{
return ProgressCallback::Wait(progress, waitSecondsForRetry);
});

if (!waitCompleted)
{
break;
}
}
}
catch (...)
{
if (retryCount < MaxRetryCount - 1)
Expand Down
5 changes: 0 additions & 5 deletions src/AppInstallerCLITests/TestCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,6 @@ namespace TestCommon
return {};
}

bool TestProgress::Wait(std::chrono::milliseconds)
{
return false;
}

wil::unique_hkey RegCreateVolatileTestRoot()
{
// First create/open the real test root
Expand Down
2 changes: 0 additions & 2 deletions src/AppInstallerCLITests/TestCommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,6 @@ namespace TestCommon

CancelFunctionRemoval SetCancellationFunction(std::function<void()>&& f) override;

bool Wait(std::chrono::milliseconds millisecondsToWait) override;

std::function<void(uint64_t, uint64_t, AppInstaller::ProgressType)> m_OnProgress;
};

Expand Down
3 changes: 1 addition & 2 deletions src/AppInstallerCommonCore/Downloader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -514,8 +514,7 @@ namespace AppInstaller::Utility
{
if (hre.code() == APPINSTALLER_CLI_ERROR_SERVICE_UNAVAILABLE)
{
auto retryAfter = httpRandomAccessStream->RetryAfter();
THROW_EXCEPTION(AppInstaller::Utility::ServiceUnavailableException(retryAfter));
THROW_EXCEPTION(AppInstaller::Utility::ServiceUnavailableException(httpRandomAccessStream->RetryAfter()));
}

throw;
Expand Down
1 change: 0 additions & 1 deletion src/AppInstallerCommonCore/MsixInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,6 @@ namespace AppInstaller::Msix
{
m_stream = Utility::GetReadOnlyStreamFromURI(uriStr);

// Here if thrown APPINSTALLER_CLI_ERROR_SERVICE_UNAVAILABLE somehow get RetryAfter
if (GetBundleReader(m_stream.Get(), &m_bundleReader))
{
m_isBundle = true;
Expand Down
4 changes: 2 additions & 2 deletions src/AppInstallerCommonCore/Progress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,12 @@ namespace AppInstaller
}
}

bool ProgressCallback::Wait(std::chrono::milliseconds millisecondsToWait)
bool ProgressCallback::Wait(IProgressCallback& progress, std::chrono::milliseconds millisecondsToWait)
{
wil::unique_event calledEvent;
calledEvent.create();

auto cancellationFunc = this->SetCancellationFunction([&calledEvent]()
auto cancellationFunc = progress.SetCancellationFunction([&calledEvent]()
{
calledEvent.SetEvent();
});
Expand Down
7 changes: 2 additions & 5 deletions src/AppInstallerCommonCore/Public/AppInstallerProgress.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,6 @@ namespace AppInstaller

// Sets a cancellation function that will be called when the operation is to be cancelled.
[[nodiscard]] virtual CancelFunctionRemoval SetCancellationFunction(std::function<void()>&& f) = 0;

// Waits with cancellation. Returns false if cancelled before timeout.
virtual bool Wait(std::chrono::milliseconds millisecondsToWait) = 0;
};

// Implementation of IProgressCallback.
Expand All @@ -81,6 +78,8 @@ namespace AppInstaller
ProgressCallback() = default;
ProgressCallback(IProgressSink* sink);

static bool Wait(IProgressCallback& progress, std::chrono::milliseconds ms);

void BeginProgress() override;

void OnProgress(uint64_t current, uint64_t maximum, ProgressType type) override;
Expand All @@ -93,8 +92,6 @@ namespace AppInstaller

[[nodiscard]] IProgressCallback::CancelFunctionRemoval SetCancellationFunction(std::function<void()>&& f) override;

bool Wait(std::chrono::milliseconds ms) override;

void Cancel(CancelReason reason = CancelReason::Abort);

IProgressSink* GetSink();
Expand Down
22 changes: 21 additions & 1 deletion src/AppInstallerRepositoryCore/Microsoft/SQLiteIndexSource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ namespace AppInstaller::Repository::Microsoft
AICLI_LOG(Repo, Info, << "Downloading manifest");
ProgressCallback emptyCallback;

const int MaxRetryCount = 2;
constexpr int MaxRetryCount = 2;
constexpr std::chrono::seconds maximumWaitTimeAllowed = 10s;
for (int retryCount = 0; retryCount < MaxRetryCount; ++retryCount)
{
try
Expand All @@ -157,6 +158,25 @@ namespace AppInstaller::Repository::Microsoft

break;
}
catch (const ServiceUnavailableException& sue)
{
if (retryCount < MaxRetryCount - 1)
{
auto waitSecondsForRetry = sue.RetryAfter();
if (waitSecondsForRetry > maximumWaitTimeAllowed)
{
throw;
}

// TODO: Get real progress callback to allow cancelation.
auto ms = std::chrono::duration_cast<std::chrono::milliseconds>(waitSecondsForRetry);
Sleep(static_cast<DWORD>(ms.count()));
}
else
{
throw;
}
}
catch (...)
{
if (retryCount < MaxRetryCount - 1)
Expand Down
9 changes: 1 addition & 8 deletions src/AppInstallerRepositoryCore/RepositorySource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,6 @@ namespace AppInstaller::Repository
{
AddOrUpdateResult result;

// Do not update if we are still before the update block time.
if (IsUpdateSuppressed(details))
{
AICLI_LOG(Repo, Info, << "Update is suppressed until: " << details.DoNotUpdateBefore);
return {};
}

auto factory = ISourceFactory::GetForType(details.Type);

// If we are instructed to wait longer than this, just fail rather than retrying.
Expand Down Expand Up @@ -109,7 +102,7 @@ namespace AppInstaller::Repository

AICLI_LOG(Repo, Info, << "Source add/update failed, waiting " << millisecondsToWait.count() << " milliseconds and retrying: " << details.Name);

if (!progress.Wait(millisecondsToWait))
if (!ProgressCallback::Wait(progress, millisecondsToWait))
{
AICLI_LOG(Repo, Info, << "Source second try cancelled.");
return {};
Expand Down
2 changes: 2 additions & 0 deletions src/WinGetUtil/pch.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@
#include <memory>
#include <mutex>
#include <string>

#include <winrt/Windows.Foundation.h>

0 comments on commit 4c352ff

Please sign in to comment.