You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Mar 3, 2023. It is now read-only.
Repository navigation
This repository was archived by the owner on Mar 3, 2023. It is now read-only.
Currently TextEditor.getPath returns the realpath of the file. When a project directory contains symlinks somewhere under it it becomes impossible to decide which project root a specific file belongs to. Please see noseglid/atom-build#245 for a longer explanation of the use case as well as an example folder hierarchy.
The only way to make a correlation between a TextEditor and a project root requires the TextEditor to provide the non-real path of the file.
Getting the realpath from the non-real path is trivial (fs.realpath())) but the other way around is simply not possible.
@atom/feedback thoughts on this? I'm not familiar with a foolproof way to associate a TextEditor to a project path - I can see the benefit of adding a getter for something like nonRealPath / literalPath (naming is hard), or perhaps even better, a method that returns the project root, if any, that the file in the editor belongs to. My gut tells me that a lot of people are inferring project root from the file path.. i certainly have in packages before.
If we could get the project root and project-relative path (both I think would be useful in other contexts too) from a TextEditor, that should fix this issue I think?
But this is going to be a really, really deep rabbit hole, I feel. The problem is that there can be an infinite number of paths that can reach a file. Should the TextEditor instance have to know about all of them? What if one of the n paths changes after the TextEditor is created? Say one of the non-real (imaginary?) paths to the file in question is a/foo/c.txt and gets renamed to a/bar/c.txt. Do we have to have file watchers on everything to manage this?
I agree with @dirk-thomas that we should simply not compute the real path, and leave that to the caller. Does anyone know of circumstances where that would break things in a way that wasn't trivially fixable?
Then I attempted to open test.md in multiple ways from both real-dir and fake-dir and recorded their getPath() result with the command: atom.workspace.getActiveTextEditor().getPath(). Here are the results:
real-dir/test.md
Open from tree-view: /Users/Lee/Source/test-atom-9879/real-dir/test.md
Open from fuzzy-finder: /Users/Lee/Source/test-atom-9879/real-dir/test.md
Open from Cmd+O: /Users/Lee/Source/test-atom-9879/real-dir/test.md
Open via drag-and-drop: /Users/Lee/Source/test-atom-9879/real-dir/test.md (New window appears)
fake-dir/test.md
Open from tree-view: /Users/Lee/Source/test-atom-9879/real-dir/test.md
Open from fuzzy-finder: Does not show up in list
Open from Cmd+O: /Users/Lee/Source/test-atom-9879/real-dir/test.md
Open from drag-and-drop: /Users/Lee/Source/test-atom-9879/real-dir/test.md (New window appears)
Ok, 100% consistent. Which tells me that the code for all of this is almost assuredly in one place ... most likely the opener mechanism.
So then I delved into the Wayback Machine and followed the opener code all the way back to November 2013. As far as I can see, the opener code (which migrated between Project and Workspace over the span) has always* called Project::resolvePath or Project::resolve on the path passed to it. And the resolve twins have always* called fs.absolute() on the path passed to them. Which you can still see here:
So I was wrong and completely fabricated my previously mentioned memory.
Now, where does that leave us? Well, it appears that Project::resolvePath has never been part of the public API and Project::resolve was deprecated back on January 9th, 2015. So at least we don't have to worry about third-party packages depending on this as an API. But since TextEditors have always* returned absolute paths ... we may want to be careful about breaking that implicit contract.
I do understand that changing the existent behavior is risky. But do we agree that we should somehow expose the non-realpath with a different method (however clumsy the name might be)?
Obviously I would like to have the feature rather sooner then later 😉 in order to actually make the build commands (referenced in the description) work. Without this feature there is simply no way to make it work for projects with symlinks. Out of curiosity: what is the rough time frame for Atom 2.0?
Let me try to describe what changes would be required (also for me to understand the Atom internals a bit better) and what that might affect:
Modify Project.resolvePath() to return non-realpath but normalized absolute path instead.
Consider the current usage of the function:
Project.isPathModified() depends on what Buffer.getPath() returns. If it will return a non-realpath nothing needs to be done. Otherwise Project.isPathModified() needs to invoke realpath on the argument before passing it to findBufferForPath().
Workspace.open() this is where we actually want the non-realpath since from here the uri / path gets passed throughout the pipeline until it ends up in the TextEditor.
The function also determines if the file is already open in a pane (itemForURI()). This is based on TextBuffer.getUri() which uses getPath(). If getPath() continues to return a realpath the argument to itemForURI() needs to be a realpath.
Is there a way to find out if other code invokes this non-public API?
Modify TextEditor.getPath() to call realpath() before returning the value and introduce a new method TextEditor.getNonRealPath().
If we ensure that existing API like TextEditor.getPath() or TextBuffer.getPath() still return the same realpath as before this might be a backward compatible change? I am happy to hear your thoughts...
I have updated #10856 to provide additional API exposing the non-realpath. The existing API should not change behavior (except that a TextBuffer now internally stores the non-realpath). Any feedback is welcome.
This issue has been automatically locked since there has not been any recent activity after it was closed. If you can still reproduce this issue in Safe Mode then please open a new issue and fill out the entire issue template to ensure that we have enough information to address your issue. Thanks!
Activity
thedaniel commentedon Dec 3, 2015
@atom/feedback thoughts on this? I'm not familiar with a foolproof way to associate a TextEditor to a project path - I can see the benefit of adding a getter for something like
nonRealPath/literalPath(naming is hard), or perhaps even better, a method that returns the project root, if any, that the file in the editor belongs to. My gut tells me that a lot of people are inferring project root from the file path.. i certainly have in packages before.lee-dohm commentedon Dec 3, 2015
If we could get the project root and project-relative path (both I think would be useful in other contexts too) from a
TextEditor, that should fix this issue I think?But this is going to be a really, really deep rabbit hole, I feel. The problem is that there can be an infinite number of paths that can reach a file. Should the
TextEditorinstance have to know about all of them? What if one of thenpaths changes after theTextEditoris created? Say one of the non-real (imaginary?) paths to the file in question isa/foo/c.txtand gets renamed toa/bar/c.txt. Do we have to have file watchers on everything to manage this?maxbrunsfeld commentedon Dec 3, 2015
I agree with @dirk-thomas that we should simply not compute the real path, and leave that to the caller. Does anyone know of circumstances where that would break things in a way that wasn't trivially fixable?
lee-dohm commentedon Dec 4, 2015
I'm pretty sure it was this way to begin with (because it was easier), but it changed for some reason ¯_(ツ)_/¯ I'll see if I can backtrace it.
lee-dohm commentedon Dec 4, 2015
So I devised a test just to see how consistent this is:
real-dirinside itreal-dirnamedfake-dirreal-dirnamedtest.mdThen I attempted to open
test.mdin multiple ways from bothreal-dirandfake-dirand recorded theirgetPath()result with the command:atom.workspace.getActiveTextEditor().getPath(). Here are the results:real-dir/test.md/Users/Lee/Source/test-atom-9879/real-dir/test.md/Users/Lee/Source/test-atom-9879/real-dir/test.md/Users/Lee/Source/test-atom-9879/real-dir/test.md/Users/Lee/Source/test-atom-9879/real-dir/test.md(New window appears)fake-dir/test.md/Users/Lee/Source/test-atom-9879/real-dir/test.md/Users/Lee/Source/test-atom-9879/real-dir/test.md/Users/Lee/Source/test-atom-9879/real-dir/test.md(New window appears)Ok, 100% consistent. Which tells me that the code for all of this is almost assuredly in one place ... most likely the opener mechanism.
So then I delved into the Wayback Machine and followed the opener code all the way back to November 2013. As far as I can see, the opener code (which migrated between
ProjectandWorkspaceover the span) has always* calledProject::resolvePathorProject::resolveon the path passed to it. And theresolvetwins have always* calledfs.absolute()on the path passed to them. Which you can still see here:atom/src/project.coffee
Lines 212 to 219 in 2696f49
So I was wrong and completely fabricated my previously mentioned memory.
Now, where does that leave us? Well, it appears that
Project::resolvePathhas never been part of the public API andProject::resolvewas deprecated back on January 9th, 2015. So at least we don't have to worry about third-party packages depending on this as an API. But since TextEditors have always* returned absolute paths ... we may want to be careful about breaking that implicit contract.* For values of "always" back to November 2013
dirk-thomas commentedon Dec 5, 2015
I do understand that changing the existent behavior is risky. But do we agree that we should somehow expose the non-realpath with a different method (however clumsy the name might be)?
Regarding the
absolute()function infs-plus: I find it rather unintuitive that it resolves symlinks. Based on how similar functions in other languages work (e.g. in Python: https://docs.python.org/3/library/os.path.html#os.path.abspath) I expect the function to:..within the path (normalizeX/path/../YtoX/Y)~But I would not expect the function to perform a
realpath().lee-dohm commentedon Dec 5, 2015
Sure, we should. The question is when? Is this no big deal and we can take it now? Or is it something that should wait until v2.0?
dirk-thomas commentedon Dec 5, 2015
Obviously I would like to have the feature rather sooner then later 😉 in order to actually make the build commands (referenced in the description) work. Without this feature there is simply no way to make it work for projects with symlinks. Out of curiosity: what is the rough time frame for Atom 2.0?
Let me try to describe what changes would be required (also for me to understand the Atom internals a bit better) and what that might affect:
Buffer.getPath()returns. If it will return a non-realpath nothing needs to be done. OtherwiseProject.isPathModified()needs to invoke realpath on the argument before passing it tofindBufferForPath().TextEditor.itemForURI()). This is based onTextBuffer.getUri()which usesgetPath(). IfgetPath()continues to return a realpath the argument toitemForURI()needs to be a realpath.fs.getSizeSync()which might need a realpath (?).TextEditor.getPath()to callrealpath()before returning the value and introduce a new methodTextEditor.getNonRealPath().If we ensure that existing API like
TextEditor.getPath()orTextBuffer.getPath()still return the same realpath as before this might be a backward compatible change? I am happy to hear your thoughts...dirk-thomas commentedon Dec 20, 2015
It would be great if someone could provide guidance regarding my proposed changes. I am happy to work on a patch if the direction is clear.
winstliu commentedon Dec 22, 2015
Was going through a few old issues and noticed this one that seemed really similar: #3110.
dirk-thomas commentedon Jan 13, 2016
ping 😉
joefitzgerald commentedon Jan 29, 2016
@50Wliu yep, this is exactly what #3110 is about. I'm going to close it in deference to this.
dirk-thomas commentedon Sep 7, 2016
I have updated #10856 to provide additional API exposing the non-realpath. The existing API should not change behavior (except that a TextBuffer now internally stores the non-realpath). Any feedback is welcome.
maxbrunsfeld commentedon Jan 5, 2017
This will be fixed in Atom 1.14. We'll preserve whatever path the project was initialized with. Sorry for the very very long turnaround time.
dirk-thomas commentedon Jan 5, 2017
👍 for supporting this with the current API without the need for additional API.
Avoid unnecessary realpath() calls
lock commentedon Apr 3, 2018
This issue has been automatically locked since there has not been any recent activity after it was closed. If you can still reproduce this issue in Safe Mode then please open a new issue and fill out the entire issue template to ensure that we have enough information to address your issue. Thanks!