Skip to content

If a file (or its containing directory) is symlinked, then it can be opened in two RStudio tabs #12616

Open

Description

@dvg-p4

System details

RStudio Edition : Desktop
RStudio Version : 2022.12.0 Build 353
OS Version      :  MacOS Ventura 13.0
R Version       :  4.2.2

Also reproduced on:

RStudio Edition : Server
RStudio Version :  2022.07.0 Build 548
OS Version      :  CentOS Linux 7
R Version       :  3.6.0

Steps to reproduce the problem

Terminal:

echo hello > some_file.txt
ln -s some_file.txt the_same_file.txt

image

Click each of these in turn--two tabs open in RStudio

image

Alternatively:

mkdir A
mkdir B
cd A
mkdir C
cd ../B
ln -s ../A/C
Dans-P4-MacBook-Pro:B dgealow$ cd C
Dans-P4-MacBook-Pro:C dgealow$ echo hello > file.txt

Then, in the RStudio file browser, open both A/C/file.txt and B/C/file.txt,

Describe the problem in detail

RStudio usually will not allow opening a single file in two tabs. Symlinks (of either a file itself or a directory that contains it) bypass this restriction, allowing a state in which the same file is open twice. This state is prone to errors, since unsaved edits to one tab will not appear in the other tab. If edits are made in both tabs they will overwrite each other. In a small toy example, it's easy to see what's going on, but for a large script in a big project it's easy not to realize what's happening until you've already overwritten your own work.

Describe the behavior you expected

Prevent re-opening of a file that is already open via an equivalent symlinked path. (Or allow for simultaneous synchronized editing in multiple tabs a la VSCode, but that's obviously a much bigger request.)

  • I have read the guide for submitting good bug reports.
  • I have installed the latest version of RStudio, and confirmed that the issue still persists.
  • I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.

Activity

  1. added
    new
    on Jan 23, 2023
  2. ronblum commented on Jan 24, 2023

    @ronblum
    Contributor

    @dvg-p4 Thank you for raising this! I can readily reproduce this in RStudio Desktop 2022.07.2+576 and RStudio Server 2022.12.0+353. I'll mark it for review as part of our ongoing development of RStudio.

  3. added and removed
    new
    on Jan 24, 2023
  4. CGMossa commented on Feb 13, 2023

    @CGMossa

    This is also happening when using the browser() tag; See this
    image

  5. CGMossa commented on Feb 13, 2023

    @CGMossa

    I see now that this might be unrelated, or it not. See issue #12702 for how this is happening.

  6. github-actions commented on Aug 13, 2023

    @github-actions

    This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs, per https://github.com/rstudio/rstudio/wiki/Issue-Grooming. Thank you for your contributions.

  7. added
    stale
    on Aug 13, 2023
  8. github-actions commented on Aug 27, 2023

    @github-actions

    This issue has been automatically closed due to inactivity.

  9. dvg-p4 commented on Aug 28, 2023

    @dvg-p4
    Author

    Should this be re-opened?

  10. CGMossa commented on Aug 28, 2023

    @CGMossa

    Possibly.

  11. kevinushey commented on Aug 28, 2023

    @kevinushey
    Collaborator

    IMHO, we should allow this, and instead improve the way we detect whether a file has changed on disk (for the case where a single file has been opened from different potential links)

  12. 3 remaining items

  13. dvg-p4 commented on Mar 27, 2024

    @dvg-p4
    Author

    IIRC this can also happen with ~/file vs /home/[me]/file, particularly when clicking on a line in testthat output

  14. gtritchie commented on May 1, 2024

    @gtritchie
    Member

    See #14297 for another example of problems due to path normalizatiion issues. In that case, related to long vs. short filenames on Windows. Often triggered when a path is under the user's profile and their account name has non-ascii characters.

  15. kevinushey commented on May 28, 2024

    @kevinushey
    Collaborator

    Some other observations:

    • If both the file and the symlink live within the current project, then the project file monitor is able to detect changes on the filesystem and update the tab's contents when either one of the files is changed.
    • If you're currently editing a symlink, then the edits to the original file won't appear until the tab hosting the original file is opened.

    Some potential ways forward:

    • If we detect that a file is a symlink, use a file monitor to detect changes on the resolved path for the file, so that we can detect and respond to changes.
    • Prompt the user when opening a symlink for editing, and ask whether they want to edit using the symlink file path, or the resolved file path.
    • Resolve symlinks by default when opening them for editing. (Perhaps with this behavior behind a user preference if necessary.)
  16. gtritchie commented on Jun 3, 2024

    @gtritchie
    Member

    In case it proves helpful in some way, Electron's ShowOpenDialog[Sync] API has this option on macOS:

    noResolveAliases macOS - Disable the automatic alias (symlink) path resolution. Selected aliases will now return the alias path instead of their target path.

  17. removed this from the Kousa Dogwood milestone on Sep 17, 2024
  18. added this to the Kousa Dogwood milestone on Sep 17, 2024
  19. gtritchie commented on Oct 29, 2024

    @gtritchie
    Member

    Too late in this release to mess with this, so once again bumping it to the next.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions