-
Notifications
You must be signed in to change notification settings - Fork 3k
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
command: normalize paths for path and track-list/N/external-filename #15780
Conversation
b04e522
to
6f6b63a
Compare
This is breaking change. It even breaks first party clients see Line 192 in 62c3aeb
mpv/osdep/mac/remote_command_center.swift Line 197 in 62c3aeb
And probably all non-first part scripts.
I don't understand why we need to duplicate those? We even export |
Didn't realize this was so popular. Nobody really complained about something named
I mean it's not really critical but we have |
Well, the property name is only cosmetic and having returning only filename for external file would be rather useless, because how would you reference that file? Also
I don't agree to break something that has hundreds of matches on github alone https://github.com/search?q=external-filename+mpv&type=code in scripts and applications. Do we really want to force everyone to change just for the sake of renaming it? It will be deprecated for years at minimum and still some clients won't be updated. |
Download the artifacts for this pull request: |
7b85de1
to
8a98188
Compare
I think it's bizarre that property names don't actually give back what they say they do but fine I guess if everyone is used to it. This is just the path normalization stuff now. |
const char *path) | ||
{ | ||
assert(talloc_ctx && "mp_normalize_user_path requires talloc_ctx!"); | ||
char *expanded = mp_get_user_path(NULL, global, path); |
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.
If talloc_ctx is required, why not use it here?
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.
It's only required because mp_normalize_path
below requires it. I thought it was better to free the unneeded memory after the path is constructed.
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.
Maybe we should fix mp_normalize_path
to clean internal allocations. Because it is getting awkward. In principle talloc_ctx
should only contain output allocation. And it should work with NULL, as any other function like we have.
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've added a commit that fixes that as simplifies several calls of it as well.
player/command.c
Outdated
@@ -507,7 +507,10 @@ static int mp_property_path(void *ctx, struct m_property *prop, | |||
MPContext *mpctx = ctx; | |||
if (!mpctx->filename) | |||
return M_PROPERTY_UNAVAILABLE; | |||
return m_property_strdup_ro(action, arg, mpctx->filename); | |||
char *path = mp_normalize_path(mpctx, mpctx->filename); |
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.
use temporary talloc_ctx, it will leave some allocations that won't be deallocated if attached to mpctx
player/command.c
Outdated
@@ -1997,6 +2000,9 @@ static int get_track_entry(int item, int action, void *arg, void *ctx) | |||
struct MPContext *mpctx = ctx; | |||
struct track *track = mpctx->tracks[item]; | |||
|
|||
char *external_filename = mp_normalize_user_path(mpctx, mpctx->global, |
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.
ditto
player/command.c
Outdated
@@ -507,7 +507,10 @@ static int mp_property_path(void *ctx, struct m_property *prop, | |||
MPContext *mpctx = ctx; | |||
if (!mpctx->filename) | |||
return M_PROPERTY_UNAVAILABLE; | |||
return m_property_strdup_ro(action, arg, mpctx->filename); | |||
char *path = mp_normalize_path(mpctx, mpctx->filename); |
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.
Also I though you want to normalize mpctx->filename
itself, not only the property.
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.
Nah, I decided that was too risky.
The renaming stuff can be revisited in separate PR, but we need to be careful doing changes like that. We have bad track record of breaking our api users. |
I think our normalize function does more than expected. Normalization is fine, but making this resolve symlinks may not be expected as we never did that in our properties. |
Normalization doesn't resolve symlinks unless they contain |
04bccb8
to
b0a95a0
Compare
Instead of requiring the caller to pass an appropriate talloc_ctx, mp_normalize_path will make its own internal allocations and cleanup as needed.
If a talloc_ctx was being made solely for a onetime usage of getting a normalized string, we can now just pass NULL instead and free the string directly to make things easier.
Expanding a path and then normalizing it is probably a common shorthand. The reason to not incorporate this directly into mp_normalize_path is because it requires the global struct which is out of scope for path_utils so use this wrapper instead.
Now that mp_normalize_path can accept NULL and we have a shorthand for expand + normalize, now is a good chance to simplify this to make it less awkward.
It's better for API users to actually get predictable results.
b0a95a0
to
bee35b8
Compare
should be fine. |
@@ -1997,6 +2000,9 @@ static int get_track_entry(int item, int action, void *arg, void *ctx) | |||
struct MPContext *mpctx = ctx; | |||
struct track *track = mpctx->tracks[item]; | |||
|
|||
char *external_filename = mp_normalize_user_path(NULL, mpctx->global, | |||
track->external_filename); |
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 keeps spamming
[ 1.966][d][global] user path: 'folder.jpg' -> 'folder.jpg'
in my logs. depends on circumstancestrack-list
may (apparently) be read a few times per osc update.
obviously the name should only be normalized once - why does this go through "user_path" stuff at all? it's not like the external filename is supposed to contain e.g.
~~global/
or so
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.
- mp_get_user_path logs everytime it's called. Anytime the property is read, this will get called. One way to avoid that would be to save the track's external filename as expanded directly, but not sure if that would have some other unforeseen consequence or so.
- It needs it in order to expand
~/path
which works now.mp_normalize_path
on its own is too dumb to handle that.
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.
One way to avoid that would be to save the track's external filename as expanded directly, but not sure if that would have some other unforeseen consequence or so.
Well, normalizing the filename once when you open it and remembering what the path was sounds like the correct behavior to me.
path
andtrack-list/N/external-filename
track-list/N/external-filename
totrack-list/N/external-path
because it actually returns a pathtrack-list/N/external-filename
andtrack-list/N/external-filename/no-ext
properties.