-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Allow exporting to hidden files #5795
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,6 @@ | ||
| ## New in v1.28 | ||
|
|
||
| <!-- Nothing yet! --> | ||
|
|
||
| ## Bug Fixes | ||
| * `winget export` now works when the destination path is a hidden file |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -157,8 +157,25 @@ namespace AppInstaller::CLI::Workflow | |
| auto packages = PackagesJson::CreateJson(context.Get<Execution::Data::PackageCollection>()); | ||
|
|
||
| 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); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would really like it if there were a way to simply open the hidden file rather than changing the attribute. There might be a set of mode options that change the If that cannot be done, then at a minimum we should use a scope exit to reset the attributes. |
||
| } | ||
|
|
||
| std::ofstream outputFileStream{ outputFilePath }; | ||
| outputFileStream << packages; | ||
|
|
||
| if (isHidden) | ||
| { | ||
| // Restore hidden attribute | ||
| SetFileAttributesW(outputFilePath.c_str(), attrs); | ||
| } | ||
| } | ||
|
|
||
| void ReadImportFile(Execution::Context& context) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
existscheck shouldn't be necessary; the return value fromGetFileAttributesWshould beINVALID_FILE_ATTRIBUTESfor a non-existent file as well.