-
-
Notifications
You must be signed in to change notification settings - Fork 368
File in sub-dir of staticdir in long-path notation would not load #1638
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
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 |
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.
Could you please deal with reduced coverage?
cherrypy/lib/static.py
Outdated
@@ -314,6 +314,10 @@ def staticdir(section, dir, root='', match='', content_types=None, index='', | |||
branch = request.path_info[len(section) + 1:] | |||
branch = urllib.parse.unquote(branch.lstrip(r'\/')) | |||
|
|||
# On Windows, correct the path for long-path support | |||
if os.name == 'nt': | |||
branch = branch.replace('/', '\\') |
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.
I think it's better to start relying on pathlib
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
You want to introduce a whole new dependency just for a 2 line change?
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
@@ -132,6 +132,14 @@ def dynamic(self): | |||
'error_page.404': error_page_404, | |||
} | |||
} | |||
|
|||
# Windows specific long-path support | |||
if(platform.system() == 'Windows'): |
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.
Don't use parens.
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use r'\'
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.
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.
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.
Oh.. I see
@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
@@ -185,6 +189,14 @@ def test_static(self): | |||
# we just check the content | |||
self.assertMatchesBody('^Dummy stylesheet') | |||
|
|||
@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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a period at the end of docstring. This is required by PEP 257.
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.
(this is the last nitpick and I'll merge PR after fixing it)
@Safihre thank you! |
If a
staticdir
is supplied in Windows long-path notation, serving a file from a subdirectory would fail becauseos.stat
does 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.