Skip to content

Commit

Permalink
Implement DownloadCommandProhibited (#3487)
Browse files Browse the repository at this point in the history
  • Loading branch information
yao-msft authored Aug 2, 2023
1 parent f1627af commit 881904c
Show file tree
Hide file tree
Showing 34 changed files with 686 additions and 7 deletions.
2 changes: 2 additions & 0 deletions doc/windows/package-manager/winget/returnCodes.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ ms.localizationpriority: medium
| 0x8A150069 | -1978335127 | APPINSTALLER_CLI_ERROR_PACKAGE_IS_STUB | The package currently installed is the stub package |
| 0x8A15006A | -1978335126 | APPINSTALLER_CLI_ERROR_APPTERMINATION_RECEIVED | Application shutdown signal received |
| 0x8A15006B | -1978335125 | APPINSTALLER_CLI_ERROR_DOWNLOAD_DEPENDENCIES | Failed to download package dependencies. |
| 0x8A15006C | -1978335124 | APPINSTALLER_CLI_ERROR_DOWNLOAD_COMMAND_PROHIBITED | Failed to download package. Download for offline installation is prohibited. |


## Install errors.

Expand Down
10 changes: 10 additions & 0 deletions schemas/JSON/manifests/v1.6.0/manifest.installer.1.6.0.json
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,10 @@
},
"description": "Details about the installation. Used for deeper installation detection."
},
"DownloadCommandProhibited": {
"type": [ "boolean", "null" ],
"description": "Indicates whether the installer is prohibited from being downloaded for offline installation."
},
"Installer": {
"type": "object",
"properties": {
Expand Down Expand Up @@ -690,6 +694,9 @@
},
"InstallationMetadata": {
"$ref": "#/$defs/InstallationMetadata"
},
"DownloadCommandProhibited": {
"$ref": "#/$defs/DownloadCommandProhibited"
}
},
"required": [
Expand Down Expand Up @@ -803,6 +810,9 @@
"InstallationMetadata": {
"$ref": "#/$defs/InstallationMetadata"
},
"DownloadCommandProhibited": {
"$ref": "#/$defs/DownloadCommandProhibited"
},
"Installers": {
"type": "array",
"items": {
Expand Down
10 changes: 10 additions & 0 deletions schemas/JSON/manifests/v1.6.0/manifest.singleton.1.6.0.json
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,10 @@
},
"description": "Details about the installation. Used for deeper installation detection."
},
"DownloadCommandProhibited": {
"type": [ "boolean", "null" ],
"description": "Indicates whether the installer is prohibited from being downloaded for offline installation."
},
"Installer": {
"type": "object",
"properties": {
Expand Down Expand Up @@ -789,6 +793,9 @@
},
"InstallationMetadata": {
"$ref": "#/$defs/InstallationMetadata"
},
"DownloadCommandProhibited": {
"$ref": "#/$defs/DownloadCommandProhibited"
}
},
"required": [
Expand Down Expand Up @@ -1025,6 +1032,9 @@
"InstallationMetadata": {
"$ref": "#/$defs/InstallationMetadata"
},
"DownloadCommandProhibited": {
"$ref": "#/$defs/DownloadCommandProhibited"
},
"Installers": {
"type": "array",
"items": {
Expand Down
1 change: 1 addition & 0 deletions src/AppInstallerCLICore/Resources.h
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ namespace AppInstaller::CLI::Resource
WINGET_DEFINE_RESOURCE_STRINGID(InstalledScopeArgumentDescription);
WINGET_DEFINE_RESOURCE_STRINGID(InstallerAbortsTerminal);
WINGET_DEFINE_RESOURCE_STRINGID(InstallerBlockedByPolicy);
WINGET_DEFINE_RESOURCE_STRINGID(InstallerDownloadCommandProhibited);
WINGET_DEFINE_RESOURCE_STRINGID(InstallerDownloaded);
WINGET_DEFINE_RESOURCE_STRINGID(InstallerDownloads);
WINGET_DEFINE_RESOURCE_STRINGID(InstallerElevationExpected);
Expand Down
19 changes: 18 additions & 1 deletion src/AppInstallerCLICore/Workflows/DownloadFlow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -591,4 +591,21 @@ namespace AppInstaller::CLI::Workflow
YamlWriter::OutputYamlFile(manifest, installer.value(), manifestDownloadPath);
AICLI_LOG(CLI, Info, << "Successfully generated manifest yaml. Path: " << manifestDownloadPath);
}
}

void EnsureSupportForDownload(Execution::Context& context)
{
// No checks needed if not download installer only.
if (WI_IsFlagClear(context.GetFlags(), Execution::ContextFlag::InstallerDownloadOnly))
{
return;
}

const auto& installer = context.Get<Execution::Data::Installer>();

if (installer->DownloadCommandProhibited)
{
context.Reporter.Error() << Resource::String::InstallerDownloadCommandProhibited << std::endl;
AICLI_TERMINATE_CONTEXT(APPINSTALLER_CLI_ERROR_DOWNLOAD_COMMAND_PROHIBITED);
}
}
}
6 changes: 6 additions & 0 deletions src/AppInstallerCLICore/Workflows/DownloadFlow.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,10 @@ namespace AppInstaller::CLI::Workflow
// Inputs: Manifest, Installer, DownloadDirectory
// Outputs: None
void ExportManifest(Execution::Context& context);

// This method ensures requirements of download for later offline installation.
// Required Args: None
// Inputs: Installer
// Outputs: None
void EnsureSupportForDownload(Execution::Context& context);
}
4 changes: 3 additions & 1 deletion src/AppInstallerCLICore/Workflows/InstallFlow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,9 @@ namespace AppInstaller::CLI::Workflow
AICLI_TERMINATE_CONTEXT(APPINSTALLER_CLI_ERROR_NO_APPLICABLE_INSTALLER);
}

