Skip to content

Commit d147071

Browse files
authored
Normalize directory separators when adding packages to path (#5796)
- Resolves #5033
1 parent 0be0199 commit d147071

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

doc/ReleaseNotes.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,6 @@ To use the feature, try `winget source edit winget-font` to set the Explicit sta
1414
<!-- Nothing yet! -->
1515

1616
## Bug Fixes
17+
* Portable Packages now use the correct directory separators regardless of which convention is used in the manifest
1718
* `--suppress-initial-details` now works with `winget configure test`
1819
* `--suppress-initial-details` no longer requires `--accept-configuration-agreements`

src/AppInstallerCLICore/PortableInstaller.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -359,8 +359,11 @@ namespace AppInstaller::CLI::Portable
359359
}
360360
}
361361

362-
void PortableInstaller::AddToPathVariable(const std::filesystem::path& value)
362+
void PortableInstaller::AddToPathVariable(std::filesystem::path value)
363363
{
364+
// Ensure the preferred separator format
365+
value.make_preferred();
366+
364367
if (PathVariable(GetScope()).Append(value))
365368
{
366369
AICLI_LOG(Core, Info, << "Appending portable target directory to PATH registry: " << value);
@@ -372,15 +375,17 @@ namespace AppInstaller::CLI::Portable
372375
}
373376
}
374377

375-
void PortableInstaller::RemoveFromPathVariable(const std::filesystem::path& value)
378+
void PortableInstaller::RemoveFromPathVariable(std::filesystem::path value)
376379
{
377380
if (std::filesystem::exists(value) && !std::filesystem::is_empty(value))
378381
{
379382
AICLI_LOG(Core, Info, << "Install directory is not empty: " << value);
380383
}
381384
else
382385
{
383-
if (PathVariable(GetScope()).Remove(value))
386+
// Attempt to remove both the original and the preferred format to ensure removal
387+
// Necessary for handling old path values associated with winget-cli#5033
388+
if (PathVariable(GetScope()).Remove(value) || PathVariable(GetScope()).Remove(value.make_preferred()))
384389
{
385390
InstallDirectoryAddedToPath = false;
386391
AICLI_LOG(CLI, Info, << "Removed target directory from PATH registry: " << value);

src/AppInstallerCLICore/PortableInstaller.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ namespace AppInstaller::CLI::Portable
113113
void CreateTargetInstallDirectory();
114114
void RemoveInstallDirectory();
115115

116-
void AddToPathVariable(const std::filesystem::path& value);
117-
void RemoveFromPathVariable(const std::filesystem::path& value);
116+
void AddToPathVariable(std::filesystem::path value);
117+
void RemoveFromPathVariable(std::filesystem::path value);
118118
};
119119
}

0 commit comments

Comments
 (0)