diff --git a/doc/ReleaseNotes.md b/doc/ReleaseNotes.md index 8ec1e210c6..10b0987511 100644 --- a/doc/ReleaseNotes.md +++ b/doc/ReleaseNotes.md @@ -1,3 +1,6 @@ ## New in v1.28 + +## Bug Fixes +* `winget export` now works when the destination path is a hidden file diff --git a/src/AppInstallerCLICore/Workflows/ImportExportFlow.cpp b/src/AppInstallerCLICore/Workflows/ImportExportFlow.cpp index eaceb5e85c..2213735183 100644 --- a/src/AppInstallerCLICore/Workflows/ImportExportFlow.cpp +++ b/src/AppInstallerCLICore/Workflows/ImportExportFlow.cpp @@ -157,8 +157,25 @@ namespace AppInstaller::CLI::Workflow auto packages = PackagesJson::CreateJson(context.Get()); std::filesystem::path outputFilePath{ context.Args.GetArg(Execution::Args::Type::OutputFile) }; + + // Check if the file exists and is hidden + DWORD attrs = std::filesystem::exists(outputFilePath) ? GetFileAttributesW(outputFilePath.c_str()) : INVALID_FILE_ATTRIBUTES; + bool isHidden = (attrs != INVALID_FILE_ATTRIBUTES && (attrs & FILE_ATTRIBUTE_HIDDEN)); + + if (isHidden) + { + // Remove hidden attribute so we can write to it + SetFileAttributesW(outputFilePath.c_str(), attrs & ~FILE_ATTRIBUTE_HIDDEN); + } + std::ofstream outputFileStream{ outputFilePath }; outputFileStream << packages; + + if (isHidden) + { + // Restore hidden attribute + SetFileAttributesW(outputFilePath.c_str(), attrs); + } } void ReadImportFile(Execution::Context& context)