Skip to content

Conversation

@JoeKar
Copy link
Member

@JoeKar JoeKar commented Feb 5, 2026

This will help us to keep track of the same file opened via different symlinks.

Fixes #3995

return filename, err
}
if !filepath.IsAbs(dstFilename) {
filename = filepath.Join(filepath.Dir(filename), dstFilename)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we really need to resolve relative path to absolute one?

And even if we do, why need to do that at each iteration, not just at the end?

Copy link
Member Author

@JoeKar JoeKar Feb 9, 2026

Choose a reason for hiding this comment

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

Do we really need to resolve relative path to absolute one?

From my perspective yes, because we compare it at the end against the buffers AbsPath and it shall not be affected by any relative link or whatever.
This doesn't mean that we have to do this within this function. We can also do this in the using function.

And even if we do, why need to do that at each iteration, not just at the end?

Obviously no. 🤦‍♂️

EDIT:
In an intermediate state I had an issue caused by layer 8 (me), which lead me to a wrong assumption.

Copy link
Member Author

Choose a reason for hiding this comment

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

This doesn't mean that we have to do this within this function. We can also do this in the using function.

I would prefer to do this at the end of ResolveSymlinks().

Copy link
Collaborator

Choose a reason for hiding this comment

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

Obviously no. 🤦‍♂️

Actually I've recalled that we do need to do that at each iteration, since any intermediate symlink may be relative too. (And that is the actual reason why resolving to absolute path needs to be done by ResolveSymlinks(), not just by the caller.)

@dmaluka
Copy link
Collaborator

dmaluka commented Feb 10, 2026

I've noticed an "issue" with this PR. If we have a regular file foo and a symlink bar pointing to it, and we open bar in micro, the statusline shows its name is bar (not resolved). Ok, that is not a problem in itself. Then we open foo in another pane, and the statusline shows its name is bar too, not foo. Just because bar has been already opened, so its SharedBuffer already exists (and thus is reused by foo), and b.Path in this SharedBuffer is bar, not foo. Even though it is foo that is the original file, while bar is a symlink to it.

For comparison, vim shows the resolved file name in the statusline, so it behaves predictably: it always shows the original file name.

Well, maybe we can treat this as a feature ("first wins" rule)...

Otherwise we can't identify if we have the same file open multiple times via
different symlinks.
Additionally this will also store the buffer backup and serialized buffer for
the same target file just once.
Otherwise it will be removed async, which shouldn't happen in case there is
still one buffer open with the same modified file.
@JoeKar
Copy link
Member Author

JoeKar commented Feb 10, 2026

For comparison, vim shows the resolved file name in the statusline, so it behaves predictably: it always shows the original file name.

Well, maybe we can treat this as a feature ("first wins" rule)...

Hm, indeed...this behavior is somehow strange.
The order of opening the file shouldn't influence how it is named in the editor.
It should be every time the file name/path the user opened or the resolved path.

EDIT:
The more tricky thing is the (relative) path before the basename of the file (set basename false).

EDIT2:
Didn't find an elegant solution so far.

Otherwise we do unnecessarily serialize per shared buffer as well as storing
multiple cursor states, while only the last one will be restored anyway.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Different saveundo buffers for symlinked files

2 participants