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

download with powershell 2.0 for windows #21968

Closed
wants to merge 7 commits into from
Closed

Conversation

musm
Copy link
Contributor

@musm musm commented May 19, 2017

Supported on all versions starting from windows 7

error("automatic download failed (error: $res): $url")
end
ps = "C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe"
res = run(`$ps -NoProfile -Command "(New-Object System.Net.Webclient).DownloadFile(\"$url\", \"$filename\")"`)
Copy link
Sponsor Member

Choose a reason for hiding this comment

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

DownloadFile('$(replace(url, "'", "''"))', '$(replace(filename, "'", "''"))'

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I admit I don't know what that does here, seem more complicated but does the same job?

Copy link
Sponsor Member

Choose a reason for hiding this comment

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

it ensures that meta characters (`, $, ') pass through unscathed

Copy link
Contributor

Choose a reason for hiding this comment

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

should have some tests for this then? likewise with the unix version

Copy link
Contributor

Choose a reason for hiding this comment

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

what is a counterexample and how does this fix it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@vtjnash (mind providing some test cases for this since I don't understand why it's needed?)

@vtjnash
Copy link
Sponsor Member

vtjnash commented May 19, 2017

Also, do we need to enable secure HTTPS support explicitly (JuliaPackaging/WinRPM.jl#57 (comment))?

@ararslan ararslan added the system:windows Affects only Windows label May 19, 2017
@musm
Copy link
Contributor Author

musm commented May 19, 2017

I enabled https support. Yes it looks like we need to do it explicitly.
I updated the code to always enable https tls1.2 support.

@musm
Copy link
Contributor Author

musm commented May 20, 2017

@musm
Copy link
Contributor Author

musm commented May 25, 2017

bump?

@@ -571,11 +571,10 @@ end
downloadcmd = nothing
Copy link
Contributor

Choose a reason for hiding this comment

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

may as well set this, if a command is being used

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think downloadcmd can be removed and just be a local variable.
However this is unrelated to the changes in this PR. Let's save this for a separate PR

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure on a good way to avoid the global here?

Copy link
Contributor

Choose a reason for hiding this comment

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

you're changing the download function to shell out to something, the value of what you're shelling out to should be saved in the global that exists for that purpose

end
ps = "C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe"
enable_tls12 = "[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12"
download_cmd = "(New-Object System.Net.Webclient).DownloadFile('$(replace(url, "'", "''"))', '$(replace(filename, "'", "''"))')"
Copy link
Contributor

Choose a reason for hiding this comment

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

this replacement doesn't make a lot of sense, could use comments and tests to show what it's accomplishing and why it's necessary

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See comment at #21968 (comment) . Not really sure why it's needed so someoneelse would need to add tests and comments for this

Copy link
Sponsor Member

Choose a reason for hiding this comment

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

try fetching a URL stuffed with metacharacters like https://httpbin.org/get?test='^"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think I see your point, but don't you want
replace(filename, "'", "\'")
instead of
replace(filename, "'", "''")
or are those the same

and is this only needed here since we first interpolate the string into another string before interpolating into the cmd run( ) ? I'm just trying to understand why the non windows download cmd doesn't need this.

Copy link
Sponsor Member

Choose a reason for hiding this comment

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

No, the escape sequence for ' is '', not \'

Non-windows can call the download program directly, and doesn't need to involve a shell.

Copy link
Contributor

Choose a reason for hiding this comment

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

you mean `' ?

Copy link
Sponsor Member

Choose a reason for hiding this comment

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

no, the escape-character is context sensitive. I used single quotes because the rules are simplest (https://ss64.com/ps/syntax-esc.html)

@musm
Copy link
Contributor Author

musm commented Jun 2, 2017

test added

@@ -598,7 +598,7 @@ else
rethrow()
end
elseif downloadcmd == :curl
run(`curl -L -f -o $filename $url`)
run(`curl -L -f -s -o $filename $url`)
Copy link
Contributor

Choose a reason for hiding this comment

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

separate PR please

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will do

Copy link
Contributor

Choose a reason for hiding this comment

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

you've seen JuliaPackaging/BinDeps.jl#135, but this function could probably use a more serious refactoring - not everyone will want all downloads to be silent. you can use curlrc to control some of these globally if you know you're using curl

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah I think that will require more serious thinking about the api etc. I think for now we should at least try to make the experience consistent; dumping out the progress bar from curl directly doesn't seem very Julian. I agree it would be useful to have some control over the progress etc.

@musm
Copy link
Contributor Author

musm commented Jun 2, 2017

anyone mind retriggering travis ?

@nalimilan
Copy link
Member

Done.

@KristofferC
Copy link
Sponsor Member

I plan on merging this tomorrow unless someone has an objection

@tkelman
Copy link
Contributor

tkelman commented Jun 26, 2017

This should set the downloadcmd global.

@musm
Copy link
Contributor Author

musm commented Jun 26, 2017

downloadcmd is only relevant for non windows systems. I have made no modifications to this variable in this PR, aside from placing it in the non windows branch, since it does not affect windows systems.

@tkelman
Copy link
Contributor

tkelman commented Jun 26, 2017

Now that the download function shells out on windows, that variable is relevant on windows

@musm
Copy link
Contributor Author

musm commented Jun 26, 2017

How so? Looks to me that downloadcmd is used on linux to test which download shell function to use. On windows we only have powershell so I am a bit confused as to your suggestion?

@tkelman
Copy link
Contributor

tkelman commented Jun 26, 2017

set it to powershell on windows.

@musm
Copy link
Contributor Author

musm commented Jul 8, 2017

Do we know what using powershell2 instead of URLDownloadToFileW solves? Is it possible proxy issues or something else. The docs mention that URLDownloadToFileW is limited to downloading 4GB files.

@vtjnash
Copy link
Sponsor Member

vtjnash commented Jul 9, 2017

The belief is that this will have better support for redirects, cookies, authentication, and file size among other issues

Copy link
Contributor

@tkelman tkelman left a comment

Choose a reason for hiding this comment

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

needs rebase

@@ -591,17 +591,19 @@ end

# file downloading

downloadcmd = nothing
Copy link
Contributor

Choose a reason for hiding this comment

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

don't think this should be moved

@musm
Copy link
Contributor Author

musm commented Jul 15, 2017

The only thing that is disappointing with shelling is that it is slower than the call to URLDownloadToFileW ....

@tkelman
Copy link
Contributor

tkelman commented Jul 16, 2017

powershell has a kind of annoying first-time startup delay, hopefully isn't as bad if you download multiple things in a julia session

@musm
Copy link
Contributor Author

musm commented Jul 17, 2017

powershell has a kind of annoying first-time startup delay, hopefully isn't as bad if you download multiple things in a julia session

Fair enough. Should we merge this then?

@musm
Copy link
Contributor Author

musm commented Jul 24, 2017

bumping for decision

@musm
Copy link
Contributor Author

musm commented Jul 28, 2017

It may be worth adding this as a non-functional change to Compat and using that as Compat.download in BinDeps and WinRPM , thoughts on this ?

@tkelman
Copy link
Contributor

tkelman commented Jul 28, 2017

BinDeps already has been using powershell in its download_cmd

@musm
Copy link
Contributor Author

musm commented Jul 28, 2017

Right, but at least then it would be using the same implementation (e.g. it doesn't look like it correctly escapes urls).

@musm
Copy link
Contributor Author

musm commented Jul 28, 2017

@tkelman Would you be on board with that? I.e. replace all uses of download with the definitions in base?

@tkelman
Copy link
Contributor

tkelman commented Jul 28, 2017

The BinDeps version would have to be deprecated, as it's used by other packages

@musm
Copy link
Contributor Author

musm commented Aug 5, 2017

Should we merge this or leave it as is ?

@musm
Copy link
Contributor Author

musm commented Sep 17, 2017

I don't think this is important and causing issues

@musm musm closed this Sep 17, 2017
@nalimilan
Copy link
Member

What kind of issues? I thought it was supposed to reduce download failures, which would be a major improvement. The PR has been approved for weeks, so why close it now?

@JeffBezanson
Copy link
Sponsor Member

Rebased: #25477

@musm musm deleted the patch-6 branch May 15, 2019 16:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
system:windows Affects only Windows
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants