-
Notifications
You must be signed in to change notification settings - Fork 3.2k
screenshot: fix %f corner case #17021
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
base: master
Are you sure you want to change the base?
screenshot: fix %f corner case #17021
Conversation
|
I also changed the This just an aside, though. If you want |
|
According to DOCS/contribute.md GNU features should not be used and it may not work on Windows. |
7fd0aa5 to
98e477a
Compare
|
I am a little embarassed for missing that. I grepped for |
98e477a to
896d9d2
Compare
URLs can end with trailing slashes (/) which in turn results in GNU
basename[1] returning the empty string. Catch that case and fallback on
the raw value of mpctx->filename. Subsequent path sanitation takes care
of translating invalid path component chars.
Issue reproduction steps:
```
mpv \
--screenshot-dir=$HOME/mpv-shots \
--screenshot-template='%f/%P' \
https://example.org/video/
```
This would result in %f expanding to '' and thus render
screenshot-template an absolute path which, for some reason, would in
turn take precedence of screenshot-dir and hence result in a
non-writeable path, i.e. `/timestamp.ext`.
With this new approach the resulting path looks like this:
`/home/user/mpv-shots/http:__example.org_video_/timestamp.ext`
Not particularly pretty but less ambiguous and more consistent over a
diverse range of input paths.
[1] mpv-player#14635 (comment)
There is no reason to create the screenshot dir separately, because the final path starts with it. So defer creating directories to the last possible moment with all the information necessary.
896d9d2 to
a5f29e5
Compare
|
Sorry for the last force push, had to rewrite history. |
When the path is a URL, use the whole path as basename. The dirname will be "." in this case. This simplifies various checks throughout the codebase. In particular, it avoids returning an empty string for URLs ending with /. The filename property will return full URLs, which is desirable because the domain and path segments before the last are useful information. This fixes half of mpv-player#10975. The empty string check in mp_property_filename() can be removed because it only happened with the basename of URLs ending with /. mp_property_filename() will not be called with directories with trailing slashes because mpv expands them immediately when they are the current playlist entry; I tested it by observing filename. Also mpv-player#16896 will prevent directories with trailing slashes anyway. This also fixes the issue described in mpv-player#17015 of %f in --screenshot-template being evaluated to an empty string for URLs ending with /, which can inadvertently make it use an absolute path. Alternative to mpv-player#16932 and mpv-player#17021.
When the path is a URL, use the whole path as basename. The dirname will be "." in this case. This simplifies various checks throughout the codebase. In particular, it avoids returning an empty string for URLs ending with /. The filename property will return full URLs, which is desirable because the domain and path segments before the last are useful information. This fixes half of mpv-player#10975. This also fixes the issue described in mpv-player#17015 of %f in --screenshot-template being evaluated to an empty string for URLs ending with /, which can inadvertently make it use an absolute path. Alternative to mpv-player#16932 and mpv-player#17021.
This introduces a simple wrapper around `mp_basename`. It returns URLs unchanged. Especially with filename representations of streaming service URLs the last path segment, which usually points to a file in most other contexts, is becoming ever less meaningful. So provide this to conveniently use URLs as-is where usually a file name would be expected. Some caution is advised, because components that expect no '/' may get tripped up. Credit goes to @guidocella for the idea.
|
Download the artifacts for this pull request: Windows |
URLs can end with trailing slashes (/) which in turn results in GNU basename[1] returning the empty string. Catch that case and fallback on the raw value of mpctx->filename. Subsequent path sanitation takes care of translating invalid path component chars.
Issue reproduction steps:
This would result in %f expanding to '' and thus render screenshot-template an absolute path which, for some reason, would in turn take precedence of screenshot-dir and hence result in a non-writeable path, i.e.
/timestamp.ext.With this new approach the resulting path looks like this:
/home/user/mpv-shots/http:__example.org_video_/timestamp.extNot particularly pretty but less ambiguous and more consistent over a diverse range of input paths. For transparency and reference also see [2] which sadly could not be revived.
[1] #14635 (comment)
[2] #17015
Check!