winget-cli icon indicating copy to clipboard operation
winget-cli copied to clipboard

Installation of portable packages does not respect scope preference from settings.json

Open sitiom opened this issue 3 years ago • 1 comments

Brief description of your issue

Installation of portable packages does not respect scope preference defined in the settings.json. Explicitly using the --scope parameter works, however.

Steps to reproduce

  1. Add this section in your settings.json:
    "installBehavior": {
        "preferences": {
            "scope": "machine"
        }
    },
  1. Install a portable package without explicitly defining the scope (e.g., winget install yt-dlp.yt-dlp)
  2. Package is installed under user scope

Expected behavior

It should respect the scope preference in the settings.json

Actual behavior

It defaults to the user scope despite the config in the settings.

Environment

Windows Package Manager v1.4.10173
Copyright (c) Microsoft Corporation. All rights reserved.

Windows: Windows.Desktop v10.0.22621.1194
System Architecture: X64
Package: Microsoft.DesktopAppInstaller v1.19.10173.0

Logs: %LOCALAPPDATA%\Packages\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe\LocalState\DiagOutputDir

User Settings: %LOCALAPPDATA%\Packages\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe\LocalState\settings.json

sitiom avatar Aug 28 '22 02:08 sitiom

I think I found the bug.

In PortableFlow.cpp in InitializePortableInstaller(), there is the following line:

scope = Manifest::ConvertToScopeEnum(context.Args.GetArg(Execution::Args::Type::InstallScope));

This doesn't check the settings.json file at all.

To fix this, it needs to check ConvertScope(Settings::User().Get<Settings::Setting::InstallScopePreference>()) and ConvertScope(Settings::User().Get<Settings::Setting::InstallScopeRequirement>()) as well.

MarcoPeraza avatar Feb 02 '23 17:02 MarcoPeraza