Skip to content
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

Clean up temp files from installer download #56

Merged
merged 6 commits into from
Jun 3, 2021
Merged

Clean up temp files from installer download #56

merged 6 commits into from
Jun 3, 2021

Conversation

ryfu-msft
Copy link
Contributor

@ryfu-msft ryfu-msft commented Jun 2, 2021

The changes in this pull request ensure that the temp files from the downloaded installer are deleted before the end of the command execution. This should fix #40, where the installer hash does not match due to old installer files not being cleaned up from the %TEMP% directory.

Microsoft Reviewers: Open in CodeFlow

@ryfu-msft ryfu-msft requested a review from palenshus June 2, 2021 17:25
@palenshus
Copy link
Contributor

Looks like we have a bug, in DownloadFileAsync, if the file already exists, but with a different length, we download the new one, but looks like that doesn't replace the old one, it just writes overwrites it. Meaning, if the previous one is larger, we'll download a smaller one and write those bytes over the old one, creating a bogus file.

The fix is simple, and I think sufficient to protect us here, add a File.Delete:

        if (!File.Exists(targetFile) || new FileInfo(targetFile).Length != downloadSize)
        {
            File.Delete(targetFile);
            using var targetFileStream = File.OpenWrite(targetFile);

What do you think?

@ghost ghost added the Issue-Bug label Jun 3, 2021
@ryfu-msft ryfu-msft marked this pull request as ready for review June 3, 2021 16:17
@ryfu-msft ryfu-msft requested a review from a team as a code owner June 3, 2021 16:17
@ryfu-msft
Copy link
Contributor Author

Looks like we have a bug, in DownloadFileAsync, if the file already exists, but with a different length, we download the new one, but looks like that doesn't replace the old one, it just writes overwrites it. Meaning, if the previous one is larger, we'll download a smaller one and write those bytes over the old one, creating a bogus file.

The fix is simple, and I think sufficient to protect us here, add a File.Delete:

        if (!File.Exists(targetFile) || new FileInfo(targetFile).Length != downloadSize)
        {
            File.Delete(targetFile);
            using var targetFileStream = File.OpenWrite(targetFile);

What do you think?

100% agree. This is a much better solution. I added your suggested changes and removed mine

@ryfu-msft ryfu-msft closed this Jun 3, 2021
@ryfu-msft ryfu-msft reopened this Jun 3, 2021
NOTICE.txt Show resolved Hide resolved
@palenshus
Copy link
Contributor

using CommandLine;

Can you reset this file since it's no longer being changed?


Refers to: src/WingetCreateCLI/Commands/NewCommand.cs:13 in 9c904ab. [](commit_id = 9c904ab, deletion_comment = False)

Copy link
Contributor

@palenshus palenshus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Installer hash does not match
2 participants