winget-cli

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit bea26bae8b5c983238139189d91ee3ebe4d5d268
parent 43fc40e7e065dda4d982ba316f92c44d311ff7a7
Author: yao-msft <50888816+yao-msft@users.noreply.github.com>
Date:   Fri,  2 Jun 2023 18:35:34 -0700

Move hasData check to default installation check only (#3302)


Diffstat:
Msrc/AppInstallerCLICore/Argument.cpp | 2+-
Msrc/AppInstallerCLICore/Workflows/UpdateFlow.cpp | 7++-----
Msrc/AppInstallerRepositoryCore/PackageInstalledStatus.cpp | 139+++++++++++++++++++++++++++++++++++++++----------------------------------------
3 files changed, 71 insertions(+), 77 deletions(-)

diff --git a/src/AppInstallerCLICore/Argument.cpp b/src/AppInstallerCLICore/Argument.cpp @@ -148,7 +148,7 @@ namespace AppInstaller::CLI case Execution::Args::Type::All: return { type, "all"_liv, 'r', "recurse"_liv, ArgTypeCategory::MultiplePackages }; case Execution::Args::Type::IncludeUnknown: - return { type, "include-unknown"_liv, 'u', "unknown"_liv }; + return { type, "include-unknown"_liv, 'u', "unknown"_liv, ArgTypeCategory::CopyFlagToSubContext }; case Execution::Args::Type::IncludePinned: return { type, "include-pinned"_liv, "pinned"_liv, ArgTypeCategory::CopyFlagToSubContext }; case Execution::Args::Type::UninstallPrevious: diff --git a/src/AppInstallerCLICore/Workflows/UpdateFlow.cpp b/src/AppInstallerCLICore/Workflows/UpdateFlow.cpp @@ -218,11 +218,8 @@ namespace AppInstaller::CLI::Workflow updateContext.Add<Execution::Data::Package>(match.Package); // Filter out packages with unknown installed versions - if (context.Args.Contains(Execution::Args::Type::IncludeUnknown)) - { - updateContext.Args.AddArg(Execution::Args::Type::IncludeUnknown); - } - else if (Utility::Version(installedVersion->GetProperty(PackageVersionProperty::Version)).IsUnknown()) + if (Utility::Version(installedVersion->GetProperty(PackageVersionProperty::Version)).IsUnknown() && + !context.Args.Contains(Execution::Args::Type::IncludeUnknown)) { // we don't know what the package's version is and the user didn't ask to upgrade it anyway. AICLI_LOG(CLI, Info, << "Skipping " << match.Package->GetProperty(PackageProperty::Id) << " as it has unknown installed version"); diff --git a/src/AppInstallerRepositoryCore/PackageInstalledStatus.cpp b/src/AppInstallerRepositoryCore/PackageInstalledStatus.cpp @@ -146,93 +146,90 @@ namespace AppInstaller::Repository auto manifest = availableVersion->GetManifest(); for (auto const& installer : manifest.Installers) { - if (installer.InstallationMetadata.HasData()) + InstallerInstalledStatus installerStatus; + installerStatus.Installer = installer; + + // ARP related checks + if (WI_IsAnyFlagSet(checkTypes, InstalledStatusType::AllAppsAndFeaturesEntryChecks)) { - InstallerInstalledStatus installerStatus; - installerStatus.Installer = installer; + bool isMatchingInstaller = + installedVersion && + IsInstallerTypeCompatible(installedType, installer.EffectiveInstallerType()) && + (installedScope == ScopeEnum::Unknown || installer.Scope == ScopeEnum::Unknown || installedScope == installer.Scope) && // Treat unknown scope as compatible + (installedArchitecture == Utility::Architecture::Unknown || installer.Arch == Utility::Architecture::Neutral || installedArchitecture == installer.Arch) && // Treat unknown installed architecture as compatible + (installedLocale.empty() || installer.Locale.empty() || !Locale::IsWellFormedBcp47Tag(installedLocale) || Locale::GetDistanceOfLanguage(installedLocale, installer.Locale) >= Locale::MinimumDistanceScoreAsCompatibleMatch); // Treat invalid locale as compatible + + // ARP entry status + if (WI_IsFlagSet(checkTypes, InstalledStatusType::AppsAndFeaturesEntry)) + { + installerStatus.Status.emplace_back( + InstalledStatusType::AppsAndFeaturesEntry, + "", + isMatchingInstaller ? WINGET_INSTALLED_STATUS_ARP_ENTRY_FOUND : WINGET_INSTALLED_STATUS_ARP_ENTRY_NOT_FOUND); + } - // ARP related checks - if (WI_IsAnyFlagSet(checkTypes, InstalledStatusType::AllAppsAndFeaturesEntryChecks)) + // ARP install location status + if (isMatchingInstaller && WI_IsFlagSet(checkTypes, InstalledStatusType::AppsAndFeaturesEntryInstallLocation)) { - bool isMatchingInstaller = - installedVersion && - IsInstallerTypeCompatible(installedType, installer.EffectiveInstallerType()) && - (installedScope == ScopeEnum::Unknown || installer.Scope == ScopeEnum::Unknown || installedScope == installer.Scope) && // Treat unknown scope as compatible - (installedArchitecture == Utility::Architecture::Unknown || installer.Arch == Utility::Architecture::Neutral || installedArchitecture == installer.Arch) && // Treat unknown installed architecture as compatible - (installedLocale.empty() || installer.Locale.empty() || !Locale::IsWellFormedBcp47Tag(installedLocale) || Locale::GetDistanceOfLanguage(installedLocale, installer.Locale) >= Locale::MinimumDistanceScoreAsCompatibleMatch); // Treat invalid locale as compatible - - // ARP entry status - if (WI_IsFlagSet(checkTypes, InstalledStatusType::AppsAndFeaturesEntry)) - { - installerStatus.Status.emplace_back( - InstalledStatusType::AppsAndFeaturesEntry, - "", - isMatchingInstaller ? WINGET_INSTALLED_STATUS_ARP_ENTRY_FOUND : WINGET_INSTALLED_STATUS_ARP_ENTRY_NOT_FOUND); - } + installerStatus.Status.emplace_back( + InstalledStatusType::AppsAndFeaturesEntryInstallLocation, + installedLocation.u8string(), + installedLocationStatus); + } - // ARP install location status - if (isMatchingInstaller && WI_IsFlagSet(checkTypes, InstalledStatusType::AppsAndFeaturesEntryInstallLocation)) + // ARP install location files + if (isMatchingInstaller && + installedLocationStatus == WINGET_INSTALLED_STATUS_INSTALL_LOCATION_FOUND && + WI_IsFlagSet(checkTypes, InstalledStatusType::AppsAndFeaturesEntryInstallLocationFile)) + { + for (auto const& file : installer.InstallationMetadata.Files) { - installerStatus.Status.emplace_back( - InstalledStatusType::AppsAndFeaturesEntryInstallLocation, - installedLocation.u8string(), - installedLocationStatus); - } + std::filesystem::path filePath = installedLocation / Utility::ConvertToUTF16(file.RelativeFilePath); + auto fileStatus = CheckInstalledFileStatus(filePath, checkFileHash ? file.FileSha256 : Utility::SHA256::HashBuffer{}, fileHashes); - // ARP install location files - if (isMatchingInstaller && - installedLocationStatus == WINGET_INSTALLED_STATUS_INSTALL_LOCATION_FOUND && - WI_IsFlagSet(checkTypes, InstalledStatusType::AppsAndFeaturesEntryInstallLocationFile)) - { - for (auto const& file : installer.InstallationMetadata.Files) - { - std::filesystem::path filePath = installedLocation / Utility::ConvertToUTF16(file.RelativeFilePath); - auto fileStatus = CheckInstalledFileStatus(filePath, checkFileHash ? file.FileSha256 : Utility::SHA256::HashBuffer{}, fileHashes); - - installerStatus.Status.emplace_back( - InstalledStatusType::AppsAndFeaturesEntryInstallLocationFile, - filePath.u8string(), - fileStatus); - } + installerStatus.Status.emplace_back( + InstalledStatusType::AppsAndFeaturesEntryInstallLocationFile, + filePath.u8string(), + fileStatus); } } + } - // Default install location related checks - if (WI_IsAnyFlagSet(checkTypes, InstalledStatusType::AllDefaultInstallLocationChecks)) + // Default install location related checks + if (WI_IsAnyFlagSet(checkTypes, InstalledStatusType::AllDefaultInstallLocationChecks) && installer.InstallationMetadata.HasData()) + { + auto defaultInstalledLocation = Filesystem::GetExpandedPath(installer.InstallationMetadata.DefaultInstallLocation); + HRESULT defaultInstalledLocationStatus = CheckInstalledLocationStatus(defaultInstalledLocation); + + // Default install location status + if (WI_IsFlagSet(checkTypes, InstalledStatusType::DefaultInstallLocation)) { - auto defaultInstalledLocation = Filesystem::GetExpandedPath(installer.InstallationMetadata.DefaultInstallLocation); - HRESULT defaultInstalledLocationStatus = CheckInstalledLocationStatus(defaultInstalledLocation); + installerStatus.Status.emplace_back( + InstalledStatusType::DefaultInstallLocation, + defaultInstalledLocation.u8string(), + defaultInstalledLocationStatus); + } - // Default install location status - if (WI_IsFlagSet(checkTypes, InstalledStatusType::DefaultInstallLocation)) + // Default install location files + if (defaultInstalledLocationStatus == WINGET_INSTALLED_STATUS_INSTALL_LOCATION_FOUND && + WI_IsFlagSet(checkTypes, InstalledStatusType::DefaultInstallLocationFile)) + { + for (auto const& file : installer.InstallationMetadata.Files) { - installerStatus.Status.emplace_back( - InstalledStatusType::DefaultInstallLocation, - defaultInstalledLocation.u8string(), - defaultInstalledLocationStatus); - } + std::filesystem::path filePath = defaultInstalledLocation / Utility::ConvertToUTF16(file.RelativeFilePath); + auto fileStatus = CheckInstalledFileStatus(filePath, checkFileHash ? file.FileSha256 : Utility::SHA256::HashBuffer{}, fileHashes); - // Default install location files - if (defaultInstalledLocationStatus == WINGET_INSTALLED_STATUS_INSTALL_LOCATION_FOUND && - WI_IsFlagSet(checkTypes, InstalledStatusType::DefaultInstallLocationFile)) - { - for (auto const& file : installer.InstallationMetadata.Files) - { - std::filesystem::path filePath = defaultInstalledLocation / Utility::ConvertToUTF16(file.RelativeFilePath); - auto fileStatus = CheckInstalledFileStatus(filePath, checkFileHash ? file.FileSha256 : Utility::SHA256::HashBuffer{}, fileHashes); - - installerStatus.Status.emplace_back( - InstalledStatusType::DefaultInstallLocationFile, - filePath.u8string(), - fileStatus); - } + installerStatus.Status.emplace_back( + InstalledStatusType::DefaultInstallLocationFile, + filePath.u8string(), + fileStatus); } } + } - if (!installerStatus.Status.empty()) - { - result.emplace_back(std::move(installerStatus)); - } + if (!installerStatus.Status.empty()) + { + result.emplace_back(std::move(installerStatus)); } }