File in sub-dir of staticdir in long-path notation would not load#1638
File in sub-dir of staticdir in long-path notation would not load#1638webknjaz merged 1 commit intocherrypy:masterfrom Safihre:master
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1638 +/- ##
==========================================
- Coverage 77.06% 76.96% -0.11%
==========================================
Files 106 106
Lines 14299 14306 +7
==========================================
- Hits 11020 11010 -10
- Misses 3279 3296 +17 |
webknjaz
left a comment
There was a problem hiding this comment.
Could you please deal with reduced coverage?
|
|
||
| # On Windows, correct the path for long-path support | ||
| if os.name == 'nt': | ||
| branch = branch.replace('/', '\\') |
There was a problem hiding this comment.
I think it's better to start relying on pathlib
There was a problem hiding this comment.
Pathlib is not available in Python 2.7 or anything below 3.4 so I don't think it applies right now.
There was a problem hiding this comment.
There was a problem hiding this comment.
You want to introduce a whole new dependency just for a 2 line change?
There was a problem hiding this comment.
Well, this just looks redundant to me, that's why I'm looking into using this package, which handles path processing way better than such simplistic things.
And I don't truly understand what is this \\? notation and why one would like to combine different delimiter styles. I just want this change, which I cannot check, to not reduce reliability.
There was a problem hiding this comment.
Agreed, Windows is weird. Only using this notation we can reliably get all paths (including those with unicode) to work on Windows. The mixing of delimiter styles is inherent to Cherrypy running on Windows, in that sense it's actually surprising that it worked so far. Windows users will supply paths in Windows style.
Unfortunately I have no experience with pathlib and combined with my lack of understanding of cherrypy internals, me implementing it would probably not work out well.
Simple isn't necessarily bad ;)
There was a problem hiding this comment.
Okay, let's postpone pathlib integration question, but I'll ask you to document the problem this change solves in code via comment.
cherrypy/test/test_static.py
Outdated
| } | ||
|
|
||
| # Windows specific long-path support | ||
| if(platform.system() == 'Windows'): |
There was a problem hiding this comment.
Plus this doesn't need to be conditional.
cherrypy/test/test_static.py
Outdated
| if(platform.system() == 'Windows'): | ||
| rootconf['/static-long'] = { | ||
| 'tools.staticdir.on': True, | ||
| 'tools.staticdir.dir': '\\\\?\\%s' % curdir, |
There was a problem hiding this comment.
Why don't you use r'string' notation here?
|
What can I do about the reduced coverage? Have you looked at the report? |
|
@Safihre It looks like codecov's CI detection script has broke: |
|
That explains. |
|
@Safihre it's not related to PR. codecov works w/o tokens for public builds in public CIs |
| # Python normally converts this but not when the staticdir is | ||
| # supplied in long-path notation, eg: \\?\C:\static\js/script.js | ||
| if os.name == 'nt': | ||
| branch = branch.replace('/', '\\') |
There was a problem hiding this comment.
That's not possible:
E branch = branch.replace('/', r'\')
E ^
E SyntaxError: EOL while scanning string literal
EDIT: not possible in general with only 1 char, not just as function parameter.
|
@Safihre plz also rebase your branch in order for it to pick up my workaround for codecov's bug |
cherrypy/test/test_static.py
Outdated
|
|
||
| @pytest.mark.skipif(platform.system() != 'Windows', reason='Windows only') | ||
| def test_static_longpath(self): | ||
| """Test serving of a file in subdir of a Windows long-path staticdir""" |
There was a problem hiding this comment.
Please add a period at the end of docstring. This is required by PEP 257.
There was a problem hiding this comment.
(this is the last nitpick and I'll merge PR after fixing it)
|
@Safihre thank you! |
If a
staticdiris supplied in Windows long-path notation, serving a file from a subdirectory would fail becauseos.statdoes not like the mixing of forward and backwards slashes.Tested on both Python 2.7.14 and 3.6.2.
In the included test the old behavior would be to do:
Which fails due to the mixed slashes, resulting in a 404.