context << EnsureSupportForInstall;
context <<
EnsureSupportForDownload <<
EnsureSupportForInstall;
}

void CheckForUnsupportedArgs(Execution::Context& context)
Expand Down
4 changes: 3 additions & 1 deletion src/AppInstallerCLIE2ETests/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,9 @@ public class ErrorCode
public const int ERROR_NOT_ALL_QUERIES_FOUND_SINGLE = unchecked((int)0x8A150067);
public const int ERROR_PACKAGE_IS_PINNED = unchecked((int)0x8A150068);
public const int ERROR_PACKAGE_IS_STUB = unchecked((int)0x8A150069);
public const int ERROR_DOWNLOAD_DEPENDENCIES = unchecked((int)0x8A15006A);
public const int ERROR_APPTERMINATION_RECEIVED = unchecked((int)0x8A15006A);
public const int ERROR_DOWNLOAD_DEPENDENCIES = unchecked((int)0x8A15006B);
public const int ERROR_DOWNLOAD_COMMAND_PROHIBITED = unchecked((int)0x8A15006C);

public const int ERROR_INSTALL_PACKAGE_IN_USE = unchecked((int)0x8A150101);
public const int ERROR_INSTALL_INSTALL_IN_PROGRESS = unchecked((int)0x8A150102);
Expand Down
3 changes: 3 additions & 0 deletions src/AppInstallerCLIPackage/Shared/Strings/en-us/winget.resw
Original file line number Diff line number Diff line change
Expand Up @@ -2056,4 +2056,7 @@ Please specify one of them using the --source option to proceed.</value>
<data name="InstallerDownloads" xml:space="preserve">
<value>Installer Downloads</value>
</data>
<data name="InstallerDownloadCommandProhibited" xml:space="preserve">
<value>Installer is prohibited from being downloaded for later offline installation. </value>
</data>
</root>
5 changes: 5 additions & 0 deletions src/AppInstallerCLITests/AppInstallerCLITests.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@
<ClCompile Include="CustomHeader.cpp" />
<ClCompile Include="Dependencies.cpp" />
<ClCompile Include="Downloader.cpp" />
<ClCompile Include="DownloadFlow.cpp" />
<ClCompile Include="ExperimentalFeature.cpp" />
<ClCompile Include="ExportFlow.cpp" />
<ClCompile Include="Filesystem.cpp" />
Expand Down Expand Up @@ -243,6 +244,7 @@
<ClCompile Include="RestInterface_1_1.cpp" />
<ClCompile Include="RestInterface_1_4.cpp" />
<ClCompile Include="RestInterface_1_5.cpp" />
<ClCompile Include="RestInterface_1_6.cpp" />
<ClCompile Include="Runtime.cpp" />
<ClCompile Include="SearchRequestSerializer.cpp" />
<ClCompile Include="ShowFlow.cpp" />
Expand Down Expand Up @@ -283,6 +285,9 @@
<CopyFileToFolders Include="TestData\Manifest-Good.yaml">
<DeploymentContent>true</DeploymentContent>
</CopyFileToFolders>
<CopyFileToFolders Include="TestData\DownloadFlowTest_DownloadCommandProhibited.yaml">
<DeploymentContent>true</DeploymentContent>
</CopyFileToFolders>
<CopyFileToFolders Include="TestData\InstallFlowTest_EncodedUrl.yaml">
<DeploymentContent>true</DeploymentContent>
</CopyFileToFolders>
Expand Down
9 changes: 9 additions & 0 deletions src/AppInstallerCLITests/AppInstallerCLITests.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,12 @@
<ClCompile Include="PathVariable.cpp">
<Filter>Source Files\CLI</Filter>
</ClCompile>
<ClCompile Include="RestInterface_1_6.cpp">
<Filter>Source Files\Repository</Filter>
</ClCompile>
<ClCompile Include="DownloadFlow.cpp">
<Filter>Source Files\CLI</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<None Include="PropertySheet.props" />
Expand Down Expand Up @@ -573,6 +579,9 @@
<CopyFileToFolders Include="TestData\TestZip.zip">
<Filter>TestData</Filter>
</CopyFileToFolders>
<CopyFileToFolders Include="TestData\DownloadFlowTest_DownloadCommandProhibited.yaml">
<Filter>TestData</Filter>
</CopyFileToFolders>
<CopyFileToFolders Include="TestData\InstallFlowTest_NoApplicableArchitecture.yaml">
<Filter>TestData</Filter>
</CopyFileToFolders>
Expand Down
24 changes: 24 additions & 0 deletions src/AppInstallerCLITests/DownloadFlow.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
#include "pch.h"
#include "WorkflowCommon.h"
#include <Commands/DownloadCommand.h>

