Skip to content
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

Editor doesn't recognize when two paths point to same file (via symlinks) #94317

Closed
kentonv opened this issue Apr 2, 2020 · 3 comments
Closed
Assignees
Labels
*duplicate Issue identified as a duplicate of another issue(s)

Comments

@kentonv
Copy link

kentonv commented Apr 2, 2020

  • VSCode Version: 1.43.2
  • OS Version: Debian Buster (Linux)

When a directory tree contains symlinks that cause a file to appear at multiple paths, vscode will allow each path to be open in a separate editor and edited independently. This can lead to very confusing situations where two different sets of changes have been made in different windows and only one can be saved.

Steps to Reproduce:

  1. In an empty directory, do:
    mkdir foo
    ln -s foo bar
    touch foo/file.txt
    code .
    
  2. Using the file explorer or quick-open, open both foo/file.txt and bar/file.txt.
  3. Make changes in both editors. Notice they don't sync.
  4. Try to save both editors. The second one will complain that the file has changed on disk.

Does this issue occur when all extensions are disabled?: Yes

Expected results:

In step 2, vscode should recognize that both paths point to the same file, and should only open one or the other.

Impact:

I have a code tree that uses symlinks. Several times, I have been burned by this, having accidentally made modifications to the same file under two different aliases. Fortunately, vscode lets me know that there is a problem (rather than just overwriting), but I've found it extremely difficult to merge the changes correctly. (Arguably it would be less difficult if vscode presented a 3-way diff rather than a 2-way diff, but it would be better to avoid the situation entirely...)

I have tried to mitigate the problem by using "files.exclude" to hide all but one alias. However, I've found that extensions which open editor windows (e.g. implementing "jump to definition" or whatnot) are inconsistent about which version of the path they choose to open.

Possible fixes:

On Unix systems, it's possible to recognize when two files are the same by using the stat(2) system call on each and comparing the st_dev and st_ino values (device and inode numbers). Under Node.js these can be accessed using fs.stat() as stats.dev and stats.ino. If editor tabs were keyed by device and inode numbers rather than file path, it would be impossible to open the same file in multiple tabs.

Another solution is to expand all symlinks before opening a file, to derive its canonical path. This solution is theoretically ugly and less robust, but may be easier to implement in practice. Also, it's worth noting that some extensions (such as the git extension) do not work properly when the file is opened under a path other than the canonical one, so canonicalizing paths may be preferable to sidestep such bugs (though, arguably such extensions should be fixed directly).

@bpasero bpasero added the *duplicate Issue identified as a duplicate of another issue(s) label Apr 5, 2020
@kentonv
Copy link
Author

kentonv commented Apr 5, 2020

@bpasero I did search for similar issues before filing this and wasn't able to find one. Can you point me to the issue that this is duplicating?

@bpasero
Copy link
Member

bpasero commented Apr 6, 2020

/duplicate #12448

@github-actions github-actions bot locked and limited conversation to collaborators May 20, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
*duplicate Issue identified as a duplicate of another issue(s)
Projects
None yet
Development

No branches or pull requests

3 participants
@bpasero @kentonv and others