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

Show file name in Invoke-WebRequest -OutFile -Verbose #24041

Merged
merged 1 commit into from
Jul 17, 2024

Conversation

jshigetomi
Copy link
Collaborator

@jshigetomi jshigetomi commented Jul 10, 2024

PR Summary

When using the Invoke-WebRequest -OutFile the verbose output of the file name is not the file name but the provided directory. File name should reflect the downloaded file name and not the directory.

I replaced the directory output to the file name I accessed from the HttpResponseMessage object.

PR Context

Fixes: #21081

This PR is part of an effort to resolve all issues related to @CarloToso 's contribution which made directory passing available for Invoke-WebRequest cmdlet when the -OutFile flag is present.

@mklement0 mentioned in #21081 that VERBOSE: File Name: displays the given directory name instead of the file name.

PR Checklist

@jshigetomi jshigetomi changed the title Fixes: #21081 from Fix Invoke-WebRequest -OutFile Verbose Outputting Directory Name Instead of File Name Jul 10, 2024
@@ -63,7 +63,7 @@ internal override void ProcessResponse(HttpResponseMessage response)
{
string outFilePath = WebResponseHelper.GetOutFilePath(response, _qualifiedOutFile);

WriteVerbose(string.Create(System.Globalization.CultureInfo.InvariantCulture, $"File Name: {Path.GetFileName(_qualifiedOutFile)}"));
WriteVerbose(string.Create(System.Globalization.CultureInfo.InvariantCulture, $"File Name: {response.RequestMessage?.RequestUri?.Segments[^1]}"));
Copy link
Collaborator

Choose a reason for hiding this comment

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

Wouldn't we want to use the outFilePath rather than repeating the more complex logic done in GetOutFilePath? We can keep the Path.GetFileName call if we just want the filename and not the full path.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@jborean93 , good catch! That is a much better way to do it.

@iSazonov
Copy link
Collaborator

@mklement0 Please review.

@iSazonov iSazonov added the CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log label Jul 16, 2024
@mklement0
Copy link
Contributor

@iSazonov, it looks like the content of this PR is also part of the more comprehensive #24047

@iSazonov
Copy link
Collaborator

@iSazonov, it looks like the content of this PR is also part of the more comprehensive #24047

If current PR solves problem #21081 it is enough to merge as more specific PR.

@mklement0
Copy link
Contributor

It does.

@iSazonov iSazonov self-assigned this Jul 17, 2024
@iSazonov iSazonov changed the title Fix Invoke-WebRequest -OutFile Verbose Outputting Directory Name Instead of File Name Output file name in Invoke-WebRequest -OutFile -Verbose Jul 17, 2024
@iSazonov iSazonov changed the title Output file name in Invoke-WebRequest -OutFile -Verbose Show file name in Invoke-WebRequest -OutFile -Verbose Jul 17, 2024
@iSazonov iSazonov merged commit 666fdb5 into PowerShell:master Jul 17, 2024
32 checks passed
Copy link
Contributor

microsoft-github-policy-service bot commented Jul 17, 2024

📣 Hey @jshigetomi, how did we do? We would love to hear your feedback with the link below! 🗣️

🔗 https://aka.ms/PSRepoFeedback

@jshigetomi jshigetomi deleted the issue-21081-fix branch July 17, 2024 17:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log
Projects
None yet
4 participants