using namespace TestCommon;
using namespace AppInstaller::CLI;

TEST_CASE("DownloadFlow_DownloadCommandProhibited", "[DownloadFlow][workflow]")
{
std::ostringstream downloadOutput;
TestContext context{ downloadOutput, std::cin };
auto previousThreadGlobals = context.SetForCurrentThread();
context.Args.AddArg(Execution::Args::Type::Manifest, TestDataFile("DownloadFlowTest_DownloadCommandProhibited.yaml").GetPath().u8string());

DownloadCommand download({});
download.Execute(context);
INFO(downloadOutput.str());

// Verify AppInfo is printed
REQUIRE_TERMINATED_WITH(context, APPINSTALLER_CLI_ERROR_DOWNLOAD_COMMAND_PROHIBITED);
REQUIRE(downloadOutput.str().find(Resource::LocString(Resource::String::InstallerDownloadCommandProhibited).get()) != std::string::npos);
}
2 changes: 1 addition & 1 deletion src/AppInstallerCLITests/RestClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ TEST_CASE("GetSupportedInterface", "[RestSource]")
REQUIRE(RestClient::GetSupportedInterface(utility::conversions::to_utf8string(TestRestUri), {}, info, version)->GetVersion() == version);

// Update this test to next version so that we don't forget to add to supported versions before rest e2e tests are available.
Version invalid{ "1.6.0" };
Version invalid{ "1.7.0" };
REQUIRE_THROWS(RestClient::GetSupportedInterface(utility::conversions::to_utf8string(TestRestUri), {}, info, invalid));
}

Expand Down
Loading

0 comments on commit 881904c

Please sign in to comment.